Created
November 8, 2022 19:55
-
-
Save meshenka/c3de0b9dbaf932a6b4b54e5cb88508f8 to your computer and use it in GitHub Desktop.
prometheus metrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package metric allows to create Prometheus metrics easily. | |
package metric | |
import "github.com/prometheus/client_golang/prometheus" | |
// DefaultHistogramBuckets provides a simple and reusable heatmap setup. | |
var DefaultHistogramBuckets = prometheus.LinearBuckets(0, 0.03, 67) | |
// Namespace is a Prometheus namespace. | |
type Namespace string | |
// RegisterCounter registers a new Prometheus vectorial counter. | |
func (ns Namespace) RegisterCounter(name, help string, labels ...string) *prometheus.CounterVec { | |
opts := prometheus.CounterOpts{ | |
Namespace: string(ns), | |
Name: name, | |
Help: help, | |
} | |
met := prometheus.NewCounterVec(opts, labels) | |
prometheus.MustRegister(met) | |
return met | |
} | |
// RegisterHistogram registers a new Prometheus histogram. | |
func (ns Namespace) RegisterHistogram(name, help string, buckets []float64, labels ...string) *prometheus.HistogramVec { | |
opts := prometheus.HistogramOpts{ | |
Namespace: string(ns), | |
Name: name, | |
Help: help, | |
Buckets: buckets, | |
} | |
met := prometheus.NewHistogramVec(opts, labels) | |
prometheus.MustRegister(met) | |
return met | |
} | |
// RegisterGauge registers a new Prometheus gauge. | |
func (ns Namespace) RegisterGauge(name, help string) prometheus.Gauge { | |
opts := prometheus.GaugeOpts{ | |
Namespace: string(ns), | |
Name: name, | |
Help: help, | |
} | |
met := prometheus.NewGauge(opts) | |
prometheus.MustRegister(met) | |
return met | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment