Documentation ¶
Overview ¶
Package influx is a go-metrics to influx DB reporter implementation.
Example ¶
package main import ( "context" "time" influx "github.com/fln/go-metrics-influx" metrics "github.com/rcrowley/go-metrics" "github.com/sirupsen/logrus" ) func worker() { c := metrics.NewCounter() metrics.Register("foo", c) for { c.Inc(1) time.Sleep(time.Second) } } func main() { // Create context with cancel callback ctx, stop := context.WithCancel(context.Background()) go influx.NewReporter( metrics.DefaultRegistry, // go-metrics registry 5*time.Second, // report interval "http://user:pass@localhost:8086", // Influx URL and credentials "app-metrics", // databse name ). Tags(map[string]string{"instance": "app@localhost"}). Context(ctx). Logger(logrus.WithField("thread", "go-metrics-influx")). Run() // ... go worker() // ... // Stop reporter goroutine after 5 minutes time.Sleep(5 * time.Minute) stop() }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter holds configuration of go-metrics influx exporter. It can be configured only be public setter methods.
func NewReporter ¶
func NewReporter(registry metrics.Registry, interval time.Duration, url string, db string) *Reporter
NewReporter creates a new instance of influx metrcs reporter. It may be further configured with helper methods. It will not start exporting metrics until Run() is called.
func (*Reporter) Context ¶
Context assigns a context to this reporter. Context is only used to stop reporter Run() method.
func (*Reporter) Logger ¶
func (r *Reporter) Logger(log logrus.FieldLogger) *Reporter
Logger sets optional logrus logger for error reporting.
func (*Reporter) Precision ¶
Precision changes the timestamp precision used in reported data points. By default timestamps are reported with a seconds precision. Having higher than seconds precision should be useful only when export interval is less than a second.