edgecast

package module
v0.0.0-...-025d1a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 5 Imported by: 1

README

edgecast

Build Status

A golang client for the Edgecast CDN API.

Installation

// Go vendor experiment (recommended)
gvt fetch "github.com/mre/edgecast"

// or globally (not recommended)
go get github.com/mre/edgecast

Usage:

import github.com/mre/edgecast

client := edgecast.NewEdgecastClient("AccountID", "Token")
data, err := client.Bandwidth()

// Example output:
// BandwidthData {
//    Bps:      42.5,
//    Platform: 2,
// }

Methods

client.Bandwidth()    // Return current bandwidth usage
client.Connections()  // Return number of active CDN connections
client.CacheStatus()  // Return cache hits and misses
client.StatusCodes()  // Return sum of HTTP status codes by category (404, 5xx,...)

Fluent interface

You can also set additional parameters using a fluent interface:

client := edgecast.NewEdgecastClient(config.AccountID, config.Token).
    SetRetries(3). // Setup HTTP request retries (e.g. for flaky connections)
    SetTimeout(5)  // Set request timeout per HTTP request (in seconds

Documentation

Index

Constants

View Source
const (
	// APIEndpoint holds the Edgecast API endpoint URL
	// Meaning of the wildcards:
	// AccountID
	// Platform (see below)
	// Method endpoint (see Metric* below)
	APIEndpoint = "https://api.edgecast.com/v2/realtimestats/customers/%s/media/%d/%s"

	// DefaultRequestRetries defines the default number of http requests before giving up
	DefaultRequestRetries = 1

	// DefaultRequestTimeout defines the default request timeout in seconds
	DefaultRequestTimeout = 5

	// MethodBandwidth is the endpoint for Edgecast bandwidth
	MethodBandwidth = "bandwidth"
	// MethodConnections is the endpoint for Edgecast connections
	MethodConnections = "connections"
	// MethodCachestatus is the endpoint for the Edgecast cache status
	MethodCachestatus = "cachestatus"
	// MethodStatuscodes is the endpoint for the Edgecast status codes
	MethodStatuscodes = "statuscode"
)
View Source
const (
	MediaTypeFlash = 2
	MediaTypeLarge = 3
	MediaTypeSmall = 8
	MediaTypeADN   = 14
)

Media types (also known as "platform") Specify, which Edgecast platforms to monitor. They are identified by an integer value and passed to the API url. The following types are available: flash, http_large, http_small, adn

Unfortunately the stats aren't more fine grained than this. If you have more than one 'service' using the platform(s), you'll get them added together.

Variables

This section is empty.

Functions

This section is empty.

Types

type BandwidthData

type BandwidthData struct {
	Bps      float64
	Platform int
}

BandwidthData holds that data of a request to the edgecast bandwidth API

type CacheStatusData

type CacheStatusData []struct {
	CacheStatus string `json:"CacheStatus"`
	Connections int64  `json:"Connections"`
}

CacheStatusData represends all fields returned from a request to the /cachestatus endpoint

type ConnectionData

type ConnectionData struct {
	Connections float64
	Platform    int
}

ConnectionData holds that data of a request to the edgecast connections API

type Edgecast

type Edgecast struct {
	AccountID string
	BaseURL   string
	Token     string
	Retries   int
	Timeout   int
}

Edgecast client for Go

func NewEdgecastClient

func NewEdgecastClient(accountID, token string) *Edgecast

NewEdgecastClient creates a new Edgecast client

func (Edgecast) Bandwidth

func (e Edgecast) Bandwidth(platform int) (*BandwidthData, error)

Bandwidth returns the current bandwidth usage

func (Edgecast) CacheStatus

func (e Edgecast) CacheStatus(platform int) (*CacheStatusData, error)

CacheStatus returns the current cache status usage

func (Edgecast) Connections

func (e Edgecast) Connections(platform int) (*ConnectionData, error)

Connections returns the current bandwidth usage

func (*Edgecast) SetRetries

func (e *Edgecast) SetRetries(retries int) *Edgecast

SetRetries sets the number of consecutive query replies until giving up

func (*Edgecast) SetTimeout

func (e *Edgecast) SetTimeout(timeout int) *Edgecast

SetTimeout sets the request timeout

func (Edgecast) StatusCodes

func (e Edgecast) StatusCodes(platform int) (*StatusCodeData, error)

StatusCodes returns the current HTTP status codes

type RawEdgecastResult

type RawEdgecastResult struct {
	Result float64
}

RawEdgecastResult represends a raw JSON response object from the API

type StatusCodeData

type StatusCodeData []struct {
	Connections int64  `json:"Connections"`
	StatusCode  string `json:"StatusCode"`
}

StatusCodeData represends all fields returned from a request to the /statuscode endpoint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL