Skip to content

Commit

Permalink
feat: add start time metric (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno authored Jan 5, 2024
1 parent 9218088 commit 4317583
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewApp(configPath string) *App {
queriers := []types.Querier{
queriersPkg.NewPriceQuerier(appConfig, coingecko),
queriersPkg.NewBalanceQuerier(appConfig, log),
queriersPkg.NewUptimeQuerier(),
}

return &App{
Expand Down
31 changes: 31 additions & 0 deletions pkg/queriers/uptime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package queriers

import (
"main/pkg/types"
"time"

"github.com/prometheus/client_golang/prometheus"
)

type UptimeQuerier struct {
StartTime time.Time
}

func NewUptimeQuerier() *UptimeQuerier {
return &UptimeQuerier{
StartTime: time.Now(),
}
}

func (u *UptimeQuerier) GetMetrics() ([]prometheus.Collector, []types.QueryInfo) {
uptimeMetricsGauge := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "cosmos_wallets_exporter_start_time",
Help: "Unix timestamp on when the app was started. Useful for annotations.",
},
[]string{},
)

uptimeMetricsGauge.With(prometheus.Labels{}).Set(float64(u.StartTime.Unix()))
return []prometheus.Collector{uptimeMetricsGauge}, []types.QueryInfo{}
}

0 comments on commit 4317583

Please sign in to comment.