Skip to content

Commit 8a2e34c

Browse files
authored
Merge pull request #691 from macgyver13/lnd-exporter
Enable lnd pod logging
2 parents 8e621be + 33b4e16 commit 8a2e34c

File tree

10 files changed

+101
-27
lines changed

10 files changed

+101
-27
lines changed

docs/logging_monitoring.md

+10
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ outbounds 0.0
116116
mempool_size 0.0
117117
```
118118
119+
### Defining lnd metrics to capture
120+
121+
Lightning nodes can also be configured to export metrics to prometheus using `lnd-exporter`.
122+
Example configuration is provided in `test/data/ln/`. Review `node-defauts.yaml` for a typical logging configuration. All default metrics reported to prometheus are prefixed with `lnd_`
123+
124+
[lnd-exporter configuration reference](https://github.com/macgyver13/lnd-exporter/tree/main?tab=readme-ov-file#configuration)
125+
lnd-exporter assumes same macaroon referenced in ln_framework (can be overridden by env variable)
126+
127+
**Note: `test/data/ln` and `test/data/logging` take advantage of **extraContainers** configuration option to add containers to default `lnd/templates/pod`*
128+
119129
### Grafana
120130
121131
Data from Prometheus exporters is collected and fed into Grafana for a

resources/charts/bitcoincore/charts/lnd/templates/configmap.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: {{ include "lnd.fullname" . }}
55
labels:
66
{{- include "lnd.labels" . | nindent 4 }}
7+
role: macaroon-ref
78
data:
89
lnd.conf: |
910
{{- .Values.baseConfig | nindent 4 }}
@@ -37,7 +38,7 @@ data:
3738
AwEHoUQDQgAEBVltIvaTlAQI/3FFatTqVflZuZdRJ0SmRMSJrFLPtp0fxE7hmteS
3839
t6gjQriy90fP8j9OJXBNAjt915kLY4zVvg==
3940
-----END EC PRIVATE KEY-----
40-
41+
MACAROON_HEX: 0201036c6e6402f801030a1062beabbf2a614b112128afa0c0b4fdd61201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620b17be53e367290871681055d0de15587f6d1cd47d1248fe2662ae27f62cfbdc6
4142
---
4243
apiVersion: v1
4344
kind: ConfigMap

resources/charts/bitcoincore/charts/lnd/templates/pod.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ metadata:
1212
collect_logs: "true"
1313
{{- end }}
1414
chain: {{ .Values.global.chain }}
15+
annotations:
16+
kubectl.kubernetes.io/default-container: "lnd"
1517
spec:
1618
{{- with .Values.imagePullSecrets }}
1719
imagePullSecrets:
@@ -56,11 +58,9 @@ spec:
5658
- mountPath: /root/.lnd/tls.cert
5759
name: config
5860
subPath: tls.cert
59-
{{- if .Values.circuitBreaker }}
60-
- name: circuitbreaker
61-
image: pinheadmz/circuitbreaker:278737d
62-
imagePullPolicy: IfNotPresent
63-
{{- end}}
61+
{{- with .Values.extraContainers }}
62+
{{- toYaml . | nindent 4 }}
63+
{{- end }}
6464
volumes:
6565
{{- with .Values.volumes }}
6666
{{- toYaml . | nindent 4 }}

resources/charts/bitcoincore/charts/lnd/templates/service.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@ spec:
2020
targetPort: rest
2121
protocol: TCP
2222
name: rest
23+
{{- if .Values.metricsExport }}
24+
- port: {{ .Values.prometheusMetricsPort }}
25+
targetPort: prom-metrics
26+
protocol: TCP
27+
name: prometheus-metrics
28+
{{- end }}
2329
selector:
2430
{{- include "lnd.selectorLabels" . | nindent 4 }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- if .Values.metricsExport }}
2+
apiVersion: monitoring.coreos.com/v1
3+
kind: ServiceMonitor
4+
metadata:
5+
name: {{ include "lnd.fullname" . }}
6+
labels:
7+
app.kubernetes.io/name: lnd-metrics
8+
release: prometheus
9+
spec:
10+
endpoints:
11+
- port: prometheus-metrics
12+
selector:
13+
matchLabels:
14+
app: {{ include "lnd.fullname" . }}
15+
{{- end }}

resources/plugins/simln/charts/simln/templates/configmap.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ data:
1717
IQDPofN0fEl5gTwCYhk3nZbjMqJhZ8BsSJ6K8XRhxr7zbwIhAPsgQCFOqUWg632O
1818
NEO53OQ6CIqnpxSskjsFNH4ZBQOE
1919
-----END CERTIFICATE-----
20-
admin.macaroon.hex: |
21-
0201036c6e6402f801030a1062beabbf2a614b112128afa0c0b4fdd61201301a160a0761646472657373120472656164120577726974651a130a04696e666f120472656164120577726974651a170a08696e766f69636573120472656164120577726974651a210a086d616361726f6f6e120867656e6572617465120472656164120577726974651a160a076d657373616765120472656164120577726974651a170a086f6666636861696e120472656164120577726974651a160a076f6e636861696e120472656164120577726974651a140a057065657273120472656164120577726974651a180a067369676e6572120867656e657261746512047265616400000620b17be53e367290871681055d0de15587f6d1cd47d1248fe2662ae27f62cfbdc6
20+
{{- $configMaps := lookup "v1" "ConfigMap" .Release.Namespace "" }}
21+
{{- range $configMaps.items }}
22+
{{- if and .metadata.labels (hasKey .metadata.labels "role") (eq (index .metadata.labels "role") "macaroon-ref") }}
23+
admin.macaroon.hex: {{ index .data "MACAROON_HEX" | quote }}
24+
{{- end }}
25+
{{- end }}

test/data/ln/network.yaml

+1-18
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,15 @@ nodes:
22
- name: tank-0000
33
addnode:
44
- tank-0001
5-
ln:
6-
lnd: true
7-
85
- name: tank-0001
96
addnode:
107
- tank-0002
11-
ln:
12-
lnd: true
13-
148
- name: tank-0002
159
addnode:
1610
- tank-0000
17-
ln:
18-
lnd: true
19-
2011
- name: tank-0003
2112
addnode:
2213
- tank-0000
23-
ln:
24-
lnd: true
2514
lnd:
2615
config: |
2716
bitcoin.timelockdelta=33
@@ -32,12 +21,9 @@ nodes:
3221
target: tank-0004-ln
3322
capacity: 100000
3423
push_amt: 50000
35-
3624
- name: tank-0004
3725
addnode:
3826
- tank-0000
39-
ln:
40-
lnd: true
4127
lnd:
4228
channels:
4329
- id:
@@ -46,9 +32,6 @@ nodes:
4632
target: tank-0005-ln
4733
capacity: 50000
4834
push_amt: 25000
49-
5035
- name: tank-0005
5136
addnode:
52-
- tank-0000
53-
ln:
54-
lnd: true
37+
- tank-0000

test/data/ln/node-defaults.yaml

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
1+
# enable collectLogs and metricsExport to activate publish lnd-exporter metrics
2+
3+
#Core configs
14
image:
25
repository: bitcoindevproject/bitcoin
36
pullPolicy: IfNotPresent
47
tag: "27.0"
8+
collectLogs: false
9+
metricsExport: false
510

11+
#LN configs
12+
ln:
13+
lnd: true
614
lnd:
715
defaultConfig: |
8-
color=#000000
16+
color=#000000
17+
config: |
18+
bitcoin.timelockdelta=33
19+
metricsExport: false
20+
prometheusMetricsPort: 9332
21+
extraContainers:
22+
- name: lnd-exporter
23+
image: bitdonkey/lnd-exporter:0.1.3
24+
imagePullPolicy: IfNotPresent
25+
volumeMounts:
26+
- name: config
27+
mountPath: /macaroon.hex
28+
subPath: MACAROON_HEX
29+
env:
30+
- name: METRICS
31+
value: >
32+
lnd_balance_channels=parse("/v1/balance/channels","balance")
33+
lnd_local_balance_channels=parse("/v1/balance/channels","local_balance.sat")
34+
lnd_remote_balance_channels=parse("/v1/balance/channels","remote_balance.sat")
35+
lnd_block_height=parse("/v1/getinfo","block_height")
36+
lnd_peers=parse("/v1/getinfo","num_peers")
37+
ports:
38+
- name: prom-metrics
39+
containerPort: 9332
40+
protocol: TCP

test/data/logging/network.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,27 @@ nodes:
1111
- name: tank-0002
1212
addnode:
1313
- tank-0000
14+
ln:
15+
lnd: true
16+
lnd:
17+
metricsExport: true
18+
prometheusMetricsPort: 9332
19+
extraContainers:
20+
- name: lnd-exporter
21+
image: bitdonkey/lnd-exporter:0.1.3
22+
imagePullPolicy: IfNotPresent
23+
volumeMounts:
24+
- name: config
25+
mountPath: /macaroon.hex
26+
subPath: MACAROON_HEX
27+
env:
28+
- name: METRICS
29+
value: >
30+
lnd_block_height=parse("/v1/getinfo","block_height")
31+
lnd_peers=parse("/v1/getinfo","num_peers")
32+
ports:
33+
- name: prom-metrics
34+
containerPort: 9332
35+
protocol: TCP
1436
caddy:
1537
enabled: true

test/logging_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def get_five_values_for_metric(metric):
9494

9595
self.wait_for_predicate(lambda: get_five_values_for_metric("blocks"))
9696
self.wait_for_predicate(lambda: get_five_values_for_metric("txrate"))
97+
self.wait_for_predicate(lambda: get_five_values_for_metric("lnd_block_height"))
9798

9899
# Verify default dashboard exists
99100
dbs = requests.get(f"{self.grafana_url}/api/search").json()

0 commit comments

Comments
 (0)