Metadata-Version: 2.5
Name: nodeping-exporter
Version: 0.1.0
Summary: Prometheus exporter for NodePing checks, including AGENT checks and subaccounts
Project-URL: Homepage, https://gitlab.com/ggiesen/nodeping-exporter
Project-URL: Source, https://gitlab.com/ggiesen/nodeping-exporter
Project-URL: Issues, https://gitlab.com/ggiesen/nodeping-exporter/-/issues
Project-URL: Changelog, https://gitlab.com/ggiesen/nodeping-exporter/-/blob/master/CHANGELOG.md
Author-email: "Gary T. Giesen" <ggiesen@giesen.me>
License-Expression: MPL-2.0
License-File: LICENSE
Keywords: exporter,monitoring,nodeping,prometheus
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: No Input/Output (Daemon)
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27
Requires-Dist: prometheus-client>=0.20
Requires-Dist: pydantic>=2.6
Provides-Extra: dev
Requires-Dist: mypy==2.4.1; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff==0.17.5; extra == 'dev'
Description-Content-Type: text/markdown

# nodeping-exporter

Prometheus exporter for [NodePing](https://nodeping.com) checks, including
AGENT checks and the checks that run on them, across a parent account and its
subaccounts.

The main thing it adds over NodePing's own view is freshness. NodePing keeps
a check's last state when results stop arriving, so a check pinned to an agent
that died months ago still shows up. This exporter exposes the time of every
check's last result and which agent each check depends on, so that case can
be alerted on. See [docs/DESIGN.md](docs/DESIGN.md) section 4.

## How it works

A background thread polls `GET /checks?lastresult=1` once per account per
interval (default 60 s) and keeps the result in memory. Scrapes render that
snapshot and never call the NodePing API, so API load does not depend on how
many scrapers there are or how often they scrape. Subaccounts are discovered
from `GET /accounts` every 15 minutes; the parent account's token reads all of
them.

The exporter only issues GET requests.

## Installation

Requires Python 3.11 or newer (AlmaLinux 10 ships 3.12; on EL9 install the
`python3.12` package, or let uv fetch an interpreter). The container image is
one option; the exporter is an ordinary Python package and runs fine from a
venv.

### uv tool (quickest, per-user)

Releases are published to [PyPI](https://pypi.org/project/nodeping-exporter/):

```console
$ uv tool install nodeping-exporter
$ NODEPING_TOKEN=... nodeping-exporter
```

An unreleased commit installs straight from git with
`git+https://gitlab.com/ggiesen/nodeping-exporter.git@<ref>` in place of the
package name.

### venv + systemd (servers)

```console
# uv venv /opt/nodeping-exporter --python 3.12
# uv pip install --python /opt/nodeping-exporter/bin/python nodeping-exporter==0.1.0
# install -d -m 0700 /etc/nodeping-exporter
# (umask 077; cat > /etc/nodeping-exporter/token)   # paste token, then Ctrl-D
# cp contrib/systemd/environment.example /etc/nodeping-exporter/environment
# cp contrib/systemd/nodeping-exporter.service /etc/systemd/system/
# systemctl daemon-reload && systemctl enable --now nodeping-exporter
```

Plain `python3 -m venv` + `pip install` works the same way if uv isn't
available. The unit runs as a systemd dynamic user, gets the token through
`LoadCredential` (the token file stays root-only), and is hardened
(`systemd-analyze security` exposure 1.4). Upgrade by re-running the
`uv pip install` with a newer version and restarting the service.

### Container

```console
$ podman run -d -p 10062:10062 \
    -v /path/to/token:/etc/nodeping-exporter/token:ro \
    registry.gitlab.com/ggiesen/nodeping-exporter:<tag>
```

The image runs as UID 65532 and reads the token from
`/etc/nodeping-exporter/token` by default.

## Configuration

| Flag | Env | Default | |
|---|---|---|---|
| `--nodeping.token-file` | `NODEPING_TOKEN_FILE` | | File containing the API token. Preferred over `NODEPING_TOKEN`. |
| | `NODEPING_TOKEN` | | API token, used if no token file is given. |
| `--web.listen-address` | `NODEPING_EXPORTER_LISTEN_ADDRESS` | `:10062` | `:port` listens on IPv4 and IPv6. |
| `--web.telemetry-path` | | `/metrics` | |
| `--nodeping.poll-interval` | `NODEPING_POLL_INTERVAL` | `60` | Seconds between polls of each account. Checks run at most once a minute. |
| `--nodeping.max-snapshot-age` | | `600` | Drop an account's check series if its last good poll is older than this. |
| `--nodeping.account` | `NODEPING_ACCOUNT` (comma list) | | Poll only these customerids (repeatable). Can't be combined with include/exclude. |
| `--nodeping.accounts.include` | `NODEPING_ACCOUNTS_INCLUDE` | | Regex on customerid or name; poll only matching accounts. |
| `--nodeping.accounts.exclude` | `NODEPING_ACCOUNTS_EXCLUDE` | | Regex on customerid or name; skip matching accounts. |
| `--nodeping.agent-source-ip` | | off | Add `source_ip` to `nodeping_agent_info`. |
| `--nodeping.no-target-label` | | off | Leave `target` off `nodeping_check_info`. |
| `--nodeping.api-url` | | `https://api.nodeping.com/api/1/` | |
| `--nodeping.timeout` | | `60` | API request timeout, seconds. |
| `--log.level` | `LOG_LEVEL` | `INFO` | |

At startup the exporter fetches the account list before it opens its port. It
exits with status 2 if `--nodeping.account` names an account the token can't
see, or if include/exclude match no account, and with status 1 if the API
still fails after 3 attempts (bad token, API unreachable). After startup, an
account that disappears is dropped with a warning; if every selected account
disappears, the previous list is kept and a warning logged.

Other endpoints: `/-/healthy` (always 200 while running) and `/-/ready` (200
once every selected account has been polled successfully at least once).

Port 10062 is not registered in the Prometheus
[default port allocations](https://github.com/prometheus/prometheus/wiki/Default-port-allocations);
it was unallocated on 2026-11-13 and should be registered if the project goes
public.

## Deployment models

Both are supported; pick per deployment.

### Central exporter, one scrape per account (recommended)

One exporter polls every account. Each consumer scrapes only its account by
adding `account=<customerid>` to the scrape:

```
GET /metrics?account=<customerid>
```

The per-account view contains only series labelled with that account,
including that account's `nodeping_poll_errors_total` and
`nodeping_parse_errors_total`. Probe info and the exporter's own API and
process metrics are only on the plain `/metrics`. An account the exporter does
not poll returns 404, so a mistyped customerid shows up as a failed scrape
(`up == 0`), not an empty one. Scrapes never call the NodePing API, so adding
consumers adds no API load.

Alloy:

```alloy
prometheus.scrape "nodeping_customer" {
  targets    = [{"__address__" = "nodeping-exporter.monitoring.svc:10062", "instance" = "<customerid>"}]
  params     = { "account" = ["<customerid>"] }
  forward_to = [prometheus.remote_write.default.receiver]
}
```

Prometheus:

```yaml
scrape_configs:
  - job_name: nodeping-customer
    params:
      account: ["<customerid>"]
    static_configs:
      - targets: ["nodeping-exporter.monitoring.svc:10062"]
        labels:
          instance: "<customerid>"
```

The token lives in one place. Consumers in other namespaces need network
access to the exporter's port.

### One instance per account

Pin each instance with `--nodeping.account <customerid>`, for example one per
customer namespace.

Every instance still needs the **parent** token: NodePing subaccounts have no
API tokens of their own. Each copy of that token can read, change and delete
checks on every account, so do not place it anywhere a customer, or anyone
scoped to one customer, can read Secrets. See docs/DESIGN.md section 12.

## API token

NodePing API tokens belong to the parent account and are read/write across
the parent and every subaccount; NodePing does not document a read-only token.
Treat the token as a credential that can delete every check (NodePing config
is not versioned anywhere, so deletions are not recoverable from Git).

## Metrics

See [docs/METRICS.md](docs/METRICS.md) for the full list and
[docs/alerts.example.yaml](docs/alerts.example.yaml) for example alert rules.

## Development

```console
$ make venv     # .venv with the package and dev tools
$ make all      # ruff, mypy, pytest
$ make image    # podman build
```

Tests run against synthetic fixtures in `tests/fixtures/` that reproduce the
live API's quirks. Never commit real API output; it contains customer ids,
internal targets, agent tokens and, for some check types, passwords.

## Repository layout

| Path | |
|---|---|
| `src/nodeping_exporter/client.py` | Read-only API client and API metrics. |
| `src/nodeping_exporter/models.py` | pydantic models that absorb the API's loose typing. |
| `src/nodeping_exporter/snapshot.py` | Parsing, AGENT relationships, target sanitizing. |
| `src/nodeping_exporter/poller.py` | Background polling, account discovery. |
| `src/nodeping_exporter/collector.py` | Renders snapshots as metrics. |
| `src/nodeping_exporter/cli.py` | Flags and HTTP server. |
| `contrib/systemd/` | systemd unit and environment file for venv installs. |
| `docs/DESIGN.md` | Design, API findings, decisions and open questions. |

## Branching and CI

`master` is the primary branch; changes go through feature branches and merge
requests. The GitLab pipeline runs ruff (lint and format check), mypy and
pytest on every branch, and builds and pushes the container image to the
project's GitLab registry on `master` (tagged with the short commit SHA) and
on tags (also tagged with the git tag). Every branch also builds the wheel and
sdist with uv and smoke-tests the wheel in a clean venv.

Releasing: bump `__version__` in `src/nodeping_exporter/__init__.py` (the
only place the version lives), update `CHANGELOG.md`, then tag `vX.Y.Z`. On a
`vX.Y.Z` tag the pipeline publishes the package to PyPI with trusted
publishing (GitLab OIDC, `release` environment; no stored API token). The job
fails if the tag and the package version disagree. PyPI never accepts the same
version twice, so a bad release is fixed with a new version, not a re-tag.

## License

[MPL-2.0](LICENSE)
