Newer
Older
Angelo Capossele
committed
package prometheus
import (
"github.com/iotaledger/goshimmer/plugins/autopeering/local"
Angelo Capossele
committed
"github.com/iotaledger/goshimmer/plugins/banner"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/prometheus/client_golang/prometheus"
)
var (
Ching-Hua (Vivian) Lin
committed
infoApp *prometheus.GaugeVec
syncStatus prometheus.Gauge
nodeID string
Angelo Capossele
committed
)
func registerInfoMetrics() {
infoApp = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "iota_info_app",
Help: "Node software name and version.",
},
[]string{"name", "version", "nodeID"},
Angelo Capossele
committed
)
if local.GetInstance() != nil {
nodeID = local.GetInstance().ID().String()
}
infoApp.WithLabelValues(banner.AppName, banner.AppVersion, nodeID).Set(1)
Angelo Capossele
committed
Ching-Hua (Vivian) Lin
committed
syncStatus = prometheus.NewGauge(prometheus.GaugeOpts{
Angelo Capossele
committed
Name: "sync",
Help: "Node sync status.",
})
registry.MustRegister(infoApp)
Ching-Hua (Vivian) Lin
committed
registry.MustRegister(syncStatus)
Angelo Capossele
committed
addCollect(collectInfoMetrics)
}
func collectInfoMetrics() {
Ching-Hua (Vivian) Lin
committed
syncStatus.Set(func() float64 {
Angelo Capossele
committed
if metrics.Synced() {
return 1.0
}
return 0.
}())
}