Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metrics ¶
type Metrics struct{}
Metrics prototypes Example:
Counter *prometheus.CounterVec ResponseTime *prometheus.HistogramVec
func NewMetrics ¶
Method for creation new custom Prometheus metrics Example:
pm := &Metrics{
Counter: prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "servicename_requests_total",
Help: "Description",
ConstLabels: map[string]string{
"version": version,
"hash": hash,
"buildTime": buildTime,
},
},
[]string{"endpoint"},
),
ResponseTime: prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "servicename_response_time_seconds",
Help: "Description",
ConstLabels: map[string]string{
"version": version,
"hash": hash,
"buildTime": buildTime,
},
},
[]string{"endpoint"},
),
}
prometheus.Register(pm.Counter)
prometheus.Register(pm.ResponseTime)
type MetricsManager ¶
type MetricsManager struct {
// contains filtered or unexported fields
}
func NewMetricsManager ¶
func NewMetricsManager(version, hash, buildTime string) *MetricsManager
func (*MetricsManager) ServeHTTP ¶
func (pmm *MetricsManager) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
Main middleware method to collect metrics for Prometheus. Example:
start := time.Now() next(rw, r) Request counter metric pmm.prometheusMetrics.Counter.WithLabelValues(r.URL.Path).Inc() Response time metric pmm.prometheusMetrics.ResponseTime.WithLabelValues(r.URL.Path).Observe(time.Since(start).Seconds())
Click to show internal directories.
Click to hide internal directories.