Documentation
¶
Overview ¶
Package graphite provides simple Graphite client
Example ¶
package main
import (
"log"
"github.com/jtaczanowski/go-graphite-client"
)
func main() {
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,
}
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client - struct with Graphite connection settings.
func (*Client) SendData ¶
SendData - creates new connection to Graphite server and pushes provided batch of metrics in this single connection, thread-safe.
Returns error in case of problems establishing, sending data or closing the connection (which should not be a problem with such short-lived connections).
SendData receives as argument map[string]int64 where string is metric name, float64 is metric value, example:
map[string]float64{"test": 1234.1234, "test": 1234.1234}
func (*Client) SendDataWithTimeStamp ¶ added in v1.1.0
SendDataWithTimeStamp - creates new connection to Graphite server and pushes provided batch of metrics in this single connection, thread-safe.
Returns error in case of problems establishing, sending data or closing the connection (which should not be a problem with such short-lived connections).
SendData receives as first argument map[string]int64 where string is metric name, float64 is metric value, example:
map[string]float64{"test": 1234.1234, "test": 1234.1234}
and as a second argument Unix timestamp with which the metrics will be sent, example: timeNow().Unix()
