feat: wire Metrics into service + add metrics.snapshot action
Every synced block increments blocks_processed counter. Alias registrations increment aliases_found counter. Sync errors tracked separately. blockchain.metrics.snapshot returns all counters atomically. 43 total Core actions. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
e296ab0651
commit
054af81725
2 changed files with 12 additions and 1 deletions
|
|
@ -667,3 +667,10 @@ func makeEstHeightAtTime(ch *chain.Chain) core.ActionHandler {
|
|||
return core.Result{Value: est, OK: true}
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterMetricsActions registers operational metrics actions.
|
||||
func RegisterMetricsActions(c *core.Core, m *Metrics) {
|
||||
c.Action("blockchain.metrics.snapshot", func(ctx context.Context, opts core.Options) core.Result {
|
||||
return core.Result{Value: m.Snapshot(), OK: true}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ type BlockchainService struct {
|
|||
store *store.Store
|
||||
daemon *daemon.Server
|
||||
events *EventBus
|
||||
metrics *Metrics
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
|
|
@ -78,11 +79,14 @@ func (s *BlockchainService) start() core.Result {
|
|||
s.store = st
|
||||
s.chain = chain.New(st)
|
||||
s.events = NewEventBus()
|
||||
s.metrics = NewMetrics(s.chain)
|
||||
|
||||
// Wire block events
|
||||
// Wire block events + metrics
|
||||
s.chain.SetBlockCallback(func(height uint64, hash string, aliasName string) {
|
||||
s.metrics.RecordBlock()
|
||||
s.events.Emit(Event{Type: EventBlockNew, Height: height, Data: hash})
|
||||
if aliasName != "" {
|
||||
s.metrics.RecordAlias()
|
||||
s.events.Emit(Event{Type: EventAlias, Height: height, Data: aliasName})
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue