@@ -38,7 +38,9 @@ type ChannelsCollector struct {
38
38
// NewChannelsCollector returns a new instance of the ChannelsCollector for the
39
39
// target lnd client.
40
40
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" }
42
44
return & ChannelsCollector {
43
45
channelBalanceDesc : prometheus .NewDesc (
44
46
"lnd_channels_open_balance_sat" ,
@@ -217,61 +219,84 @@ func (c *ChannelsCollector) Collect(ch chan<- prometheus.Metric) {
217
219
return
218
220
}
219
221
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
+
220
242
for _ , channel := range listChannelsResp .Channels {
243
+ status := statusLabel (channel )
244
+ initiator := initiatorLabel (channel )
245
+
221
246
ch <- prometheus .MustNewConstMetric (
222
247
c .incomingChanSatDesc , prometheus .GaugeValue ,
223
248
float64 (channel .RemoteBalance ),
224
- strconv .Itoa (int (channel .ChanId )),
249
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
225
250
)
226
251
ch <- prometheus .MustNewConstMetric (
227
252
c .outgoingChanSatDesc , prometheus .GaugeValue ,
228
253
float64 (channel .LocalBalance ),
229
- strconv .Itoa (int (channel .ChanId )),
254
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
230
255
)
231
256
ch <- prometheus .MustNewConstMetric (
232
257
c .numPendingHTLCsDesc , prometheus .GaugeValue ,
233
258
float64 (len (channel .PendingHtlcs )),
234
- strconv .Itoa (int (channel .ChanId )),
259
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
235
260
)
236
261
ch <- prometheus .MustNewConstMetric (
237
262
c .satsSentDesc , prometheus .GaugeValue ,
238
263
float64 (channel .TotalSatoshisSent ),
239
- strconv .Itoa (int (channel .ChanId )),
264
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
240
265
)
241
266
ch <- prometheus .MustNewConstMetric (
242
267
c .satsRecvDesc , prometheus .GaugeValue ,
243
268
float64 (channel .TotalSatoshisReceived ),
244
- strconv .Itoa (int (channel .ChanId )),
269
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
245
270
)
246
271
ch <- prometheus .MustNewConstMetric (
247
272
c .numUpdatesDesc , prometheus .GaugeValue ,
248
273
float64 (channel .NumUpdates ),
249
- strconv .Itoa (int (channel .ChanId )),
274
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
250
275
)
251
276
ch <- prometheus .MustNewConstMetric (
252
277
c .csvDelayDesc , prometheus .GaugeValue ,
253
278
float64 (channel .CsvDelay ),
254
- strconv .Itoa (int (channel .ChanId )),
279
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
255
280
)
256
281
ch <- prometheus .MustNewConstMetric (
257
282
c .unsettledBalanceDesc , prometheus .GaugeValue ,
258
283
float64 (channel .UnsettledBalance ),
259
- strconv .Itoa (int (channel .ChanId )),
284
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
260
285
)
261
286
ch <- prometheus .MustNewConstMetric (
262
287
c .feePerKwDesc , prometheus .GaugeValue ,
263
288
float64 (channel .FeePerKw ),
264
- strconv .Itoa (int (channel .ChanId )),
289
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
265
290
)
266
291
ch <- prometheus .MustNewConstMetric (
267
292
c .commitWeightDesc , prometheus .GaugeValue ,
268
293
float64 (channel .CommitWeight ),
269
- strconv .Itoa (int (channel .ChanId )),
294
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
270
295
)
271
296
ch <- prometheus .MustNewConstMetric (
272
297
c .commitFeeDesc , prometheus .GaugeValue ,
273
298
float64 (channel .CommitFee ),
274
- strconv .Itoa (int (channel .ChanId )),
299
+ strconv .Itoa (int (channel .ChanId )), status , initiator ,
275
300
)
276
301
}
277
302
}
0 commit comments