feat: wire Metrics into service + add metrics.snapshot action
Some checks failed
Security Scan / security (push) Successful in 14s
Test / Test (push) Failing after 34s

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:
Claude 2026-04-02 04:54:26 +01:00
parent e296ab0651
commit 054af81725
No known key found for this signature in database
GPG key ID: AF404715446AEB41
2 changed files with 12 additions and 1 deletions

View file

@ -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}
})
}

View file

@ -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})
}
})