Warp10Exporter

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2017 License: GPL-3.0 Imports: 12 Imported by: 1

README

Warp10Exporter Go Report Card Build Status GoDoc

A Go framework to generate and push metrics to The Warp 10 Platform.

Documentation

Example

package main

import (
	"time"

	warp "github.com/PierreZ/Warp10Exporter"
)

func main() {

	gts := warp.NewGTS("metrics.test").WithLabels(warp.Labels{
		"ip": "1.2.3.4",
	}).AddDatapoint(time.Now(), "42")
	// Not checking the error
	gts.Push("http://localhost:8080", "WRITE_TOKEN")

	// You can also create batchs
	batch := warp.NewBatch()
	batch.Register(gts)
	gts.AddDatapoint(ts, 42)

	err := batch.Push("http://localhost:8080", "WRITE_TOKEN")
	if err != nil {
		// You can also write metrics to a file, to use 
		// https://github.com/ovh/beamium for example
		err = batch.FlushOnDisk("/opt/beamium/sink")
		if err != nil {
			panic(err)
		}
	}
}

TODO

  • Order Datapoints before writing into buffer to optimize parsing on Warp10 side
  • Add Geo on Datapoints by creating NewGeoDatapoints(...)

Documentation

Overview

Package Warp10Exporter is an helper to create GTS for Warp10 Example:

package main

import (
	"time"

	warp "github.com/PierreZ/Warp10Exporter"
)

func main() {

	gts := warp.NewGTS("metrics.test").WithLabels(warp.Labels{
		"ip": "1.2.3.4",
	}).AddDatapoint(time.Now(), "42")
	// Not checking the error
	gts.Push("http://localhost:8080", "WRITE_TOKEN")

	// You can also create batchs
	batch := warp.NewBatch()
	batch.Register(gts)
	gts.AddDatapoint(ts, 42)

	err := batch.Push("http://localhost:8080", "WRITE_TOKEN")
	if err != nil {
		// You can also write metrics to a file, to use
		// https://github.com/ovh/beamium for example
		err = batch.FlushOnDisk("/opt/beamium/sink")
		if err != nil {
			panic(err)
		}
	}
}

For a full guide visit https://github.com/PierreZ/Warp10Exporter

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyBatch = errors.New("Empty Batch")

ErrEmptyBatch is the error thrown when trying to push or write an empty batch of GTS

View Source
var ErrEmptyGTS = errors.New("Empty GTS")

ErrEmptyGTS is the error thrown when trying to push or write an empty GTS

Functions

func ChangePrefix

func ChangePrefix(newprefix string)

ChangePrefix is changing the prefix for metrics files.

func SetHeader

func SetHeader(header string)

SetHeader is changing the classic Header X-Warp10-Token

func SetURI

func SetURI(uri string)

SetURI is changing the classic URI /api/v0/update

Types

type Batch

type Batch map[string]*GTS

Batch is allowing you to push multiples GTS in a single push

func NewBatch

func NewBatch() *Batch

NewBatch is creating a batch

func (*Batch) FlushOnDisk

func (batch *Batch) FlushOnDisk(path string) error

FlushOnDisk is flushing the metrics into a file compatible with the Warp10 Input format. You can then use Beamium to handle the push.

func (*Batch) Print

func (batch *Batch) Print(b *bytes.Buffer)

Print is priting a batch of GTS

func (*Batch) Push

func (batch *Batch) Push(warp10Endpoint string, warp10Token string) error

Push is pushing a GTS batch to a warp10 endpoint

func (*Batch) Register

func (batch *Batch) Register(gts *GTS)

Register is adding a GTS to a batch

type Datapoint

type Datapoint struct {
	Timestamp time.Time
	Value     interface{}
}

Datapoint are datapoint in a GTS

func (*Datapoint) PrintValue

func (dp *Datapoint) PrintValue() string

PrintValue is Printing the value It's supporting string

type Datapoints

type Datapoints []Datapoint

Datapoints are a slice of Datapoint

type GTS

type GTS struct {
	Classname  string
	Labels     map[string]string
	Datapoints Datapoints
}

GTS are GeoTimeSeries

func NewGTS

func NewGTS(classname string) *GTS

NewGTS is creating a new GTS with a name and a value

func (*GTS) AddDatapoint

func (gts *GTS) AddDatapoint(ts time.Time, value interface{}) *GTS

AddDatapoint is adding a datapoint to a GTS

func (*GTS) AddLabel

func (gts *GTS) AddLabel(key string, value string) *GTS

AddLabel is pushing a new label to the GTS

func (*GTS) FlushOnDisk

func (gts *GTS) FlushOnDisk(path string) error

FlushOnDisk is flushing the metrics into a file compatible with the Warp10 Input format. You can then use Beamium to handle the push.

func (*GTS) GetIdentifier

func (gts *GTS) GetIdentifier() string

GetIdentifier is returning an identifier for a GTS The identifier is useful to handle a map of GTS

func (*GTS) Print

func (gts *GTS) Print(b *bytes.Buffer)

Print is printing the Warp10 Input Format it respects the following format: TS// NAME{LABELS} VALUE

func (*GTS) Push

func (gts *GTS) Push(warp10Endpoint string, warp10Token string) error

Push is pushing a single GTS to a warp10 endpoint

func (*GTS) WithLabels

func (gts *GTS) WithLabels(labels Labels) *GTS

WithLabels is adding Labels

type Labels

type Labels map[string]string

Labels type, used to pass to `WithLabels`.

Jump to

Keyboard shortcuts

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