Instrumenting services using gauges
Gauges are very similar to counters. The only significant difference is that we can not only increment, but also decrease their values. We'll continue exploring vfarcic/docker-flow-swarm-listener GitHub repository for an example of a gauge.
Since gauge is almost identical to counter, we won't go into many details but only briefly explore a few snippets.
Just as with a counter, we need to declare a variable that defines the type of the metric. A simple example is as follows:
var serviceGauge = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Subsystem: "docker_flow", Name: "service_count", Help: "Service gauge", }, []string{"service"}, )
Next, we need to register it with Prometheus. We'll reuse the code from the init
function where we defined the errorCounter
and add serviceGauge
.
func init() { prometheus.MustRegister(errorCounter, serviceGauge) }
There's also a function that simplifies the usage of the metric:
func RecordService...