feat: add ipfs version info to prometheus metrics

Adds `ipfs_info` prometheus metric with version and commit info

```prometheus
ipfs_info{commit="9ea7c6a1-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: 's avatarOli Evans <oli@tableflip.io>
上级 9ea7c6a1
......@@ -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})
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论