Skip to content

Commit

Permalink
Add function for calling init metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Nov 12, 2024
1 parent 2f6189b commit 8ca8513
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type Metrics struct {

// All the serviceMetrics interfaces that are registered
serviceMetrics map[chiaService]serviceMetrics

buildInfoMetric *prometheus.Gauge
}

// NewMetrics returns a new instance of metrics
Expand Down Expand Up @@ -128,10 +130,7 @@ func NewMetrics(port uint16, logLevel log.Level) (*Metrics, error) {
// If not, the reconnect handler will handle it later
_, _ = metrics.checkNetwork()

// Init each service's metrics
for _, service := range metrics.serviceMetrics {
service.InitMetrics(metrics.network)
}
metrics.initMetrics()

return metrics, nil
}
Expand All @@ -148,6 +147,13 @@ func (m *Metrics) setNewClient() error {
return nil
}

func (m *Metrics) initMetrics() {
// Init each service's metrics
for _, service := range m.serviceMetrics {
service.InitMetrics(m.network)
}
}

func (m *Metrics) createDBClient() error {
var err error

Expand Down Expand Up @@ -327,10 +333,7 @@ func (m *Metrics) OpenWebsocket() error {
if changed {
m.registry = prometheus.NewRegistry()
m.dynamicPromHandler.updateHandler(promhttp.HandlerFor(m.registry, promhttp.HandlerOpts{}))
// Init each service's metrics
for _, service := range m.serviceMetrics {
service.InitMetrics(m.network)
}
m.initMetrics()
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -439,9 +442,9 @@ func (m *Metrics) reconnectHandler() {
log.Info("Network Changed, resetting all metrics")
m.registry = prometheus.NewRegistry()
m.dynamicPromHandler.updateHandler(promhttp.HandlerFor(m.registry, promhttp.HandlerOpts{}))
// Init each service's metrics
m.initMetrics()
// Init each service's data
for _, service := range m.serviceMetrics {
service.InitMetrics(m.network)
service.InitialData()
}
} else {
Expand Down

0 comments on commit 8ca8513

Please sign in to comment.