@cryptotaxi247 / kubo / commits / bbe2f5077

feat: add ipfs version info to prometheus metrics

Adds `ipfs_info` prometheus metric with version and commit info ```prometheus ipfs_info{commit="9ea7c6a11-dirty",version="0.5.0-dev"} 1 ``` This follows the same pattern as go and other systems, adding a gauge metric that is set to 1, with the version info addeds as labels. This is a common pattern for prometheus. It lets operators merge version info into other prometheus metrics by multiplying it with the other stat, as described in https://www.robustperception.io/exposing-the-software-version-to-prometheus For example, we already expose the go version info as ```prometheus go_info{version="go1.12.9"} 1 ``` License: MIT Signed-off-by: Oli Evans <oli@tableflip.io>

Oli Evans committed Sep 30, 2019 at 15:41 UTC bbe2f5077e793e207f7f01c26468442fd4897057
1 file changed +14 -1
cmd/ipfs/daemon.go
+14 -1
@@ -33,7 +33,8 @@ import (
33 goprocess "github.com/jbenet/goprocess"
34 ma "github.com/multiformats/go-multiaddr"
35 manet "github.com/multiformats/go-multiaddr-net"
36 - "github.com/prometheus/client_golang/prometheus"
36 + prometheus "github.com/prometheus/client_golang/prometheus"
37 + promauto "github.com/prometheus/client_golang/prometheus/promauto"
38 )
39
40 const (
@@ -414,6 +415,18 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
415 }
416 }
417
418 + // Add ipfs version info to prometheous metrics
419 + var ipfsInfoMetric = promauto.NewGaugeVec(prometheus.GaugeOpts{
420 + Name: "ipfs_info",
421 + Help: "IPFS version information.",
422 + }, []string{"version", "commit"})
423 +
424 + // Setting to 1 lets us multiply it with other stats to add the version labels
425 + ipfsInfoMetric.With(prometheus.Labels{
426 + "version": version.CurrentVersionNumber,
427 + "commit": version.CurrentCommit,
428 + }).Set(1)
429 +
430 // initialize metrics collector
431 prometheus.MustRegister(&corehttp.IpfsNodeCollector{Node: node})
432