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

File metadata

File hashes

Hashes for philiprehberger_server_monitor-0.1.6.tar.gz
Algorithm Hash digest
SHA256 53d56b8b3f23cc34f9805fda4fe44b51b791ecb5470a1a66406188bf77148c86
MD5 4f04b68ecd925deb932d9edf5dbb69aa
BLAKE2b-256 6c93e1fa31353577db19f7a09c85e0322870d5cbfe0b15dbf63c1122daf8932e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_server_monitor-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 49f5c637490d84081dbccf9e71ce59db0b72d68a9c61f086438279148999b653
MD5 5b510d8339748774b299e0080108830b
BLAKE2b-256 610f12b99b2450e303380845e015691d385681ca48b84197d3b33080a07ecc98

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