Skip to content

Commit

Permalink
feat: set default chain metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Jul 18, 2023
1 parent 837e3fa commit 12d3165
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
4 changes: 4 additions & 0 deletions pkg/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pkg

import (
configTypes "main/pkg/config/types"
"main/pkg/types"
"os"
"os/signal"
Expand All @@ -21,6 +22,7 @@ import (

type App struct {
Logger zerolog.Logger
Chains []*configTypes.Chain
NodesManager *nodesManagerPkg.NodesManager
Reporters []reportersPkg.Reporter
DataFetchers map[string]*data_fetcher.DataFetcher
Expand Down Expand Up @@ -55,6 +57,7 @@ func NewApp(config *config.AppConfig, version string) *App {

return &App{
Logger: logger.With().Str("component", "app").Logger(),
Chains: config.Chains,
Reporters: reporters,
NodesManager: nodesManager,
DataFetchers: dataFetchers,
Expand All @@ -67,6 +70,7 @@ func NewApp(config *config.AppConfig, version string) *App {
func (a *App) Start() {
go a.MetricsManager.Start()
a.MetricsManager.LogAppVersion(a.Version)
a.MetricsManager.SetAllDefaultMetrics(a.Chains)

for _, reporter := range a.Reporters {
reporter.Init()
Expand Down
43 changes: 24 additions & 19 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type Manager struct {
nodeConnectedCollector *prometheus.GaugeVec
reconnectsCounter *prometheus.CounterVec

// successfulQueriesCollector *prometheus.CounterVec
//failedQueriesCollector *prometheus.CounterVec
successfulQueriesCollector *prometheus.CounterVec
failedQueriesCollector *prometheus.CounterVec

eventsTotalCounter *prometheus.CounterVec
eventsFilteredCounter *prometheus.CounterVec
Expand Down Expand Up @@ -58,14 +58,14 @@ func NewManager(logger *zerolog.Logger, config configPkg.MetricsConfig) *Manager
Name: constants.PrometheusMetricsPrefix + "node_connected",
Help: "Whether the node is successfully connected (1 if yes, 0 if no)",
}, []string{"chain", "node"}),
//successfulQueriesCollector: promauto.NewCounterVec(prometheus.CounterOpts{
// Name: constants.PrometheusMetricsPrefix + "node_successful_queries_total",
// Help: "Counter of successful node queries",
// }, []string{"chain", "node", "type"}),
//failedQueriesCollector: promauto.NewCounterVec(prometheus.CounterOpts{
// Name: constants.PrometheusMetricsPrefix + "node_failed_queries_total",
// Help: "Counter of failed node queries",
//}, []string{"chain", "node", "type"}),
successfulQueriesCollector: promauto.NewCounterVec(prometheus.CounterOpts{
Name: constants.PrometheusMetricsPrefix + "node_successful_queries_total",
Help: "Counter of successful node queries",
}, []string{"chain", "node", "type"}),
failedQueriesCollector: promauto.NewCounterVec(prometheus.CounterOpts{
Name: constants.PrometheusMetricsPrefix + "node_failed_queries_total",
Help: "Counter of failed node queries",
}, []string{"chain", "node", "type"}),
reportsCounter: promauto.NewCounterVec(prometheus.CounterOpts{
Name: constants.PrometheusMetricsPrefix + "node_reports",
Help: "Counter of reports send",
Expand Down Expand Up @@ -109,6 +109,11 @@ func NewManager(logger *zerolog.Logger, config configPkg.MetricsConfig) *Manager
}
}

func (m *Manager) SetAllDefaultMetrics(chains []*configTypes.Chain) {
for _, chain := range chains {
m.SetDefaultMetrics(chain)
}
}
func (m *Manager) SetDefaultMetrics(chain *configTypes.Chain) {
m.reportsCounter.
With(prometheus.Labels{"chain": chain.Name}).
Expand Down Expand Up @@ -142,15 +147,15 @@ func (m *Manager) SetDefaultMetrics(chain *configTypes.Chain) {
Add(0)
}

// for _, node := range chain.APINodes {
// m.successfulQueriesCollector.
// With(prometheus.Labels{"chain": chain.Name, "node": node}).
// Add(0)
//
// m.failedQueriesCollector.
// With(prometheus.Labels{"chain": chain.Name, "node": node}).
// Add(0)
//}
for _, node := range chain.APINodes {
m.successfulQueriesCollector.
With(prometheus.Labels{"chain": chain.Name, "node": node}).
Add(0)

m.failedQueriesCollector.
With(prometheus.Labels{"chain": chain.Name, "node": node}).
Add(0)
}
}

func (m *Manager) Start() {
Expand Down

0 comments on commit 12d3165

Please sign in to comment.