Skip to content

Commit

Permalink
feat: add ipfs version info to prometheus metrics
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
olizilla committed Sep 30, 2019
1 parent 9ea7c6a commit bbe2f50
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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})

Expand Down

0 comments on commit bbe2f50

Please sign in to comment.