From bbe2f5077e793e207f7f01c26468442fd4897057 Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Mon, 30 Sep 2019 15:41:29 +0100 Subject: [PATCH] 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 --- cmd/ipfs/daemon.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 70ace8036b7..42c37c25896 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -33,7 +33,8 @@ import ( goprocess "github.com/jbenet/goprocess" ma "github.com/multiformats/go-multiaddr" manet "github.com/multiformats/go-multiaddr-net" - "github.com/prometheus/client_golang/prometheus" + prometheus "github.com/prometheus/client_golang/prometheus" + promauto "github.com/prometheus/client_golang/prometheus/promauto" ) const ( @@ -414,6 +415,18 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment } } + // Add ipfs version info to prometheous metrics + var ipfsInfoMetric = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ipfs_info", + Help: "IPFS version information.", + }, []string{"version", "commit"}) + + // Setting to 1 lets us multiply it with other stats to add the version labels + ipfsInfoMetric.With(prometheus.Labels{ + "version": version.CurrentVersionNumber, + "commit": version.CurrentCommit, + }).Set(1) + // initialize metrics collector prometheus.MustRegister(&corehttp.IpfsNodeCollector{Node: node})