Skip to content

Commit

Permalink
Merge pull request #40 from RadarTech/add-chain-sync-metric
Browse files Browse the repository at this point in the history
Add Synced To Chain
  • Loading branch information
Roasbeef authored Dec 7, 2019
2 parents 0b433cb + 28bdffe commit 087d7c4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions collectors/chain_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type ChainCollector struct {
bestBlockHeight *prometheus.Desc
bestBlockTimestamp *prometheus.Desc
syncedToChain *prometheus.Desc

lnd lnrpc.LightningClient
}
Expand All @@ -28,6 +29,11 @@ func NewChainCollector(lnd lnrpc.LightningClient) *ChainCollector {
"best block timestamp from lnd",
nil, nil,
),
syncedToChain: prometheus.NewDesc(
"lnd_chain_synced",
"lnd is synced to the chain",
nil, nil,
),
lnd: lnd,
}
}
Expand All @@ -40,6 +46,7 @@ func NewChainCollector(lnd lnrpc.LightningClient) *ChainCollector {
func (c *ChainCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.bestBlockHeight
ch <- c.bestBlockTimestamp
ch <- c.syncedToChain
}

// Collect is called by the Prometheus registry when collecting metrics.
Expand All @@ -61,6 +68,11 @@ func (c *ChainCollector) Collect(ch chan<- prometheus.Metric) {
c.bestBlockTimestamp, prometheus.GaugeValue,
float64(resp.BestHeaderTimestamp),
)

ch <- prometheus.MustNewConstMetric(
c.syncedToChain, prometheus.GaugeValue,
float64(boolToInt(resp.SyncedToChain)),
)
}

func init() {
Expand All @@ -70,3 +82,10 @@ func init() {
}
metricsMtx.Unlock()
}

func boolToInt(arg bool) uint8 {
if arg {
return 1
}
return 0
}

0 comments on commit 087d7c4

Please sign in to comment.