2017-08-23 18:46:03 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-kit/kit/metrics"
|
|
|
|
"github.com/go-kit/kit/metrics/multi"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Registry has to implemented by any system that wants to monitor and expose metrics.
|
|
|
|
type Registry interface {
|
2019-07-18 19:36:05 +00:00
|
|
|
// IsEpEnabled shows whether metrics instrumentation is enabled on entry points.
|
|
|
|
IsEpEnabled() bool
|
|
|
|
// IsSvcEnabled shows whether metrics instrumentation is enabled on services.
|
|
|
|
IsSvcEnabled() bool
|
2018-07-03 08:02:03 +00:00
|
|
|
|
2018-01-26 10:58:03 +00:00
|
|
|
// server metrics
|
|
|
|
ConfigReloadsCounter() metrics.Counter
|
|
|
|
ConfigReloadsFailureCounter() metrics.Counter
|
|
|
|
LastConfigReloadSuccessGauge() metrics.Gauge
|
|
|
|
LastConfigReloadFailureGauge() metrics.Gauge
|
|
|
|
|
|
|
|
// entry point metrics
|
2019-07-18 19:36:05 +00:00
|
|
|
EntryPointReqsCounter() metrics.Counter
|
|
|
|
EntryPointReqDurationHistogram() metrics.Histogram
|
|
|
|
EntryPointOpenConnsGauge() metrics.Gauge
|
2018-01-26 10:58:03 +00:00
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
// service metrics
|
|
|
|
ServiceReqsCounter() metrics.Counter
|
|
|
|
ServiceReqDurationHistogram() metrics.Histogram
|
|
|
|
ServiceOpenConnsGauge() metrics.Gauge
|
|
|
|
ServiceRetriesCounter() metrics.Counter
|
|
|
|
ServiceServerUpGauge() metrics.Gauge
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewVoidRegistry is a noop implementation of metrics.Registry.
|
|
|
|
// It is used to avoid nil checking in components that do metric collections.
|
|
|
|
func NewVoidRegistry() Registry {
|
|
|
|
return NewMultiRegistry([]Registry{})
|
2017-08-23 18:46:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 10:58:03 +00:00
|
|
|
// NewMultiRegistry is an implementation of metrics.Registry that wraps multiple registries.
|
|
|
|
// It handles the case when a registry hasn't registered some metric and returns nil.
|
|
|
|
// This allows for feature imparity between the different metric implementations.
|
2017-08-23 18:46:03 +00:00
|
|
|
func NewMultiRegistry(registries []Registry) Registry {
|
2018-07-03 08:02:03 +00:00
|
|
|
var configReloadsCounter []metrics.Counter
|
|
|
|
var configReloadsFailureCounter []metrics.Counter
|
|
|
|
var lastConfigReloadSuccessGauge []metrics.Gauge
|
|
|
|
var lastConfigReloadFailureGauge []metrics.Gauge
|
2019-07-18 19:36:05 +00:00
|
|
|
var entryPointReqsCounter []metrics.Counter
|
|
|
|
var entryPointReqDurationHistogram []metrics.Histogram
|
|
|
|
var entryPointOpenConnsGauge []metrics.Gauge
|
|
|
|
var serviceReqsCounter []metrics.Counter
|
|
|
|
var serviceReqDurationHistogram []metrics.Histogram
|
|
|
|
var serviceOpenConnsGauge []metrics.Gauge
|
|
|
|
var serviceRetriesCounter []metrics.Counter
|
|
|
|
var serviceServerUpGauge []metrics.Gauge
|
2017-08-23 18:46:03 +00:00
|
|
|
|
|
|
|
for _, r := range registries {
|
2018-01-26 10:58:03 +00:00
|
|
|
if r.ConfigReloadsCounter() != nil {
|
|
|
|
configReloadsCounter = append(configReloadsCounter, r.ConfigReloadsCounter())
|
|
|
|
}
|
|
|
|
if r.ConfigReloadsFailureCounter() != nil {
|
|
|
|
configReloadsFailureCounter = append(configReloadsFailureCounter, r.ConfigReloadsFailureCounter())
|
|
|
|
}
|
|
|
|
if r.LastConfigReloadSuccessGauge() != nil {
|
|
|
|
lastConfigReloadSuccessGauge = append(lastConfigReloadSuccessGauge, r.LastConfigReloadSuccessGauge())
|
|
|
|
}
|
|
|
|
if r.LastConfigReloadFailureGauge() != nil {
|
|
|
|
lastConfigReloadFailureGauge = append(lastConfigReloadFailureGauge, r.LastConfigReloadFailureGauge())
|
|
|
|
}
|
2019-07-18 19:36:05 +00:00
|
|
|
if r.EntryPointReqsCounter() != nil {
|
|
|
|
entryPointReqsCounter = append(entryPointReqsCounter, r.EntryPointReqsCounter())
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2019-07-18 19:36:05 +00:00
|
|
|
if r.EntryPointReqDurationHistogram() != nil {
|
|
|
|
entryPointReqDurationHistogram = append(entryPointReqDurationHistogram, r.EntryPointReqDurationHistogram())
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2019-07-18 19:36:05 +00:00
|
|
|
if r.EntryPointOpenConnsGauge() != nil {
|
|
|
|
entryPointOpenConnsGauge = append(entryPointOpenConnsGauge, r.EntryPointOpenConnsGauge())
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2019-07-18 19:36:05 +00:00
|
|
|
if r.ServiceReqsCounter() != nil {
|
|
|
|
serviceReqsCounter = append(serviceReqsCounter, r.ServiceReqsCounter())
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2019-07-18 19:36:05 +00:00
|
|
|
if r.ServiceReqDurationHistogram() != nil {
|
|
|
|
serviceReqDurationHistogram = append(serviceReqDurationHistogram, r.ServiceReqDurationHistogram())
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2019-07-18 19:36:05 +00:00
|
|
|
if r.ServiceOpenConnsGauge() != nil {
|
|
|
|
serviceOpenConnsGauge = append(serviceOpenConnsGauge, r.ServiceOpenConnsGauge())
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2019-07-18 19:36:05 +00:00
|
|
|
if r.ServiceRetriesCounter() != nil {
|
|
|
|
serviceRetriesCounter = append(serviceRetriesCounter, r.ServiceRetriesCounter())
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2019-07-18 19:36:05 +00:00
|
|
|
if r.ServiceServerUpGauge() != nil {
|
|
|
|
serviceServerUpGauge = append(serviceServerUpGauge, r.ServiceServerUpGauge())
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2017-08-23 18:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &standardRegistry{
|
2019-07-18 19:36:05 +00:00
|
|
|
epEnabled: len(entryPointReqsCounter) > 0 || len(entryPointReqDurationHistogram) > 0 || len(entryPointOpenConnsGauge) > 0,
|
|
|
|
svcEnabled: len(serviceReqsCounter) > 0 || len(serviceReqDurationHistogram) > 0 || len(serviceOpenConnsGauge) > 0 || len(serviceRetriesCounter) > 0 || len(serviceServerUpGauge) > 0,
|
2018-01-26 10:58:03 +00:00
|
|
|
configReloadsCounter: multi.NewCounter(configReloadsCounter...),
|
|
|
|
configReloadsFailureCounter: multi.NewCounter(configReloadsFailureCounter...),
|
|
|
|
lastConfigReloadSuccessGauge: multi.NewGauge(lastConfigReloadSuccessGauge...),
|
|
|
|
lastConfigReloadFailureGauge: multi.NewGauge(lastConfigReloadFailureGauge...),
|
2019-07-18 19:36:05 +00:00
|
|
|
entryPointReqsCounter: multi.NewCounter(entryPointReqsCounter...),
|
|
|
|
entryPointReqDurationHistogram: multi.NewHistogram(entryPointReqDurationHistogram...),
|
|
|
|
entryPointOpenConnsGauge: multi.NewGauge(entryPointOpenConnsGauge...),
|
|
|
|
serviceReqsCounter: multi.NewCounter(serviceReqsCounter...),
|
|
|
|
serviceReqDurationHistogram: multi.NewHistogram(serviceReqDurationHistogram...),
|
|
|
|
serviceOpenConnsGauge: multi.NewGauge(serviceOpenConnsGauge...),
|
|
|
|
serviceRetriesCounter: multi.NewCounter(serviceRetriesCounter...),
|
|
|
|
serviceServerUpGauge: multi.NewGauge(serviceServerUpGauge...),
|
2017-08-23 18:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type standardRegistry struct {
|
2019-07-18 19:36:05 +00:00
|
|
|
epEnabled bool
|
|
|
|
svcEnabled bool
|
2018-01-26 10:58:03 +00:00
|
|
|
configReloadsCounter metrics.Counter
|
|
|
|
configReloadsFailureCounter metrics.Counter
|
|
|
|
lastConfigReloadSuccessGauge metrics.Gauge
|
|
|
|
lastConfigReloadFailureGauge metrics.Gauge
|
2019-07-18 19:36:05 +00:00
|
|
|
entryPointReqsCounter metrics.Counter
|
|
|
|
entryPointReqDurationHistogram metrics.Histogram
|
|
|
|
entryPointOpenConnsGauge metrics.Gauge
|
|
|
|
serviceReqsCounter metrics.Counter
|
|
|
|
serviceReqDurationHistogram metrics.Histogram
|
|
|
|
serviceOpenConnsGauge metrics.Gauge
|
|
|
|
serviceRetriesCounter metrics.Counter
|
|
|
|
serviceServerUpGauge metrics.Gauge
|
2017-08-23 18:46:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
func (r *standardRegistry) IsEpEnabled() bool {
|
|
|
|
return r.epEnabled
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *standardRegistry) IsSvcEnabled() bool {
|
|
|
|
return r.svcEnabled
|
2017-08-23 18:46:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 10:58:03 +00:00
|
|
|
func (r *standardRegistry) ConfigReloadsCounter() metrics.Counter {
|
|
|
|
return r.configReloadsCounter
|
2017-08-23 18:46:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 10:58:03 +00:00
|
|
|
func (r *standardRegistry) ConfigReloadsFailureCounter() metrics.Counter {
|
|
|
|
return r.configReloadsFailureCounter
|
2017-08-23 18:46:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 10:58:03 +00:00
|
|
|
func (r *standardRegistry) LastConfigReloadSuccessGauge() metrics.Gauge {
|
|
|
|
return r.lastConfigReloadSuccessGauge
|
2017-08-23 18:46:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 10:58:03 +00:00
|
|
|
func (r *standardRegistry) LastConfigReloadFailureGauge() metrics.Gauge {
|
|
|
|
return r.lastConfigReloadFailureGauge
|
2017-08-23 18:46:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
func (r *standardRegistry) EntryPointReqsCounter() metrics.Counter {
|
|
|
|
return r.entryPointReqsCounter
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
func (r *standardRegistry) EntryPointReqDurationHistogram() metrics.Histogram {
|
|
|
|
return r.entryPointReqDurationHistogram
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
func (r *standardRegistry) EntryPointOpenConnsGauge() metrics.Gauge {
|
|
|
|
return r.entryPointOpenConnsGauge
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
func (r *standardRegistry) ServiceReqsCounter() metrics.Counter {
|
|
|
|
return r.serviceReqsCounter
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
func (r *standardRegistry) ServiceReqDurationHistogram() metrics.Histogram {
|
|
|
|
return r.serviceReqDurationHistogram
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2017-08-23 18:46:03 +00:00
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
func (r *standardRegistry) ServiceOpenConnsGauge() metrics.Gauge {
|
|
|
|
return r.serviceOpenConnsGauge
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2017-08-23 18:46:03 +00:00
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
func (r *standardRegistry) ServiceRetriesCounter() metrics.Counter {
|
|
|
|
return r.serviceRetriesCounter
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|
2017-08-23 18:46:03 +00:00
|
|
|
|
2019-07-18 19:36:05 +00:00
|
|
|
func (r *standardRegistry) ServiceServerUpGauge() metrics.Gauge {
|
|
|
|
return r.serviceServerUpGauge
|
2018-01-26 10:58:03 +00:00
|
|
|
}
|