Skip to main content

Devops monitoring tool for Nostream

Project description

Prometheus openmetrics for Nostream

events by kind

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nostream_exporter-0.0.2.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

nostream_exporter-0.0.2-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file nostream_exporter-0.0.2.tar.gz.

File metadata

  • Download URL: nostream_exporter-0.0.2.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for nostream_exporter-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8c37c9672c216d741e88875278420512d8b7a1a9fcdc13b00bccbb82104ff257
MD5 0e90e4bb34cb9e35478782c2a159e3f1
BLAKE2b-256 659caedc57914ac8e81379057ba7efa6cf747b03fb4501893e63088838772882

See more details on using hashes here.

File details

Details for the file nostream_exporter-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for nostream_exporter-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 16adf1a15101c12b8ef7db4f9545b53d8a2f45181d41b6b6d19778c654330bd8
MD5 4f7d512c5317244db440c110929afd89
BLAKE2b-256 6ed7f8807df2186c55bcd414294e50679d3d72c128a5c2140e16b3ada1711c32

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page