2020-08-18 10:27:50 +03:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
var (
|
|
|
|
// The Prometheus metrics will be made available on this port:
|
|
|
|
defaultPrometheusListenAddress = ":9000"
|
|
|
|
// This is the endpoint where the Prometheus metrics will be made available ("/metrics" is the default with Prometheus):
|
|
|
|
defaultPath = "/metrics"
|
2020-08-21 11:57:10 +03:00
|
|
|
// defaultPercentiles is the default spread of percentiles/quantiles we maintain for timings / histogram metrics:
|
|
|
|
defaultPercentiles = []float64{0, 0.5, 0.75, 0.90, 0.95, 0.98, 0.99, 1}
|
2020-08-18 10:27:50 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Option powers the configuration for metrics implementations:
|
|
|
|
type Option func(*Options)
|
|
|
|
|
|
|
|
// Options for metrics implementations:
|
|
|
|
type Options struct {
|
2020-08-21 11:57:10 +03:00
|
|
|
Address string
|
|
|
|
DefaultTags Tags
|
|
|
|
Path string
|
|
|
|
Percentiles []float64
|
2020-08-18 10:27:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewOptions prepares a set of options:
|
|
|
|
func NewOptions(opt ...Option) Options {
|
|
|
|
opts := Options{
|
2020-08-21 11:57:10 +03:00
|
|
|
Address: defaultPrometheusListenAddress,
|
|
|
|
DefaultTags: make(Tags),
|
|
|
|
Path: defaultPath,
|
|
|
|
Percentiles: defaultPercentiles,
|
2020-08-18 10:27:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, o := range opt {
|
|
|
|
o(&opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
|
|
|
|
// Path used to serve metrics over HTTP:
|
|
|
|
func Path(value string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Path = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Address is the listen address to serve metrics on:
|
|
|
|
func Address(value string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Address = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultTags will be added to every metric:
|
|
|
|
func DefaultTags(value Tags) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.DefaultTags = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-21 11:57:10 +03:00
|
|
|
// Percentiles defines the desired spread of statistics for histogram / timing metrics:
|
|
|
|
func Percentiles(value []float64) Option {
|
2020-08-18 10:27:50 +03:00
|
|
|
return func(o *Options) {
|
2020-08-21 11:57:10 +03:00
|
|
|
o.Percentiles = value
|
2020-08-18 10:27:50 +03:00
|
|
|
}
|
|
|
|
}
|