Skip to content

jtaczanowski/go-graphite-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-graphite-client Build Status Coverage Status Go Report Card

go-graphite-client - Simple Golang Graphite client which allows sending batches of metrics in single connection.

The optimal use of the library is to collect set of metrics for current minute in single map[string]float64 and after that pass it to Client.SendData() method. Client.SendData() method creates a new connection to Graphite server every time it's called and pushes all metric trough it.

Example usage (taken from example_text.go)

package main

import (
	"log"

	graphite "github.com/jtaczanowski/go-graphite-client"
)

func Example() {
	graphiteClient := graphite.NewClient("localhost", 2003, "metrics.prefix", "tcp")

	// metrics map
	metricsMap := map[string]float64{
		"test_metric":  1234.1234,
		"test_metric2": 12345.12345,
	}

	// append metrics from function which returns map[string]float64 as well
	for k, v := range metricsGenerator() {
		metricsMap[k] = v
	}

	// graphiteClient.SendData(data map[string]float64) error - this method expects a map of metrics as an argument
	if err := graphiteClient.SendData(metricsMap); err != nil {
		log.Printf("Error sending metrics: %v", err)
	}
}

func metricsGenerator() map[string]float64 {
	return map[string]float64{
		"test_metric4": 3.14159265359,
	}
}