Daemon that acts as both client & server for monitoring latency between different endpoints
Project description
latency-monitor
TCP and UDP latency monitoring tool, with pluggable interface for publishing metrics.
Features
- TCP Latency Monitoring: Monitor TCP connection latency one-way and round-trip to specified endpoints.
- UDP Latency Monitoring: Measure UDP one-way and round-trip time to target hosts.
- Pluggable Metrics: Flexible interface for publishing metrics to various backends
- Configurable: Easy configuration for monitoring targets and intervals,
- Lightweight: Minimal resource footprint for continuous monitoring, so it can be executed on any operating system (where Python is available).
Installation
Note: Package is not yet published to PyPI. This section describes future installation once the package is available.
Install from PyPI:
pip install latency-monitor
For development installation:
git clone https://github.com/mirceaulinic/latency-monitor.git
cd latency-monitor
uv sync --dev
[!IMPORTANT] By default, the project doesn't have any third-party dependencies. However, depending on the metrics backend you want to use, you'll have to install the additional package(s). Using
pip, you can install the additional requirements by running, e.g.,pip install latency-monitor[datadog]if you want to use Datadog as the metrics backend,pip install latency-monitor[zeromq]for ZeroMQ and so on. Similarly if you're usinguv:uv sync --extra datadogfor Datadog,uv sync --extra zeromqfor ZeroMQ, or bothuv sync --extra datadog --extra zeromq.
Configuration
Configuration options can be provided using the latency.toml file (in TOML format). By default, the program will
look for it in the current running directory, otherwise you can use the -c or --config-file CLI argument to
provide the absolute path (including the file name).
Example configuration:
name = "this-host"
max_size = 65535
tcp_port = 17171
udp_port = 17172
[[targets]]
host = "127.0.0.1"
label = "foo"
tags = ["isp:local", "location:laptop"]
[[targets]]
host = "10.0.0.2"
label = "bar"
tcp_port = 1717
udp_port = 1718
size = 65535
[[targets]]
host = "10.0.0.3"
label = "baz"
type = "udp"
interval = 200
[[targets]]
host = "lm.example.com"
timeout = 2
[metrics]
backend = "prometheus"
port = 9090
For every target you want to monitor, you can define a configuration block, with the following options:
[[targets]]
host = "<IP or hostname>"
label = "<label>"
type = "<TCP or UDP>"
tcp_port = <TCP port>
udp_port = <UDP port>
size = <packet size in bytes>
interval = <interval in milliseconds>
timeout = <timeout in seconds>
tags = [<a list of metric tags>]
Any of these settings are optional, except the IP, of course, and are pretty self-explanatory. Each of these can be defined at individual target level, as well as top-level (for all the targets); in other words, target-level options inherit the values from top-level when not configured explicitly.
The default values are:
- TCP port: 8000
- UDP port: 8001
- Size: 1470 (bytes)
- Interval: 1000 (milliseconds)
- Timeout: 1 (second)
- Type: by default both TCP and UDP, unless you only want one
While label is not mandatory, you might want to add it when the host is an IP address. This value will be set as
metric target tag (or label) when set, otherwise host will be used. Of course, when host is an actual
hostname instead of an IP address, label may be superfluous -- but I'd probably advise always using IP addresses
whenever possible to minimise the impact of other services, e.g., DNS.
Metrics Publishing
The tool supports pluggable metrics backends:
- Datadog
- Prometheus
- Cli
- Log
The last two are probably more important for debugging purposes, than actual production use.
Usage
Once you have the configuration file in place, you can start the daemon (in foreground, won't return the command line until you stop via Ctrl-C):
$ latency-monitor -c /path/to/config.toml
[!WARNING] Unlike something like Smokeping, this program MUST run on both sides of a given link. This is necessary particularly for OWD (one-way delay) results.
[!NOTE] You will typically need to configure the metrics backend on both sides of a given link, as each will provide different metrics.
There's also a basic API you can use from your programs, should you wish to build on top of this library:
from latency_monitor.api import LatencyMonitor
# Create a monitor instance
monitor = LatencyMonitor()
# Add TCP endpoint
monitor.add_tcp_target("10.0.0.1", port=8000, label="foo")
# Add UDP endpoint
monitor.add_udp_target("10.0.0.2", port=5001, label="bar")
# Start monitoring
monitor.start()
# Pick metrics from the queue yourself. You'll need to invoke this in a separate thread or process than .start()
metric = monitor.metrics_q.get()
Naturally, the latency-monitor process must be started up and listening on the target hosts.
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and code quality checks
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Install development dependencies
pip install -e ".[dev]"
# Run code formatting
black .
isort .
# Run linters
pylama .
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Author
Mircea Ulinic (@mirceaulinic)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file latency_monitor-0.1.0b0.tar.gz.
File metadata
- Download URL: latency_monitor-0.1.0b0.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18f7b38072185f9e9df437f4e4e9e7b49e4d64413efc1ad5d7a5d0ed88959074
|
|
| MD5 |
9e38837c68ae2b6dab97d0e2aa88df42
|
|
| BLAKE2b-256 |
4ba278cb089ef3ad1e8b491d53d6bb7649001ac82aba8b5b91466a492a12fd78
|
File details
Details for the file latency_monitor-0.1.0b0-py3-none-any.whl.
File metadata
- Download URL: latency_monitor-0.1.0b0-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e70a809dc78f1cee7af1c9bfadab36640c2b12cea76c60ca49f0626e5eb1576
|
|
| MD5 |
327fb3560be20072ed877224c1854ba0
|
|
| BLAKE2b-256 |
4882bacbeb3c52a83ecd6bb90863f0b529e9d30f605f1913ce4a34260b3ae903
|