Skip to main content

The NTP Statistics Toolkit

Project description

ntpxyz: The NTP Statistics Toolkit

ntpxyz is a lightweight Python tool for parsing and visualizing statistics from NTP servers. It processes standard NTP stats logs—currently loopstats (clock sync), sysstats (network traffic), and usestats (host utilization)—then generates clear, insightful plots using Matplotlib. Designed for both interactive use and automated batch runs, ntpxyz helps monitor NTP server health with minimal fuss.

Whether you're troubleshooting sync issues, analyzing traffic patterns, or checking resource usage, ntpxyz turns raw logs into actionable visuals. It supports command-line options, JSON configs for defaults, and even Telegram notifications for remote or DMZ setups.

PyPI version License: MIT

Example Plots

loopstats

loopstats

sysstats

sysstats

usestats

usestats

Features

  • Supported Stats: Loopstats (offset, drift, Allan deviation), sysstats (packets, errors, efficiency), usestats (CPU, memory, I/O).
  • Flexible Input: Parse single files or scan directories; filter by rolling periods (e.g., last week, month).
  • Output Options: Save plots as PNG, PDF, or SVG; send via Telegram for unattended alerts.
  • Configurable: CLI flags or ~/.config/ntpxyz/config.json for overrides (e.g., save dir, Telegram tokens).
  • Robust: Handles date conversions from NTP's MJD format; basic validation and error logging.

Roadmap includes more stats types, better date filtering, data exports, and comparisons—see roadmap.md for details.

Installation

ntpxyz requires Python 3.11+. Install via pip:

pip install ntpxyz

From source (clone and install editable for dev):

git clone https://github.com/brontsor/ntpxyz.git
cd ntpxyz
poetry install  # Or pip install -e .

Dependencies: allantools, matplotlib, numpy, pandas, requests (all handled by Poetry/pip).

Usage

Run with ntpxyz (or python -m ntpxyz). Provide at least one input source: --loadconfig, --scandir, or --scanfile.

usage: ntpxyz [-h] [-v] [-c CFG] [-p TIME] [-s DIR] [-f FMT] [-n NAME] [-d DIR] [-l FILE]
              [-y TYPE] [-t]

ntpxyz - The NTP Statistics Toolkit

options:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -c, --loadconfig CFG  load values from ConFiG file (e.g., ~/.config/ntpxyz/config.json)
  -p, --period TIME     specify a TIME period for scandir (e.g., rolling-week)
  -s, --savedir DIR     DIRectory to save output files (default: current dir)
  -f, --saveformat FMT  ForMaT of output: pdf, png, svg (default: png)
  -n, --savename NAME   prefix for output file NAME (default: ntpxyz)
  -d, --scandir DIR     scan a DIRectory for stats files and parse all valid matches
  -l, --scanfile FILE   path to a specific ntp statistics FILE (overrides scandir)
  -y, --statstype TYPE  override detected stats type: loopstats, sysstats, usestats
  -t, --telegram        send plot(s) to Telegram (requires config with chat_id/telegram_token)

One of --loadconfig, --scandir, or --scanfile is required. CLI flags override config values.

Examples

Process a directory of logs for the last week:

ntpxyz --scandir /var/log/ntpstats --period rolling-week --saveformat png

This scans for all supported stats types, generates plots, and saves them in the current directory as ntpxyz_loopstats.png, etc.

Load from config and send to Telegram:

ntpxyz --loadconfig ~/.config/ntpxyz/config.json --telegram

Example config.json. Note that passing in an option via CLI overrides the config file value.

{
  "scandir": "/var/log/ntpstats",
  "period": "rolling-month",
  "telegram_token": "your-bot-token",
  "chat_id": "your-chat-id",
  "telegram": true
}

Single file with custom name:

ntpxyz --scanfile /var/log/ntpstats/loopstats.202601 --savename my_ntp_plots

For setup details on Telegram, see telegram_setup.md.

Known Limitations

  • Periods only apply to --scandir.
  • Telegram may hit file size limits for PDFs; use PNG.
  • More stats types (e.g., peerstats) in future releases.

Example outputs and logs: Check the examples/ directory for sample data and plots.

Contributing

Contributions welcome! Fork the repo, create a feature branch (git checkout -b feature/my-addition), commit atomically, and open a PR. Run pre-commit run --all-files before pushing.

Install dev deps: poetry install --only dev.

Test: poetry run pytest.

Lint/Typecheck: poetry run ruff check ., poetry run mypy ., poetry run pyright.

See roadmap.md for priorities.

License

MIT License—see LICENSE for details.


Questions? Open an issue or reach out. Happy wandering!

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

ntpxyz-0.1.1.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ntpxyz-0.1.1-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file ntpxyz-0.1.1.tar.gz.

File metadata

  • Download URL: ntpxyz-0.1.1.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Darwin/25.3.0

File hashes

Hashes for ntpxyz-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a8b933bfced95f94549223d82cf9ac53601db056eab48ae62cb66e5b4e79ea4e
MD5 ae3fa42ddb7692e7d834f93f34854bdb
BLAKE2b-256 18d32d4645f86d75a4bf0470e8535a350a7b4a236ec4d5f0dc359c447bf12169

See more details on using hashes here.

File details

Details for the file ntpxyz-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ntpxyz-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Darwin/25.3.0

File hashes

Hashes for ntpxyz-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b330a7c94843f03a0aec85a0dc7c345dd6dbed994fd1bf720f9642ad5a0beb5
MD5 4c22fd35518ef493f2af514a40058c68
BLAKE2b-256 e87923b1615bef09cf73cff842e7f5b87e56d0616f31883f1704628b20b3e553

See more details on using hashes here.

Supported by

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