api/pkg/metrics/metrics_factory.go
baez90 57a7e10e74
Add Prometheus metrics (#10)
* Add Prometheus metrics

- cleanup
- update dependencies
- improve parsing of options where possible
- Update Go to latest version
2020-10-02 11:56:48 +02:00

47 lines
1.1 KiB
Go

package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
const (
metricNamespace = "inetmock"
)
func Gauge(subsystem, name, help string, labelNames ...string) (*prometheus.GaugeVec, error) {
vec := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Subsystem: subsystem,
Name: name,
Help: help,
}, labelNames)
return vec, prometheus.Register(vec)
}
func Histogram(subsystem, name, help string, buckets []float64, labelNames ...string) (*prometheus.HistogramVec, error) {
vec := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: metricNamespace,
Subsystem: subsystem,
Name: name,
Help: help,
Buckets: buckets,
},
labelNames,
)
return vec, prometheus.Register(vec)
}
func Counter(subsystem, name, help string, labelNames ...string) (*prometheus.CounterVec, error) {
vec := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Subsystem: subsystem,
Name: name,
Help: help,
},
labelNames,
)
return vec, prometheus.Register(vec)
}