Skip to content

Commit 5a65628

Browse files
authored
Merge pull request #24 from Roasbeef/revamp-graph
collectors: flatten graph metrics, update peer dashboard
2 parents 4e90b86 + 0e0eb8a commit 5a65628

File tree

6 files changed

+1076
-101
lines changed

6 files changed

+1076
-101
lines changed

collectors/channels_collector.go

+37-12
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ type ChannelsCollector struct {
3838
// NewChannelsCollector returns a new instance of the ChannelsCollector for the
3939
// target lnd client.
4040
func NewChannelsCollector(lnd lnrpc.LightningClient) *ChannelsCollector {
41-
labels := []string{"chan_id"}
41+
// Our set of labels, status should either be active or inactive. The
42+
// initiator is "true" if we are the initiator, and "false" otherwise.
43+
labels := []string{"chan_id", "status", "initiator"}
4244
return &ChannelsCollector{
4345
channelBalanceDesc: prometheus.NewDesc(
4446
"lnd_channels_open_balance_sat",
@@ -217,61 +219,84 @@ func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {
217219
return
218220
}
219221

222+
// statusLabel is a small helper function returns the proper status
223+
// label for a given channel.
224+
statusLabel := func(c *lnrpc.Channel) string {
225+
if c.Active {
226+
return "active"
227+
}
228+
229+
return "inactive"
230+
}
231+
232+
// initiatorLabel is a small helper function that returns the proper
233+
// "initiator" label for a given channel.
234+
initiatorLabel := func(c *lnrpc.Channel) string {
235+
if c.Initiator {
236+
return "true"
237+
}
238+
239+
return "false"
240+
}
241+
220242
for _, channel := range listChannelsResp.Channels {
243+
status := statusLabel(channel)
244+
initiator := initiatorLabel(channel)
245+
221246
ch <- prometheus.MustNewConstMetric(
222247
c.incomingChanSatDesc, prometheus.GaugeValue,
223248
float64(channel.RemoteBalance),
224-
strconv.Itoa(int(channel.ChanId)),
249+
strconv.Itoa(int(channel.ChanId)), status, initiator,
225250
)
226251
ch <- prometheus.MustNewConstMetric(
227252
c.outgoingChanSatDesc, prometheus.GaugeValue,
228253
float64(channel.LocalBalance),
229-
strconv.Itoa(int(channel.ChanId)),
254+
strconv.Itoa(int(channel.ChanId)), status, initiator,
230255
)
231256
ch <- prometheus.MustNewConstMetric(
232257
c.numPendingHTLCsDesc, prometheus.GaugeValue,
233258
float64(len(channel.PendingHtlcs)),
234-
strconv.Itoa(int(channel.ChanId)),
259+
strconv.Itoa(int(channel.ChanId)), status, initiator,
235260
)
236261
ch <- prometheus.MustNewConstMetric(
237262
c.satsSentDesc, prometheus.GaugeValue,
238263
float64(channel.TotalSatoshisSent),
239-
strconv.Itoa(int(channel.ChanId)),
264+
strconv.Itoa(int(channel.ChanId)), status, initiator,
240265
)
241266
ch <- prometheus.MustNewConstMetric(
242267
c.satsRecvDesc, prometheus.GaugeValue,
243268
float64(channel.TotalSatoshisReceived),
244-
strconv.Itoa(int(channel.ChanId)),
269+
strconv.Itoa(int(channel.ChanId)), status, initiator,
245270
)
246271
ch <- prometheus.MustNewConstMetric(
247272
c.numUpdatesDesc, prometheus.GaugeValue,
248273
float64(channel.NumUpdates),
249-
strconv.Itoa(int(channel.ChanId)),
274+
strconv.Itoa(int(channel.ChanId)), status, initiator,
250275
)
251276
ch <- prometheus.MustNewConstMetric(
252277
c.csvDelayDesc, prometheus.GaugeValue,
253278
float64(channel.CsvDelay),
254-
strconv.Itoa(int(channel.ChanId)),
279+
strconv.Itoa(int(channel.ChanId)), status, initiator,
255280
)
256281
ch <- prometheus.MustNewConstMetric(
257282
c.unsettledBalanceDesc, prometheus.GaugeValue,
258283
float64(channel.UnsettledBalance),
259-
strconv.Itoa(int(channel.ChanId)),
284+
strconv.Itoa(int(channel.ChanId)), status, initiator,
260285
)
261286
ch <- prometheus.MustNewConstMetric(
262287
c.feePerKwDesc, prometheus.GaugeValue,
263288
float64(channel.FeePerKw),
264-
strconv.Itoa(int(channel.ChanId)),
289+
strconv.Itoa(int(channel.ChanId)), status, initiator,
265290
)
266291
ch <- prometheus.MustNewConstMetric(
267292
c.commitWeightDesc, prometheus.GaugeValue,
268293
float64(channel.CommitWeight),
269-
strconv.Itoa(int(channel.ChanId)),
294+
strconv.Itoa(int(channel.ChanId)), status, initiator,
270295
)
271296
ch <- prometheus.MustNewConstMetric(
272297
c.commitFeeDesc, prometheus.GaugeValue,
273298
float64(channel.CommitFee),
274-
strconv.Itoa(int(channel.ChanId)),
299+
strconv.Itoa(int(channel.ChanId)), status, initiator,
275300
)
276301
}
277302
}

0 commit comments

Comments
 (0)