Metadata-Version: 2.4
Name: philiprehberger-server-monitor
Version: 0.1.7
Summary: System metrics collector for CPU, memory, disk, and network
Project-URL: Homepage, https://github.com/philiprehberger/py-server-monitor#readme
Project-URL: Repository, https://github.com/philiprehberger/py-server-monitor
Project-URL: Issues, https://github.com/philiprehberger/py-server-monitor/issues
Project-URL: Changelog, https://github.com/philiprehberger/py-server-monitor/blob/main/CHANGELOG.md
Author: Philip Rehberger
License-Expression: MIT
License-File: LICENSE
Keywords: health,metrics,monitor,server,uptime
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: psutil>=5.9
Description-Content-Type: text/markdown

# philiprehberger-server-monitor

[![Tests](https://github.com/philiprehberger/py-server-monitor/actions/workflows/publish.yml/badge.svg)](https://github.com/philiprehberger/py-server-monitor/actions/workflows/publish.yml)
[![PyPI version](https://img.shields.io/pypi/v/philiprehberger-server-monitor.svg)](https://pypi.org/project/philiprehberger-server-monitor/)
[![License](https://img.shields.io/github/license/philiprehberger/py-server-monitor)](LICENSE)

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

## Installation

```bash
pip install philiprehberger-server-monitor
```

## Usage

```python
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

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

## License

MIT
