Skip to content

Commit

Permalink
feat: add version metric (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored Jul 11, 2023
1 parent fd01dc3 commit 859d60b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/cosmos-node-exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions pkg/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()

Expand All @@ -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 {
Expand All @@ -66,6 +70,7 @@ func NewApp(
return &App{
Logger: appLogger,
Queriers: queriers,
Version: version,
}
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/queriers/app/querier.go
Original file line number Diff line number Diff line change
@@ -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{}
}

0 comments on commit 859d60b

Please sign in to comment.