项目作者: jtaczanowski

项目描述 :
Simple Golang graphite client
高级语言: Go
项目地址: git://github.com/jtaczanowski/go-graphite-client.git
创建时间: 2019-02-05T16:26:14Z
项目社区:https://github.com/jtaczanowski/go-graphite-client

开源协议:Apache License 2.0

下载


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)

  1. package main
  2. import (
  3. "log"
  4. graphite "github.com/jtaczanowski/go-graphite-client"
  5. )
  6. func Example() {
  7. graphiteClient := graphite.NewClient("localhost", 2003, "metrics.prefix", "tcp")
  8. // metrics map
  9. metricsMap := map[string]float64{
  10. "test_metric": 1234.1234,
  11. "test_metric2": 12345.12345,
  12. }
  13. // append metrics from function which returns map[string]float64 as well
  14. for k, v := range metricsGenerator() {
  15. metricsMap[k] = v
  16. }
  17. // graphiteClient.SendData(data map[string]float64) error - this method expects a map of metrics as an argument
  18. if err := graphiteClient.SendData(metricsMap); err != nil {
  19. log.Printf("Error sending metrics: %v", err)
  20. }
  21. }
  22. func metricsGenerator() map[string]float64 {
  23. return map[string]float64{
  24. "test_metric4": 3.14159265359,
  25. }
  26. }