Skip to content

Commit

Permalink
Emit DKG/Reshare status when node starts up/shuts down (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcamou committed Apr 5, 2022
1 parent 2ae6479 commit 19ba747
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions core/drand_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func (dd *DrandDaemon) InstantiateBeaconProcess(beaconID string, store key.Store
dd.beaconProcesses[beaconID] = bp
dd.state.Unlock()

metrics.DKGStateChange(metrics.DKGNotStarted, beaconID, false)
metrics.ReshareStateChange(metrics.ReshareIdle, beaconID, false)
metrics.IsDrandNode.Set(1)

return bp, nil
}

Expand Down Expand Up @@ -204,6 +208,10 @@ func (dd *DrandDaemon) RemoveBeaconProcess(beaconID string, bp *BeaconProcess) {
delete(dd.chainHashes, common.DefaultChainHash)
}

metrics.DKGStateChange(metrics.DKGShutdown, beaconID, false)
metrics.ReshareStateChange(metrics.ReshareShutdown, beaconID, false)
metrics.IsDrandNode.Set(1)

dd.state.Unlock()
}

Expand Down
12 changes: 10 additions & 2 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ const (
DKGWaiting DKGStatus = "waiting"
DKGReady DKGStatus = "ready"
DKGUnknownStatus DKGStatus = "unknown"
DKGShutdown DKGStatus = "node_stopped"
)

const (
ReshareIdle ReshareStatus = "idle"
ReshareWaiting ReshareStatus = "waiting"
ReshareInProgess ReshareStatus = "in_progress"
ReshareStatusUnknown ReshareStatus = "unknown"
ReshareShutdown ReshareStatus = "node_stopped"
)

var (
Expand Down Expand Up @@ -177,14 +179,14 @@ var (
Name: "dkg_state_change_timestamp",
Help: "DKG state change timestamp in seconds since the Epoch",
ConstLabels: map[string]string{},
}, []string{"state", "beacon_id", "is_leader"})
}, []string{"dkg_state", "beacon_id", "is_leader"})

// reshareStateChangeTimestamp tracks reshare status changes
reshareStateChangeTimestamp = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "reshare_state_change_timestamp",
Help: "Reshare state change timestamp in seconds since the Epoch",
ConstLabels: map[string]string{},
}, []string{"state", "beacon_id", "is_leader"})
}, []string{"reshare_state", "beacon_id", "is_leader"})

// drandBuildTime emits the timestamp when the binary was built in Unix time.
drandBuildTime = prometheus.NewUntypedFunc(prometheus.UntypedOpts{
Expand All @@ -193,6 +195,12 @@ var (
ConstLabels: map[string]string{"build": common.COMMIT, "version": common.GetAppVersion().String()},
}, func() float64 { return float64(getBuildTimestamp(common.BUILDDATE)) })

// IsDrandNode is 1 for drand nodes, 0 for relays
IsDrandNode = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "is_drand_node",
Help: "1 for drand nodes, not emitted for relays",
})

metricsBound = false
)

Expand Down

0 comments on commit 19ba747

Please sign in to comment.