Prometheus openmetrics for Nostream
A devops component for directly monitoring your nostream relay, which can be integrated with your self-hosted SRE stack. If you don't have a monitoring system set up already, this won't be useful to you. It's basically a python script that runs Postregsql queries to compile basic metrics.
Installation and Usage
pip install nostream-exporter
Define the connection parameters to your Nostream via environment variables. There are multiple ways you can set it up. One example is to create an .env file with the following contents:
export DB_HOST=/var/run/postgresql
export DB_PORT=5432
export DB_NAME=nostream
export DB_USER=nostream
export DB_PASSWORD='hunter2'
export METRICS_PORT=9101
export METRICS_BIND=127.0.0.1
Both the METRICS_PORT and METRICS_BIND options are optional, the defaults are shown.
I would recommend running this as an unprivileged user via systemd (or anything comparable):
useradd -mb /opt -k /dev/null -s $(which nologin) nostream_exporter
Create /etc/systemd/system/nostream_exporter.service:
[Unit]
Description=Basic openmetrics for Nostream nostr relay
[Service]
User=nostream_exporter
Group=nostream_exporter
EnvironmentFile=/opt/nostream_exporter/.env
ExecStart=nostream_exporter
Restart=on-failure
RestartSec=2m
[Install]
WantedBy=multi-user.target
Confirm that it is serving metrics:
curl http://127.0.0.1:9101/metrics
...
# HELP events Count of events by kind
# TYPE events gauge
events{kind="7"} 48184.0
events{kind="1"} 24659.0
events{kind="6"} 3737.0
events{kind="1984"} 3236.0
events{kind="4"} 2265.0
events{kind="other"} 762.0
Development
Clone the repo and install dependencies into a local virtual environment:
git clone git@github.com/bleetube/nostream_exporter
cd nostream_exporter
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install --editable .
source .env
nostream_exporter
Note that there is a difference between source .env and systemd EnvironmentFile which is that you'll need to have the export keyword. i.e. export DB_NAME=nostream
Roadmap
- Include tests
- Change
print()messages into sensible logging with configuration debug levels. - Review events table to possibly discover more metrics.
- Dockerfile
Metadata
Release files for nostream-exporter 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nostream_exporter-0.0.2.tar.gz | 14.1 kB | Without provenance | Details for nostream_exporter-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nostream_exporter-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for nostream_exporter-0.0.2-py3-none-any.whl |
Total release size: 26.9 kB
Release files / nostream_exporter-0.0.2.tar.gz
| Download URL | nostream_exporter-0.0.2.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c37c9672c216d741e88875278420512d8b7a1a9fcdc13b00bccbb82104ff257
|
|
BLAKE2b-256 checksum How to use checksums |
659caedc57914ac8e81379057ba7efa6cf747b03fb4501893e63088838772882
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Release files / nostream_exporter-0.0.2-py3-none-any.whl
| Download URL | nostream_exporter-0.0.2-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
16adf1a15101c12b8ef7db4f9545b53d8a2f45181d41b6b6d19778c654330bd8
|
|
BLAKE2b-256 checksum How to use checksums |
6ed7f8807df2186c55bcd414294e50679d3d72c128a5c2140e16b3ada1711c32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Security for nostream-exporter 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.