Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/charts/bitcoincore/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ metadata:
spec:
endpoints:
- port: prometheus-metrics
interval: {{ .Values.metricsScrapeInterval | default "15s" }}
selector:
matchLabels:
app: {{ include "bitcoincore.fullname" . }}
Expand Down
14 changes: 13 additions & 1 deletion resources/images/exporter/bitcoin-exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def make_metric_function(cmd):
return None


def make_counting_function(cmd, key, value):
try:
return lambda: sum(1 for x in eval(f"rpc.{cmd}") if x.get(key) == value)
except Exception:
return None


# Parse RPC queries into metrics
commands = METRICS.split(" ")
for labeled_cmd in commands:
Expand All @@ -53,7 +60,12 @@ def make_metric_function(cmd):
label, cmd = labeled_cmd.strip().split("=")
# label, description i.e. ("bitcoin_conn_in", "Number of connections in")
metric = Gauge(label, cmd)
metric.set_function(make_metric_function(cmd))
if "COUNT:" in cmd:
_, args = cmd.split(":")
cmd, key, value = args.split(",")
metric.set_function(make_counting_function(cmd, key, value))
else:
metric.set_function(make_metric_function(cmd))
print(f"Metric created: {labeled_cmd}")

# Start the server
Expand Down
4 changes: 2 additions & 2 deletions test/data/logging/network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ nodes:
addnode:
- tank-0002
metricsExport: true
metrics: txrate=getchaintxstats(10)["txrate"]
metrics: txrate=getchaintxstats(10)["txrate"] ipv4peers=COUNT:getpeerinfo(),network,ipv4
- name: tank-0002
addnode:
addnode:
- tank-0000
ln:
lnd: true
Expand Down
Loading