System metrics collector for CPU, memory, disk, and network
Project description
philiprehberger-server-monitor
System metrics collector for CPU, memory, disk, and network.
Installation
pip install philiprehberger-server-monitor
Usage
Single Snapshot
from philiprehberger_server_monitor import Monitor
monitor = Monitor()
snap = monitor.snapshot()
print(f"CPU: {snap.cpu.percent}%")
print(f"Memory: {snap.memory.used_gb:.1f}/{snap.memory.total_gb:.1f} GB")
print(f"Disk: {snap.disk['/'].percent}%")
# Export snapshot
data = snap.to_dict()
Continuous Monitoring with Alerts
from philiprehberger_server_monitor import Monitor, Alert
monitor = Monitor()
monitor.watch(
interval=5.0,
on_snapshot=lambda s: print(f"CPU: {s.cpu.percent}%"),
alerts=[
Alert(metric="cpu.percent", threshold=90, callback=lambda m, v, t: print(f"HIGH CPU: {v}%")),
Alert(metric="memory.percent", threshold=85, callback=lambda m, v, t: print(f"HIGH MEM: {v}%")),
],
)
Trend Tracking
from philiprehberger_server_monitor import Monitor
monitor = Monitor()
# Start recording snapshots every 5 seconds (keeps last 720)
monitor.start_recording(interval=5.0, max_snapshots=720)
# Later, analyze trends over the last 5 minutes
trend = monitor.get_trend("cpu.percent", window_seconds=300)
print(f"CPU slope: {trend.slope:.4f}%/s")
print(f"CPU went from {trend.start_value}% to {trend.end_value}%")
# Stop recording
monitor.stop_recording()
API
| Function / Class | Description |
|---|---|
Monitor |
System metrics monitor with snapshot(), watch(), stop(), and trend tracking methods |
Snapshot |
A point-in-time system metrics snapshot with cpu, memory, disk, network fields |
CpuInfo |
CPU metrics (percent, count, count_logical, per_cpu, freq_mhz) |
MemoryInfo |
Memory metrics (total, available, used, percent) with GB properties |
DiskInfo |
Disk metrics for a single mount point (total, used, free, percent) |
NetworkInfo |
Network metrics (bytes_sent, bytes_recv, packets_sent, packets_recv) |
Alert(metric, threshold, callback) |
Threshold-based alert configuration for continuous monitoring |
Trend |
Trend analysis result with metric, start_value, end_value, slope, duration_seconds |
monitor.start_recording(interval, max_snapshots) |
Start background snapshot recording into a ring buffer |
monitor.stop_recording() |
Stop the recording thread |
monitor.get_trend(metric, window_seconds) |
Compute linear trend for a metric over recent snapshots |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
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 philiprehberger_server_monitor-0.2.1.tar.gz.
File metadata
- Download URL: philiprehberger_server_monitor-0.2.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6074259f05a35dd4a2f3728118e7d381ac18a398eb1bd7945c7b5f4d2e8a189
|
|
| MD5 |
6c40a934c6a9ee19304133a4fb2516b8
|
|
| BLAKE2b-256 |
35a5ad17f0980c014866ffa5477883fe65d34c7863219d8a698e032ebdae14e5
|
File details
Details for the file philiprehberger_server_monitor-0.2.1-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_server_monitor-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6da18ff6e72db66dcd14e97973c40f8e1476899863ea381367605b7b75c071bf
|
|
| MD5 |
2fd785e99936154e3eaf18857d867d49
|
|
| BLAKE2b-256 |
38cbf8a13cf2d254806288cbd3c3364f04123db572b686777e2f8ebcf8b511c7
|