Documentation ¶
Overview ¶
Package influx is a go-metrics to influx DB reporter implementation.
Example ¶
package main import ( "context" "sync" "time" influx "github.com/dbadv/go-metrics-influx" metrics "github.com/rcrowley/go-metrics" "github.com/sirupsen/logrus" ) func worker() { c := metrics.NewCounter() if err := metrics.Register("foo", c); err != nil { // Handle err. } for { c.Inc(1) time.Sleep(time.Second) } } func main() { ctx, stop := context.WithCancel(context.Background()) var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() influx.New( metrics.DefaultRegistry, // go-metrics registry "http://localhost:8086", // influx URL "user:pass", // influx token "org", // org name "bucket", // bucket name influx.Tags(map[string]string{"instance": "app@localhost"}), influx.Logger(logrus.WithField("thread", "go-metrics-influx")), ).Run(ctx) }() // ... go worker() // ... // Stop reporter goroutine after 5 minutes. time.Sleep(5 * time.Minute) stop() // Wait for graceful shutdown. wg.Wait() }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Reporter)
Option allows to configure optional reporter parameters.
func Interval ¶
Interval specifies how often metrics should be reported to influxdb. By default it will be done every 10 seconds.
func Logger ¶
func Logger(log logrus.FieldLogger) Option
Logger sets custom logrus logger for error reporting.
func Precision ¶
Precision changes the duration precision used in reported data points. By default timestamps are reported with a 1 second precision. Having higher than seconds precision should be useful only when export interval is less than a second.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter holds configuration of go-metrics influx exporter. It should only be created using New function.
func New ¶
func New( reg metrics.Registry, url string, token string, org string, bucket string, opts ...Option, ) *Reporter
New creates a new instance of influx metrics reporter. Variadic function parameters can be used to further configure reporter. It will not start exporting metrics until Run() is called.