diff --git a/cmd/cosmos-node-exporter.go b/cmd/cosmos-node-exporter.go index d92e80f..9f3dd08 100644 --- a/cmd/cosmos-node-exporter.go +++ b/cmd/cosmos-node-exporter.go @@ -24,7 +24,7 @@ func Execute(configPath string) { } log := logger.GetLogger(appConfig.LogConfig) - app := pkg.NewApp(log, appConfig) + app := pkg.NewApp(log, appConfig, version) http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) { app.HandleRequest(w, r) diff --git a/pkg/app.go b/pkg/app.go index 3d7b9ce..5baab37 100644 --- a/pkg/app.go +++ b/pkg/app.go @@ -5,6 +5,7 @@ import ( "main/pkg/constants" cosmovisorPkg "main/pkg/cosmovisor" githubPkg "main/pkg/github" + "main/pkg/queriers/app" nodeStats "main/pkg/queriers/node_stats" "main/pkg/queriers/upgrades" "main/pkg/queriers/versions" @@ -25,11 +26,13 @@ import ( type App struct { Logger zerolog.Logger Queriers []types.Querier + Version string } func NewApp( logger *zerolog.Logger, config *config.Config, + version string, ) *App { appLogger := logger.With().Str("component", "app").Logger() @@ -53,6 +56,7 @@ func NewApp( nodeStats.NewQuerier(logger, tendermintRPC), versions.NewQuerier(logger, github, cosmovisor), upgrades.NewQuerier(config, logger, cosmovisor, tendermintRPC), + app.NewQuerier(version), } for _, querier := range queriers { @@ -66,6 +70,7 @@ func NewApp( return &App{ Logger: appLogger, Queriers: queriers, + Version: version, } } diff --git a/pkg/queriers/app/querier.go b/pkg/queriers/app/querier.go new file mode 100644 index 0000000..aef20de --- /dev/null +++ b/pkg/queriers/app/querier.go @@ -0,0 +1,42 @@ +package app + +import ( + "main/pkg/constants" + "main/pkg/query_info" + + "github.com/prometheus/client_golang/prometheus" +) + +type Querier struct { + Version string +} + +func NewQuerier(version string) *Querier { + return &Querier{ + Version: version, + } +} + +func (u *Querier) Enabled() bool { + return true +} + +func (u *Querier) Name() string { + return "app-querier" +} + +func (u *Querier) Get() ([]prometheus.Collector, []query_info.QueryInfo) { + appVersionGauge := prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: constants.MetricsPrefix + "version", + Help: "The app info and version.", + }, + []string{"version"}, + ) + + appVersionGauge. + With(prometheus.Labels{"version": u.Version}). + Set(1) + + return []prometheus.Collector{appVersionGauge}, []query_info.QueryInfo{} +}