graphite

package module
v0.0.0-...-10cd776 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: MIT Imports: 8 Imported by: 0

README

graphite-golang

This is a lightweight Graphite API client written in Go that implements Carbon submission functionality. It allows to send Tags with metric in Pickle format.

Installation

Use go-get to install graphite-golang

go get github.com/belazar13/graphite-golang

External dependencies

This project has external dependencies for support Pickle

go get github.com/hydrogen18/stalecucumber

Documentation

Like most every other Golang project, this projects documentation can be found on godoc at godoc.org/github.com/belazar13/graphite-golang.

Examples

package mylib

import (
    "github.com/belazar13/graphite-golang"
    "log"
)

func init() {

    // load your configuration file / mechanism
    config := newConfig()

    // try to connect a graphite server
    if config.GraphiteEnabled {
        Graphite, err = graphite.NewGraphite(config.Graphite.Host, config.Graphite.Port)
    } else {
        Graphite = graphite.NewGraphiteNop(config.Graphite.Host, config.Graphite.Port)
    }
    // if you couldn't connect to graphite, use a nop
    if err != nil {
        Graphite = graphite.NewGraphiteNop(config.Graphite.Host, config.Graphite.Port)
    }

    log.Printf("Loaded Graphite connection: %#v", Graphite)
    Graphite.SimpleSend("stats.graphite_loaded", "1")
}

func doWork() {
    // this will work just fine, regardless of if you're working with a graphite
    // nop or not
    Graphite.SimpleSend("stats.doing_work", "1")
}

Example with Tag and Pickle protocol

package main

import (
	"log"
	"github.com/belazar13/graphite-golang"
	"time"
)

func main() {

	Graphite, err := graphite.NewGraphite("graphite.example.com", 2004)
	if err != nil {
		log.Fatalf("%v", err)
	}

	metric := graphite.NewTaggedMetric("some.value", 100, time.Now().Unix()-100)
	metric.AddTag(&graphite.Tag{Name: "tag1", Value: "value1"})
	metric.AddTag(&graphite.Tag{Name: "tag2", Value: "value2"})

	Graphite.SendTaggedMetric(metric)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graphite

type Graphite struct {
	Host     string
	Port     int
	Protocol string
	Timeout  time.Duration
	Prefix   string
	// contains filtered or unexported fields
}

Graphite is a struct that defines the relevant properties of a graphite connection

func GraphiteFactory

func GraphiteFactory(protocol string, host string, port int, prefix string) (*Graphite, error)

func NewGraphite

func NewGraphite(host string, port int) (*Graphite, error)

NewGraphite is a factory method that's used to create a new Graphite

func NewGraphiteNop

func NewGraphiteNop(host string, port int) *Graphite

NewGraphiteNop is a factory method that returns a Graphite struct but will not actually try to send any packets to a remote host and, instead, will just log. This is useful if you want to use Graphite in a project but don't want to make Graphite a requirement for the project.

func NewGraphiteUDP

func NewGraphiteUDP(host string, port int) (*Graphite, error)

When a UDP connection to Graphite is required

func NewGraphiteWithMetricPrefix

func NewGraphiteWithMetricPrefix(host string, port int, prefix string) (*Graphite, error)

NewGraphiteWithMetricPrefix is a factory method that's used to create a new Graphite with a metric prefix

func (*Graphite) Connect

func (graphite *Graphite) Connect() error

Given a Graphite struct, Connect populates the Graphite.conn field with an appropriate TCP connection

func (*Graphite) Disconnect

func (graphite *Graphite) Disconnect() error

Given a Graphite struct, Disconnect closes the Graphite.conn field

func (*Graphite) IsNop

func (graphite *Graphite) IsNop() bool

IsNop is a getter for *graphite.Graphite.nop

func (*Graphite) SendMetric

func (graphite *Graphite) SendMetric(metric Metric) error

Given a Metric struct, the SendMetric method sends the supplied metric to the Graphite connection that the method is called upon

func (*Graphite) SendMetrics

func (graphite *Graphite) SendMetrics(metrics []Metric) error

Given a slice of Metrics, the SendMetrics method sends the metrics, as a batch, to the Graphite connection that the method is called upon

func (*Graphite) SendTaggedMetric

func (graphite *Graphite) SendTaggedMetric(metric *TaggedMetric) error

Given a TaggedMetric struct, the SendTaggedMetric method sends the supplied metric to the Graphite connection that the method is called upon

func (*Graphite) SendTaggedMetrics

func (graphite *Graphite) SendTaggedMetrics(metrics []*TaggedMetric) error

Given a slice of TaggedMetric, the SendTaggedMetrics method sends the metrics, as a batch, to the Graphite connection that the method is called upon

func (*Graphite) SimpleSend

func (graphite *Graphite) SimpleSend(stat string, value string) error

The SimpleSend method can be used to just pass a metric name and value and have it be sent to the Graphite host with the current timestamp

type Metric

type Metric struct {
	Name      string
	Value     string
	Timestamp int64
}

Metric is a struct that defines the relevant properties of a graphite metric

func NewMetric

func NewMetric(name, value string, timestamp int64) Metric

func (Metric) String

func (metric Metric) String() string

type Tag

type Tag struct {
	Name  string
	Value string
}

func (Tag) String

func (tag Tag) String() string

type TaggedMetric

type TaggedMetric struct {
	Name      string
	Value     int
	Timestamp int64
	Tags      []*Tag
}

TaggedMetric is a struct that defines the relevant properties of a graphite metric for Pickle format

func NewTaggedMetric

func NewTaggedMetric(name string, value int, timestamp int64) *TaggedMetric

func (*TaggedMetric) AddTag

func (metric *TaggedMetric) AddTag(tag *Tag)

func (*TaggedMetric) GetTags

func (metric *TaggedMetric) GetTags() string

func (*TaggedMetric) String

func (metric *TaggedMetric) String() string

Jump to

Keyboard shortcuts

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