Help us shape the future of Go! Take the 2026 Go Developer Survey

graphite

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: Apache-2.0 Imports: 4 Imported by: 6

README

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,
	}
}

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,
	}
}

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 NewClient

func NewClient(Host string, Port int, Prefix string, Protocol string) *Client

NewClient - returns new Client with default connection timeout set to 3s.

func (*Client) SendData

func (g *Client) SendData(data map[string]float64) error

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

func (g *Client) SendDataWithTimeStamp(data map[string]float64, timestamp int64) error

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()

Jump to

Keyboard shortcuts

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