Skip to main content

System metrics collector for CPU, memory, disk, and network

Project description

philiprehberger-server-monitor

Tests PyPI version License

System metrics collector for CPU, memory, disk, and network.

Installation

pip install philiprehberger-server-monitor

Usage

from philiprehberger_server_monitor import Monitor, Alert

monitor = Monitor()

# Single snapshot
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}%")

# Continuous monitoring with alerts
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=send_alert),
    ],
)

# Export snapshot
data = snap.to_dict()

Metrics

Category Fields
CPU percent, count, count_logical, per_cpu, freq_mhz
Memory total, available, used, percent, total_gb, used_gb
Disk mountpoint, total, used, free, percent
Network bytes_sent, bytes_recv, packets_sent, packets_recv

API

Function / Class Description
Monitor System metrics monitor with snapshot(), watch(), and stop() 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

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

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

philiprehberger_server_monitor-0.1.8.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file philiprehberger_server_monitor-0.1.8.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_server_monitor-0.1.8.tar.gz
Algorithm Hash digest
SHA256 b0885e13a14c06015261b3ac942e08abd529e17197b727d0dab844b05a8af380
MD5 c0a485ad57461696c79c1387c0a49fd5
BLAKE2b-256 3199e58d4c45db3c858f30a84d5861690f468bbed00394f05a683e836f597b84

See more details on using hashes here.

File details

Details for the file philiprehberger_server_monitor-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_server_monitor-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 25e2c742d941610578992c0905eebfab28039cbc47e7a93ff6231e05354ffcf2
MD5 cabd20acda2b0a1d09adde21bbb4d2ca
BLAKE2b-256 d16832b9d994b58da45435d2ffde0ca6173be86a99c302a28796353d4a2af26e

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