Skip to content

Commit bf9eff1

Browse files
authored
Merge pull request bitcoin-dev-project#423 from pinheadmz/rpc-gauge
Flexible RPC exporter for Prometheus
2 parents 75f0b91 + ec801df commit bf9eff1

28 files changed

+796
-120
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v4
19-
# - uses: chartboost/ruff-action@v1
20-
# Until this gets updated we need to use this commit hash (or later)
21-
- uses: chartboost/ruff-action@491342200cdd1cf4d5132a30ddc546b3b5bc531b
19+
- uses: chartboost/ruff-action@v1
2220
with:
2321
args: 'format --check'
24-
changed-files: 'true'
2522
build-image:
2623
needs: [ruff, ruff-format]
2724
runs-on: ubuntu-latest
@@ -52,10 +49,11 @@ jobs:
5249
runs-on: ubuntu-latest
5350
strategy:
5451
matrix:
55-
test: [scenarios_test.py, rpc_test.py, graph_test.py, ln_test.py, dag_connection_test.py]
52+
test: [scenarios_test.py, rpc_test.py, graph_test.py, ln_test.py, dag_connection_test.py, logging_test.py]
5653
steps:
5754
- uses: actions/checkout@v4
5855
- uses: hynek/setup-cached-uv@v1
56+
- uses: azure/[email protected]
5957
- uses: medyagh/setup-minikube@master
6058
with:
6159
mount-path: ${{ github.workspace }}:/mnt/src

docs/graph.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ lightning network channel (see [lightning.md](lightning.md)).
5050
<key id="bitcoin_config" attr.name="bitcoin_config" attr.type="string" for="node" />
5151
<key id="tc_netem" attr.name="tc_netem" attr.type="string" for="node" />
5252
<key id="exporter" attr.name="exporter" attr.type="boolean" for="node" />
53+
<key id="metrics" attr.name="metrics" attr.type="string" for="node" />
5354
<key id="collect_logs" attr.name="collect_logs" attr.type="boolean" for="node" />
5455
<key id="build_args" attr.name="build_args" attr.type="string" for="node" />
5556
<key id="ln" attr.name="ln" attr.type="string" for="node" />
@@ -66,20 +67,21 @@ lightning network channel (see [lightning.md](lightning.md)).
6667
</graphml>
6768
```
6869

69-
| key | for | type | default | explanation |
70-
|----------------|-------|---------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
71-
| services | graph | string | | A space-separated list of extra service containers to deploy in the network. See [docs/services.md](services.md) for complete list of available services |
72-
| version | node | string | | Bitcoin Core version with an available Warnet tank image on Dockerhub. May also be a GitHub repository with format user/repository:branch to build from source code |
73-
| image | node | string | | Bitcoin Core Warnet tank image on Dockerhub with the format repository/image:tag |
74-
| bitcoin_config | node | string | | A string of Bitcoin Core options in command-line format, e.g. '-debug=net -blocksonly' |
75-
| tc_netem | node | string | | A tc-netem command as a string beginning with 'tc qdisc add dev eth0 root netem' |
76-
| exporter | node | boolean | False | Whether to attach a Prometheus data exporter to the tank |
77-
| collect_logs | node | boolean | False | Whether to collect Bitcoin Core debug logs with Promtail |
78-
| build_args | node | string | | A string of configure options used when building Bitcoin Core from source code, e.g. '--without-gui --disable-tests' |
79-
| ln | node | string | | Attach a lightning network node of this implementation (currently only supports 'lnd') |
80-
| ln_image | node | string | | Specify a lightning network node image from Dockerhub with the format repository/image:tag |
81-
| ln_cb_image | node | string | | Specify a lnd Circuit Breaker image from Dockerhub with the format repository/image:tag |
82-
| ln_config | node | string | | A string of arguments for the lightning network node in command-line format, e.g. '--protocol.wumbo-channels --bitcoin.timelockdelta=80' |
83-
| channel_open | edge | string | | Indicate that this edge is a lightning channel with these arguments passed to lnd openchannel |
84-
| source_policy | edge | string | | Update the channel originator policy by passing these arguments passed to lnd updatechanpolicy |
85-
| target_policy | edge | string | | Update the channel partner policy by passing these arguments passed to lnd updatechanpolicy |
70+
| key | for | type | default | explanation |
71+
|----------------|-------|---------|-----------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
72+
| services | graph | string | | A space-separated list of extra service containers to deploy in the network. See [docs/services.md](services.md) for complete list of available services |
73+
| version | node | string | | Bitcoin Core version with an available Warnet tank image on Dockerhub. May also be a GitHub repository with format user/repository:branch to build from source code |
74+
| image | node | string | | Bitcoin Core Warnet tank image on Dockerhub with the format repository/image:tag |
75+
| bitcoin_config | node | string | | A string of Bitcoin Core options in command-line format, e.g. '-debug=net -blocksonly' |
76+
| tc_netem | node | string | | A tc-netem command as a string beginning with 'tc qdisc add dev eth0 root netem' |
77+
| exporter | node | boolean | False | Whether to attach a Prometheus data exporter to the tank |
78+
| metrics | node | string | Block count, peers in/out, mempool size | A space-separated string of RPC queries to scrape by prometheus |
79+
| collect_logs | node | boolean | False | Whether to collect Bitcoin Core debug logs with Promtail |
80+
| build_args | node | string | | A string of configure options used when building Bitcoin Core from source code, e.g. '--without-gui --disable-tests' |
81+
| ln | node | string | | Attach a lightning network node of this implementation (currently only supports 'lnd' or 'cln') |
82+
| ln_image | node | string | | Specify a lightning network node image from Dockerhub with the format repository/image:tag |
83+
| ln_cb_image | node | string | | Specify a lnd Circuit Breaker image from Dockerhub with the format repository/image:tag |
84+
| ln_config | node | string | | A string of arguments for the lightning network node in command-line format, e.g. '--protocol.wumbo-channels --bitcoin.timelockdelta=80' |
85+
| channel_open | edge | string | | Indicate that this edge is a lightning channel with these arguments passed to lnd openchannel |
86+
| source_policy | edge | string | | Update the channel originator policy by passing these arguments passed to lnd updatechanpolicy |
87+
| target_policy | edge | string | | Update the channel partner policy by passing these arguments passed to lnd updatechanpolicy |

docs/monitoring.md

Lines changed: 88 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,102 @@
11
# Monitoring
22

3-
## Monitoring container resource usage
3+
## Prometheus
44

5-
When run in docker, a few additional containers are started up:
5+
To monitor RPC return values over time, a Prometheus data exporter can be connected
6+
to any Bitcoin Tank and configured to scrape any available RPC results.
67

7-
* CAdvisor (container Monitoring)
8-
* Prometheus (log scraper)
9-
* Grafana (graphing/dashboard tool)
8+
The `bitcoin-exporter` image is defined in `resources/images/exporter` and
9+
maintained in the BitcoinDevProject dockerhub organization. To add the exporter
10+
in the Tank pod with Bitcoin Core add the `"exporter"` key to the node in the graphml file:
1011

11-
## CAdvisor
12+
```xml
13+
<node id="0">
14+
<data key="version">27.0</data>
15+
<data key="exporter">true</data>
16+
</node>
17+
```
1218

13-
CAdvisor needs no additional setup, and can be accessed from the docker host at
14-
localhost:8080
19+
The default metrics are defined in the `bitcoin-exporter` image:
20+
- Block count
21+
- Number of inbound peers
22+
- Number of outbound peers
23+
- Mempool size (# of TXs)
1524

16-
## Prometheus
25+
Metrics can be configured by setting a `"metrics"` key to the node in the graphml file.
26+
The metrics value is a space-separated list of labels, RPC commands with arguments, and
27+
JSON keys to resolve the desired data:
28+
29+
```
30+
label=method(arguments)[JSON result key][...]
31+
```
32+
33+
For example, the default metrics listed above are defined as:
34+
35+
```xml
36+
<node id="0">
37+
<data key="version">27.0</data>
38+
<data key="exporter">true</data>
39+
<data key="metrics">blocks=getblockcount() inbounds=getnetworkinfo()["connections_in"] outbounds=getnetworkinfo()["connections_in"] mempool_size=getmempoolinfo()["size"]</data>
40+
</node>
41+
```
1742

18-
Prometheus should also not need any additional setup, and can be accessed from
19-
the docker host at localhost:9090
43+
The data can be retrieved from the Prometheus exporter on port `9332`, example:
44+
45+
```
46+
# HELP blocks getblockcount()
47+
# TYPE blocks gauge
48+
blocks 704.0
49+
# HELP inbounds getnetworkinfo()["connections_in"]
50+
# TYPE inbounds gauge
51+
inbounds 0.0
52+
# HELP outbounds getnetworkinfo()["connections_in"]
53+
# TYPE outbounds gauge
54+
outbounds 0.0
55+
# HELP mempool_size getmempoolinfo()["size"]
56+
# TYPE mempool_size gauge
57+
mempool_size 0.0
58+
```
2059

2160
## Grafana
2261

23-
Grafana is provisioned with a single default dashboard, but alternative
24-
dashboards can be added or created.
62+
Data from Prometheus exporters can be collected and fed into Grafana for a
63+
web-based interface.
64+
65+
### Install logging infrastructure
66+
67+
First make sure you have `helm` installed, then run the `install_logging` script:
68+
69+
```bash
70+
resources/scripts/install_logging.sh
71+
```
72+
73+
To forward port `3000` and view the Grafana dashboard run the `connect_logging` script:
74+
75+
```bash
76+
resources/scripts/connect_logging.sh
77+
```
78+
79+
The Grafana dashboard (and API) will be accessible without requiring authentication
80+
at http://localhost:3000
81+
82+
## Dashboards
83+
84+
To view the default metrics in the included default dashboard, upload the dashboard
85+
JSON file to the Grafana server:
86+
87+
```
88+
curl localhost:3000/api/dashboards/db \
89+
-H "Content-Type: application/json" \
90+
--data "{\"dashboard\": $(cat resources/configs/grafana/default_dashboard.json)}"
91+
```
92+
93+
Note the URL in the reply from the server (example):
94+
95+
```
96+
{"folderUid":"","id":2,"slug":"default-warnet-dashboard","status":"success","uid":"fdu0pda1z6a68b","url":"/d/fdu0pda1z6a68b/default-warnet-dashboard","version":1}(
97+
```
2598

26-
Grafana can be accessed on the docker host from localhost:3000 using username
27-
`admin` and password `admin` by default.
99+
Open the dashboard in your browser (example):
28100

29-
The default dashboard is called "Docker Container & Host Metrics" and can be
30-
accessed via the "dashboards" tab, or from the bottom right of the home screen.
101+
`http://localhost:3000/d/fdu0pda1z6a68b/default-warnet-dashboard`
31102

32-
Additional dashboards and datasources may be added in the future.

docs/warcli.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ options:
2626
|----------|--------|------------|-----------|
2727
| commands | String | | |
2828

29-
### `warcli setup`
30-
Run the Warnet quick start setup script
31-
32-
3329
## Bitcoin
3430

3531
### `warcli bitcoin debug-log`
@@ -73,6 +69,18 @@ options:
7369

7470
## Cluster
7571

72+
### `warcli cluster deploy`
73+
Setup Warnet using the current kubectl-configured cluster
74+
75+
76+
### `warcli cluster minikube-clean`
77+
Reinit minikube images
78+
79+
80+
### `warcli cluster minikube-setup`
81+
Setup minikube for use with Warnet
82+
83+
7684
### `warcli cluster port-start`
7785
Port forward (runs as a detached process)
7886

@@ -81,11 +89,7 @@ Port forward (runs as a detached process)
8189
Stop the port forwarding process
8290

8391

84-
### `warcli cluster start`
85-
Setup and start Warnet with minikube
86-
87-
88-
### `warcli cluster stop`
92+
### `warcli cluster teardown`
8993
Stop the warnet server and tear down the cluster
9094

9195

@@ -129,19 +133,19 @@ options:
129133
## Image
130134

131135
### `warcli image build`
132-
Build bitcoind and bitcoin-cli from \<repo>/\<branch> as \<registry>:\<tag>.
136+
Build bitcoind and bitcoin-cli from \<repo> at \<commit_sha> as \<registry>:\<tag>.
133137
Optionally deploy to remote registry using --action=push, otherwise image is loaded to local registry.
134138

135139
options:
136140
| name | type | required | default |
137141
|------------|--------|------------|-----------|
138142
| repo | String | yes | |
139-
| branch | String | yes | |
143+
| commit_sha | String | yes | |
140144
| registry | String | yes | |
141145
| tag | String | yes | |
142146
| build_args | String | | |
143147
| arches | String | | |
144-
| action | String | | |
148+
| action | String | | "load" |
145149

146150
## Ln
147151

@@ -207,11 +211,11 @@ options:
207211
Start a warnet with topology loaded from a \<graph_file> into [network]
208212

209213
options:
210-
| name | type | required | default |
211-
|------------|--------|------------|-----------------------------------|
212-
| graph_file | Path | | src/warnet/graphs/default.graphml |
213-
| force | Bool | | False |
214-
| network | String | | "warnet" |
214+
| name | type | required | default |
215+
|------------|--------|------------|----------------------------------|
216+
| graph_file | Path | | resources/graphs/default.graphml |
217+
| force | Bool | | False |
218+
| network | String | | "warnet" |
215219

216220
### `warcli network status`
217221
Get status of a warnet named [network]

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ stop:
6161
set -euxo pipefail
6262

6363
kubectl delete namespace warnet
64-
kubectl delete namespace warnet-logging
64+
kubectl delete namespace warnet-logging --ignore-not-found
6565
kubectl config set-context --current --namespace=default
6666

6767
minikube image rm warnet/dev
@@ -84,7 +84,7 @@ startd:
8484
stopd:
8585
# Delete all resources
8686
kubectl delete namespace warnet
87-
kubectl delete namespace warnet-logging
87+
kubectl delete namespace warnet-logging --ignore-not-found
8888
kubectl config set-context --current --namespace=default
8989

9090
echo Done...

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ where = ["src", "resources"]
4141
[tool.ruff]
4242
extend-exclude = [
4343
"src/test_framework/*.py",
44+
"resources/images/exporter/authproxy.py",
4445
]
4546
line-length = 100
4647
indent-width = 4

0 commit comments

Comments
 (0)