Skip to content

Instantly share code, notes, and snippets.

@ipedrazas
Created April 23, 2018 13:31
Show Gist options
  • Save ipedrazas/aa2b5550fd38446c131db0913e389b5e to your computer and use it in GitHub Desktop.
Save ipedrazas/aa2b5550fd38446c131db0913e389b5e to your computer and use it in GitHub Desktop.
instrument app - prometheus
// https://github.com/stefanprodan/k8s-podinfo/blob/master/pkg/server/instrument.go
func NewInstrument() *Instrument {
// used for monitoring and alerting (RED method)
histogram := prometheus.NewHistogramVec(prometheus.HistogramOpts{
Subsystem: "http",
Name: "requests",
Help: "Seconds spent serving HTTP requests.",
Buckets: prometheus.DefBuckets,
}, []string{"method", "path", "status"})
// used for horizontal pod auto-scaling (Kubernetes HPA v2)
counter := prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "http",
Name: "requests_total",
Help: "The total number of HTTP requests.",
},
[]string{"status"},
)
prometheus.MustRegister(histogram)
prometheus.MustRegister(counter)
return &Instrument{
Histogram: histogram,
Counter: counter,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment