stackdriver

package module
v0.0.0-...-fbf5248 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2015 License: Apache-2.0 Imports: 6 Imported by: 1

README

Stackdriver API Library

A client library for accessing the Stackdriver API.

Currently implemented:

  • Custom Metrics
  • Code Deploy Events
  • Annotation Events

Usage

import (
    "github.com/bellycard/stackdriver"
    "time"
)

// Create new Stackdriver API client.
client := stackdriver.NewStackdriverClient("apikey")

// Create new Stackdriver API gateway message.
apiMessages := stackdriver.NewGatewayMessage()

now := time.Now().Unix()

// Populate gateway message with metrics.
apiMessages.CustomMetric("my-metric1", "i-axd939f", now, 50)
apiMessages.CustomMetric("my-metric2", "i-afdsf9f", now, 6.5)
apiMessages.CustomMetric("my-metric3", "i-a3d923f", now, 25)

// Send gateway message to Stackdriver API.
client.Send(apiMessages)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnnotationEvent

type AnnotationEvent struct {
	// Contents of the message, in plain text. Limited to 256 characters.
	Message string `json:"message"`
	// Person or robot who the attribution should be attributed.
	// [Optional]
	AnnotatedBy string `json:"annotated_by,omitempty"`
	// Event status level. Options are: INFO, WARN, ERROR.
	// [Default: INFO]
	// [Optional]
	Level string `json:"level,omitempty"`
	// Events with a defined instance id show up under the defined instances context.
	// [Optional]
	InstanceId string `json:"instance_id,omitempty"`
	// Unix timestamp of where the event should appear in the timeline.
	// [Default: Now]
	// [Optional]
	EventEpoch int64 `json:"event_epoch"`
}

type DeployEvent

type DeployEvent struct {
	// Revision of the code that was deployed.
	RevisionId string `json:"revision_id"`
	// Person or robot responsible for deploying the code.
	// [Optional]
	DeployedBy string `json:"deployed_by,omitempty"`
	// Environment code was deployed to. (ie: development, staging, production)
	// [Optional]
	DeployedTo string `json:"deployed_to,omitempty"`
	// Repository (or project) deployed.
	// [Optional]
	Repository string `json:"repository,omitempty"`
}

type GatewayMessage

type GatewayMessage struct {
	// Timestamp the gateway message is created.
	Timestamp int64 `json:"timestamp"`
	// Protocol version defining the schema of the gateway message.
	ProtocolVersion int64 `json:"proto_version"`
	// Stackdriver assigned Customer Id.
	// [Optional]
	CustomerId string `json:"customer_id,omitempty"`
	// Customer metrics to be sent to Stackdriver API.
	// Each data point must have its own (not necessarily unique) name, value, and collected_at.
	Data []Metric `json:"data"`
}

func NewGatewayMessage

func NewGatewayMessage() GatewayMessage

Factory function to create a new gateway message.

func (*GatewayMessage) CustomMetric

func (gwm *GatewayMessage) CustomMetric(n, id string, ca int64, v interface{})

CustomMetric takes a name, instance id, collected-at and value to populates the data slice.

type Metric

type Metric struct {
	// Timestamp in Unix time notation representing when the custom metric was collected.
	// If value is over an hour before current time the measurement will be rejected.
	CollectedAt int64 `json:"collected_at"`
	// Name of the custom metric as represented in the Stackdriver API.
	Name string `json:"name"`
	// Measurement to record for the data point.
	Value interface{} `json:"value"`
	// Metrics with a defined instance id show up under the defined instances resources.
	// One metric name can be shared across a number of instances to include on a single graph or for alerting.
	// Custom metrics not associated with an instance id will be found under the Custom resource type when creating
	// charts or alerting policies.
	// [Optional]
	Instance string `json:"instance,omitempty"`
}

type StackdriverClient

type StackdriverClient struct {
	// Stackdriver API key
	ApiKey string
}

The StackdriverClient type defines the relevant properties of a Stackdriver API connection.

func NewStackdriverClient

func NewStackdriverClient(ak string) *StackdriverClient

New returns a new client for the Stackdriver API.

func (*StackdriverClient) NewAnnotationEvent

func (sdc *StackdriverClient) NewAnnotationEvent(m, ab, l, iid string, ee int64) error

func (*StackdriverClient) NewDeployEvent

func (sdc *StackdriverClient) NewDeployEvent(rid, db, dt, r string) error

func (*StackdriverClient) Send

func (sdc *StackdriverClient) Send(gwm GatewayMessage) error

Send utilizes HTTP POST to send all currently collected metrics to the Stackdriver API.

Jump to

Keyboard shortcuts

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