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.7.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.7.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_server_monitor-0.1.7.tar.gz
Algorithm Hash digest
SHA256 ee29ea9b6ef9bc8bcd1fe80d70d8d4aaa7d27c7e7eb1a30237665a39666c4725
MD5 40a4090abf5aea3a788b8272c8a59830
BLAKE2b-256 45d3832a4d7f0489434ac157c933fa3a2611a690f4699b9632e9f23b57b31ea6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_server_monitor-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 eda57080a059ba52e73bdcedca9a5df5198c58e450441ae31c3aa5ddc49afbf4
MD5 25a471b92339cc97f99508a63bae2669
BLAKE2b-256 4111b2389f3dea117513624a27283fbe91f873e3c271cc21915990336b915fc1

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