Documentation ¶
Overview ¶
Package metrics is based on github.com/rcrowley/go-metrics and loosely inspired by github.com/vrischmann/go-metrics-influxdb. The main difference of this package and `vrischmann/go-metrics-influxdb` is the API. The API is based on the `go-metrics` api and separates the registry (built into the Reporter) from the measurement/metrics. This enables a global Reporter and the creation of independent metrics distributed across the codebase without passing the Reporter around. A reporter can however be injected into a metrics if needed.
Index ¶
- func CaptureGCStats(d time.Duration)
- func CaptureMemStats(d time.Duration)
- func Register(name string, metric Metric, options ...Option) error
- func SetDefaultReporter(reporter Reporter)
- type Counter
- type Gauge
- type GaugeFloat64
- type Histogram
- type Meter
- type Metric
- type Option
- type Reporter
- type ReporterOption
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureGCStats ¶ added in v0.1.3
CaptureGCStats starts capturing GC stats on the default reporter.
func CaptureMemStats ¶ added in v0.1.3
CaptureMemStats starts capturing Memory stats on the default reporter.
func Register ¶
Register registers a custom metric to the default reporter. Data points from a registered metric will be collected via the AddPoints endpoint and then sent to influxDB.
This function is only needed for custom metrics. Functions creating a metric in this package register themselves.
func SetDefaultReporter ¶
func SetDefaultReporter(reporter Reporter)
SetDefaultReporter sets the default reporter to be used for all metrics. It can be overwritten per Measurement.
Types ¶
type Counter ¶
type Counter interface { metrics.Counter }
Counter implements go-metrics.Counter and possibly adds a bit functionality.
func NewCounter ¶
NewCounter creates a new counter or retrieves an existing counter with the same name.
type Gauge ¶
type Gauge interface { metrics.Gauge }
Gauge implements go-metrics.Gauge and possibly adds a bit functionality.
type GaugeFloat64 ¶
type GaugeFloat64 interface { metrics.GaugeFloat64 }
GaugeFloat64 implements go-metrics.GaugeFloat64 and possibly adds a bit functionality.
func NewGaugeFloat64 ¶
func NewGaugeFloat64(name string, options ...Option) GaugeFloat64
NewGaugeFloat64 creates a new gauge with float64 or retrieves an existing gauge with the same name.
type Histogram ¶
type Histogram interface { metrics.Histogram }
Histogram implements go-metrics.Histogram and possibly adds a bit functionality.
func NewHistogram ¶
NewHistogram creates a new histogram or retrieves an existing histogram with the same name. By default, this creates a uniform sample with a reservoir size of 100. Provide a different metric via the WithMetric option: e.g. WithMetric(metrics.NewHistogram(metrics.NewUniformSample(100)))
type Meter ¶
type Meter interface { metrics.Meter }
Meter implements go-metrics.Meter and possibly adds a bit functionality.
type Metric ¶
Metric defines an interface to be implemented for custom metrics.
For a metric to be used, it needs to be registered. If no registry was provided to the Reporter, it uses the default registry and can be registered with `metrics.Register(name, metric)`. If a custom registry was provided to the Reporter, either register it to that registry or use the Reporter.Register function to register it.
type Option ¶
type Option func(s *baseMetric)
Option defines an option to be used when creating a new measurement.
func WithMeasurement ¶
WithMeasurement provides a ifluxDB measurement name to the metric.
func WithMetric ¶
func WithMetric(m interface{}) Option
WithMetric injects a github.com/rcrowley/go-metrics metric instead of creating a new one.
func WithReporter ¶
WithReporter sets a reporter to use. If not set the global reporter will be used that can be set via `metrics.SetDefaultReporter`.
type Reporter ¶
type Reporter interface { Run() Register(name string, metric Metric) error Get(name string) (Metric, bool) Tags() map[string]string Stop() }
Reporter defines a metrics reporter. It is responsible for connection handling and sending data to it. It also holds the metrics registry all the metrics get registered to. Implementing the Reporter interface is useful for testing or changing the way the reporter behaves.
func NewReporter ¶
func NewReporter(influxURL, database string, options ...ReporterOption) Reporter
NewReporter creates a new reporter which holds the influxDB connection and sends data to it.
type ReporterOption ¶
type ReporterOption func(r *reporter)
ReporterOption defines an option to be used when creating a reporter.
func Auth ¶
func Auth(user, pass string) ReporterOption
Auth sets user and password for the influxDB connection.
func Interval ¶
func Interval(d time.Duration) ReporterOption
Interval overwrites the default interval of 10 seconds. The interval is used to send the data e.g. every 10 seconds.
func Registry ¶
func Registry(reg metrics.Registry) ReporterOption
Registry uses the given metric registry instead of the global default registry.
func Tags ¶
func Tags(tags map[string]string) ReporterOption
Tags allows to add some tags to be added to all metrics sent by this reporter.
func WithGCStats ¶ added in v0.1.3
func WithGCStats() ReporterOption
WithGCStats enables collection of GC stats for this reporter.
func WithMemStats ¶ added in v0.1.3
func WithMemStats() ReporterOption
WithMemStats enables collection of memory stats for this reporter.