Skip to content

Commit 041fecc

Browse files
nitramizcdecker
authored andcommitted
prometheus: Add uv support with inline deps
CI: Install uv in CLN Python package deps jobs Update shebang to use uv run --script and add inline metadata block Update README with both install methods
1 parent 078887e commit 041fecc

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ jobs:
168168
cd lightning
169169
pip3 install --user -U \
170170
pip \
171+
uv \
171172
poetry \
172173
poetry-plugin-export \
173174
wheel \

prometheus/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,46 @@ Exposed variables include:
1616
HTLCs are currently attached to the channel
1717
- `funds`: satoshis in on-chain outputs, satoshis allocated to channels and
1818
total sum (may be inaccurate during channel resolution).
19+
20+
## Installation
21+
### Using uv (recommended)
22+
* Install `uv` and make the plugin executable
23+
```
24+
pip install --upgrade pip uv
25+
chmod a+x prometheus.py
26+
```
27+
Then you can add _just that file_ to your Core Lightning plugins directory. The plugin should start automatically and its dependencies will be installed on-the-fly when the node comes up.
28+
29+
### Using poetry (legacy)
30+
If you don't want to use `uv`, you can still use `poetry`. You need to update the shebang line to point the OS at the correct interpreter (`python3`) though:
31+
```
32+
sed -i 's#-S uv run --script#python3#' prometheus.py
33+
```
34+
35+
Then install `poetry` and build the package:
36+
```
37+
pip install --upgrade pip poetry
38+
poetry install --only main
39+
```
40+
41+
This is an example snippet for installing the plugin's dependencies and cleaning up afterwards:
42+
```
43+
PLUGIN_PATH=/opt/plugins
44+
RAW_GH_PLUGINS=https://raw.githubusercontent.com/lightningd/plugins/master
45+
mkdir -p ${PLUGIN_PATH}
46+
47+
pip3 install --break-system-packages --upgrade pip wheel poetry
48+
49+
# Add custom plugins (prometheus)
50+
## This replaces the shebang line that by default uses uv for package management
51+
(cd $PLUGIN_PATH; wget -q $RAW_GH_PLUGINS/prometheus/README.md \
52+
&& wget -q $RAW_GH_PLUGINS/prometheus/pyproject.toml \
53+
&& wget -q $RAW_GH_PLUGINS/prometheus/poetry.lock \
54+
&& wget -q $RAW_GH_PLUGINS/prometheus/prometheus.py \
55+
&& sed -i 's#-S uv run --script#python3#' prometheus.py \
56+
&& poetry config virtualenvs.create false \
57+
&& PIP_BREAK_SYSTEM_PACKAGES=1 poetry install --only main \
58+
&& rm -f README.md pyproject.toml poetry.lock)
59+
60+
chmod a+x $PLUGIN_PATH/*
61+
```

prometheus/prometheus.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env -S uv run --script
2+
3+
# /// script
4+
# requires-python = ">=3.9"
5+
# dependencies = [
6+
# "prometheus-client>=0.20.0",
7+
# "pyln-client>=24.5"
8+
# ]
9+
# ///
10+
211
from pyln.client import Plugin
312
from prometheus_client import start_http_server, CollectorRegistry
413
from prometheus_client.core import InfoMetricFamily, GaugeMetricFamily

0 commit comments

Comments
 (0)