sosmonitor 0.3.2__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sosmonitor-0.4.0/PKG-INFO +249 -0
- sosmonitor-0.4.0/README.md +221 -0
- sosmonitor-0.4.0/sosmonitor.egg-info/PKG-INFO +249 -0
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/sosmonitor.py +115 -23
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/tests/test_sosmonitor.py +195 -13
- sosmonitor-0.3.2/PKG-INFO +0 -392
- sosmonitor-0.3.2/README.md +0 -364
- sosmonitor-0.3.2/sosmonitor.egg-info/PKG-INFO +0 -392
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/LICENSE +0 -0
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/pyproject.toml +0 -0
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/setup.cfg +0 -0
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/sosmonitor.egg-info/SOURCES.txt +0 -0
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/sosmonitor.egg-info/dependency_links.txt +0 -0
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/sosmonitor.egg-info/entry_points.txt +0 -0
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/sosmonitor.egg-info/requires.txt +0 -0
- {sosmonitor-0.3.2 → sosmonitor-0.4.0}/sosmonitor.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sosmonitor
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Simple server monitor: CPU, memory, disk and load alerts by webhook or email. One file, no root, no dependencies.
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/diemsouza/sosmonitor
|
|
7
|
+
Project-URL: Repository, https://github.com/diemsouza/sosmonitor
|
|
8
|
+
Project-URL: Changelog, https://github.com/diemsouza/sosmonitor/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Issues, https://github.com/diemsouza/sosmonitor/issues
|
|
10
|
+
Keywords: monitoring,server,alerts,webhook,cron,n8n
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Operating System :: MacOS
|
|
17
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Topic :: System :: Monitoring
|
|
21
|
+
Classifier: Topic :: System :: Systems Administration
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Provides-Extra: psutil
|
|
26
|
+
Requires-Dist: psutil>=5.9; extra == "psutil"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# SOSMonitor
|
|
30
|
+
|
|
31
|
+
[](https://pypi.org/project/sosmonitor/)
|
|
32
|
+
[](https://pypi.org/project/sosmonitor/)
|
|
33
|
+
[](LICENSE)
|
|
34
|
+
|
|
35
|
+
> Sometimes simple is more than enough.
|
|
36
|
+
|
|
37
|
+
A tiny server monitor that watches **CPU, memory, disk, load average and uptime** and tells you when something crosses a limit or the server reboots, by **webhook** (n8n, Make, Zapier, your own endpoint...) and/or **email**.
|
|
38
|
+
|
|
39
|
+
No agent, no paid service, no dashboard, no root. One Python file run by cron. It fits any server that just needs a simple "hey, the disk is at 90%" alert, and it was born on locked-down hosts (Cloudways and similar).
|
|
40
|
+
|
|
41
|
+
One file (`sosmonitor.py`), Python 3.8+ standard library only (`psutil` optional), scheduled in your own crontab, writing only next to its config. One alert per level change, with a margin so a value hovering around a threshold doesn't flood your inbox.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
Pick by what your host lets you do: the **package** if you can install software (EC2, a VPS), the **single file** if you can't (managed hosts).
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Package
|
|
49
|
+
sudo apt install pipx # Debian/Ubuntu. Fedora/Amazon Linux: sudo dnf install pipx
|
|
50
|
+
pipx install sosmonitor
|
|
51
|
+
pipx ensurepath && exec $SHELL
|
|
52
|
+
|
|
53
|
+
# Single file (no pip, no root)
|
|
54
|
+
mkdir ~/sosmonitor && cd ~/sosmonitor
|
|
55
|
+
curl -fsSLO https://github.com/diemsouza/sosmonitor/raw/main/sosmonitor.py
|
|
56
|
+
python3 sosmonitor.py install # this first call replaces `sosmonitor install`
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Then, either way:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
sosmonitor install # 1. creates the config, schedules cron, creates the command
|
|
63
|
+
sosmonitor config # 2. opens the config: set server_name, webhook and/or email
|
|
64
|
+
sosmonitor test # 3. prints a test alert and sends it to the enabled channels
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`install` is safe to run again and ends with a summary of each step (`created`, `ok`, `already`, `manual` or `failed`). On macOS and Windows, CPU and memory need `psutil`: `pipx install "sosmonitor[psutil]"`.
|
|
68
|
+
|
|
69
|
+
## Commands
|
|
70
|
+
|
|
71
|
+
| Command | What it does |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `sosmonitor` (or `run`) | One check. This is what cron calls. Never creates a config |
|
|
74
|
+
| `sosmonitor test` | Prints a test alert, sends it to every enabled channel and shows the result |
|
|
75
|
+
| `sosmonitor config` | Creates the config if missing and opens it in your editor, then checks the JSON |
|
|
76
|
+
| `sosmonitor install` | Creates the config if missing, adds the crontab entry and the `sosmonitor` command (`--no-shortcut` skips the command) |
|
|
77
|
+
| `sosmonitor uninstall` | Removes the crontab entry, the command and its PATH lines |
|
|
78
|
+
| `sosmonitor --version` | Prints the version ([CHANGELOG](CHANGELOG.md)) |
|
|
79
|
+
|
|
80
|
+
Add `-c /path/to.json` to any command to use another config. Before `install` on a single-file download, use `python3 sosmonitor.py ...`.
|
|
81
|
+
|
|
82
|
+
## config.json
|
|
83
|
+
|
|
84
|
+
Created by `install` or `config` (`chmod 600`, since it holds passwords and tokens):
|
|
85
|
+
|
|
86
|
+
```json
|
|
87
|
+
{
|
|
88
|
+
"server_name": "MY-SERVER",
|
|
89
|
+
"check_interval_minutes": 1,
|
|
90
|
+
"disk_path": "/",
|
|
91
|
+
"send_every_check": true,
|
|
92
|
+
"sustain_checks": 1,
|
|
93
|
+
"thresholds": {
|
|
94
|
+
"70": "{metric} at {value}%",
|
|
95
|
+
"80": "{metric} at {value}% (WARNING)",
|
|
96
|
+
"90": "{metric} at {value}% (CRITICAL)",
|
|
97
|
+
"100": "{metric} at {value}% (AT LIMIT)"
|
|
98
|
+
},
|
|
99
|
+
"recovery_message": "{metric} at {value}% (BACK TO NORMAL)",
|
|
100
|
+
"reboot_message": "{server} restarted (up for {value})",
|
|
101
|
+
"top_processes": { "enabled": true, "count": 3 },
|
|
102
|
+
"webhook": { "enabled": false, "url": "", "token": "", "token_header": "X-Monitor-Token" },
|
|
103
|
+
"email": {
|
|
104
|
+
"enabled": false, "smtp_host": "smtp.gmail.com", "smtp_port": 587,
|
|
105
|
+
"username": "", "password": "", "from": "", "to": ["you@example.com"]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
| Key | What it does |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `server_name` | Name shown in alerts and in the email subject |
|
|
113
|
+
| `check_interval_minutes` | How often cron runs the check (used by `install`, 1 to 59) |
|
|
114
|
+
| `disk_path` | Partition to measure (`/`, `/home`, `C:\` ...) |
|
|
115
|
+
| `send_every_check` | `true`: the webhook receives the metrics on every check. `false`: only when there is an alert. Email is only sent for alerts |
|
|
116
|
+
| `sustain_checks` | Consecutive checks a metric must stay at or above a level before alerting. `1` (default) alerts at once; try `3` on noisy servers. Recovery is never delayed |
|
|
117
|
+
| `thresholds` | Levels in % and the message for each. They apply to CPU, memory and disk. Your object **replaces** the default list, so include every level you want |
|
|
118
|
+
| `recovery_message` | Sent when a metric goes back below the lowest level |
|
|
119
|
+
| `reboot_message` | Sent on the first check after the server restarts. `{value}` is the uptime, like `12m` or `3d 4h 12m` |
|
|
120
|
+
| `top_processes` | `enabled` and `count`: list the top CPU or memory consumers, only when that metric alerts |
|
|
121
|
+
| `webhook` | `url` receives a JSON `POST`. `token`, if set, goes in the header named by `token_header` |
|
|
122
|
+
| `email` | SMTP settings. Port 465 uses SSL; other ports use STARTTLS when offered. For Gmail use an [app password](https://myaccount.google.com/apppasswords). `to` is a list |
|
|
123
|
+
|
|
124
|
+
Placeholders: `{server}`, `{metric}` (CPU, Memory, Disk) and `{value}` (rounded %, or the uptime in `reboot_message`). Messages can be in any language. Keys missing from your file use their default.
|
|
125
|
+
|
|
126
|
+
## How alerts work
|
|
127
|
+
|
|
128
|
+
SOSMonitor remembers the last level of each metric (in `sosmonitor_state.json`) and **only alerts when that level changes**:
|
|
129
|
+
|
|
130
|
+
- **Going up is immediate.** 72% is level 70, 85% is level 80.
|
|
131
|
+
- **Going down needs a 5-point margin**, so a value hovering around a threshold doesn't alternate alerts and recoveries.
|
|
132
|
+
- **CPU is an average since the previous check**, which matches your host's graph and ignores a burst from another cron job. The first check after install or a reboot takes a 1-second sample.
|
|
133
|
+
- **Reboots** alert once: the first check after the server restarts says it started and for how long. It never fires on the first run after installing or updating.
|
|
134
|
+
|
|
135
|
+
Example with levels 70 and 80:
|
|
136
|
+
|
|
137
|
+
| Check | Value | Level | Alert |
|
|
138
|
+
| --- | --- | --- | --- |
|
|
139
|
+
| 1 | 65% | 0 | – |
|
|
140
|
+
| 2 | 71% | 70 | **"CPU at 71%"** |
|
|
141
|
+
| 3 | 69% | 70 | – (still within 70 − 5) |
|
|
142
|
+
| 4 | 83% | 80 | **"CPU at 83% (WARNING)"** |
|
|
143
|
+
| 5 | 77% | 80 | – (still within 80 − 5) |
|
|
144
|
+
| 6 | 74% | 70 | **"CPU at 74%"** |
|
|
145
|
+
| 7 | 64% | 0 | **"CPU at 64% (BACK TO NORMAL)"** |
|
|
146
|
+
|
|
147
|
+
Load average and uptime are collected and sent on every check but have no thresholds, so they never alert by themselves.
|
|
148
|
+
|
|
149
|
+
## What is sent
|
|
150
|
+
|
|
151
|
+
Every alert goes to every enabled channel; if all fail, it is retried on the next check. The title shows **only the most severe alert** plus a counter; the body lists them all:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
[SOSMonitor] MY-SERVER: Memory at 85% (WARNING) (+1 more)
|
|
155
|
+
|
|
156
|
+
Alerts:
|
|
157
|
+
- Memory at 85% (WARNING)
|
|
158
|
+
- CPU at 75%
|
|
159
|
+
|
|
160
|
+
Top processes by memory:
|
|
161
|
+
1. php-fpm 8.2% (1.3 GB)
|
|
162
|
+
2. mysqld 6.1% (1.0 GB)
|
|
163
|
+
|
|
164
|
+
Current metrics:
|
|
165
|
+
CPU 75% | MEMORY 85% | DISK 54% | UPTIME 3d 4h 12m
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Top processes are looked up only when a CPU or memory alert goes out, by command name only, never arguments. If the host hides them, the alert is sent without the list.
|
|
169
|
+
|
|
170
|
+
The webhook receives this JSON:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"server": "MY-SERVER",
|
|
175
|
+
"hostname": "web-01",
|
|
176
|
+
"timestamp": "2026-11-19T20:15:00-03:00",
|
|
177
|
+
"metrics": {
|
|
178
|
+
"cpu": { "percent": 83.0 },
|
|
179
|
+
"memory": { "percent": 61.2, "total_bytes": 4100000000, "available_bytes": 1590000000, "used_bytes": 2510000000 },
|
|
180
|
+
"disk": { "percent": 47.9, "total_bytes": 80000000000, "used_bytes": 38300000000, "free_bytes": 41700000000, "path": "/" },
|
|
181
|
+
"load": { "1m": 1.2, "5m": 0.9, "15m": 0.7, "cpu_count": 2, "1m_per_cpu": 0.6 },
|
|
182
|
+
"uptime": { "seconds": 273120, "boot_time": 1763400000, "boot_id": "5d0f1c2e-3b4a-4c6d-8e7f-0a1b2c3d4e5f" }
|
|
183
|
+
},
|
|
184
|
+
"alerts": [{ "metric": "cpu", "value": 83.0, "threshold": 80, "previous_threshold": 70,
|
|
185
|
+
"message": "CPU at 83% (WARNING)" }],
|
|
186
|
+
"top_processes": [{ "metric": "cpu", "name": "php-fpm", "percent": 62.5 }],
|
|
187
|
+
"message_title": "[SOSMonitor] MY-SERVER: CPU at 83% (WARNING)",
|
|
188
|
+
"message_body": "Server: MY-SERVER\n..."
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
- `message_title` and `message_body` are the email subject and body, ready to forward to WhatsApp, Telegram or Slack. Without alerts, `alerts` is empty and both are `""`, so in n8n you can filter on `message_title != ""`.
|
|
193
|
+
- `top_processes` is a flat list with a `metric` (`cpu` or `memory`) on each item, present only when there is something to report. Memory items also have `rss_bytes`.
|
|
194
|
+
- A reboot is an alert with `"metric": "reboot"` and `"threshold": 0`; its `value` is the uptime in seconds. `uptime` has no threshold. `boot_id` is `null` where the OS has none.
|
|
195
|
+
- The `test` command fills the message fields and adds `"test": true`.
|
|
196
|
+
|
|
197
|
+
## Platforms
|
|
198
|
+
|
|
199
|
+
| | CPU / memory | Disk / load | Uptime / reboot alert | Scheduling | Dependencies |
|
|
200
|
+
| --- | --- | --- | --- | --- | --- |
|
|
201
|
+
| **Linux** | Native (`/proc`) | Native | Native | User crontab | None |
|
|
202
|
+
| **macOS** | Needs `psutil` | Native | Needs `psutil` | User crontab | `pipx install "sosmonitor[psutil]"` |
|
|
203
|
+
| **Windows** | Needs `psutil` | Disk native, load via `psutil` | Needs `psutil` | Task Scheduler (`install` prints the `schtasks` command) | `pipx install "sosmonitor[psutil]"` |
|
|
204
|
+
|
|
205
|
+
Without `psutil`, the metrics it provides are skipped and nothing breaks.
|
|
206
|
+
|
|
207
|
+
## Files created (always next to the config in use)
|
|
208
|
+
|
|
209
|
+
| File | Content |
|
|
210
|
+
| --- | --- |
|
|
211
|
+
| `sosmonitor.log` | One JSON line per check (metrics, alerts, delivery result). Rotates to `.log.1` at 5 MB |
|
|
212
|
+
| `sosmonitor_state.json` | Last level of each metric, the `sustain_checks` counters, the CPU counters for the next average and the last seen boot (id and time) |
|
|
213
|
+
| `.sosmonitor.lock` | Prevents two checks from running at the same time |
|
|
214
|
+
|
|
215
|
+
## Updating
|
|
216
|
+
|
|
217
|
+
Package: `pipx upgrade sosmonitor`. Single file: back up and re-download it (`cp sosmonitor.py sosmonitor.py.bak`, then the same `curl -fsSLO` as above). Then run `sosmonitor --version && sosmonitor test`.
|
|
218
|
+
|
|
219
|
+
Your config, log and state are never touched. Read the [CHANGELOG](CHANGELOG.md) for the versions in between: each entry has a "Config changes" line. New keys work from their default; to use one, add it by hand (`config.example.json` is the reference).
|
|
220
|
+
|
|
221
|
+
## FAQ
|
|
222
|
+
|
|
223
|
+
**Where does the config live?** Order: `-c file`, then a `config.json` next to `sosmonitor.py` if one already exists (existing installs keep working), otherwise `~/.config/sosmonitor/config.json` (`$XDG_CONFIG_HOME`, or `%APPDATA%\SOSMonitor` on Windows). The log, state and lock always live next to the config in use. Existing files are never moved or copied, and the user folder survives package upgrades.
|
|
224
|
+
|
|
225
|
+
**How does the `sosmonitor` command work?** With the single-file install on Linux/macOS, `install` links `~/.local/bin/sosmonitor` to the script and adds that folder to `PATH` in your shell startup files. Open a new session or run the `export` line it prints; the full path it prints always works. If a package install already provides the command, `install` marks it `already` and touches nothing. `uninstall` removes only what `install` created. On Windows, create `sosmonitor.cmd` in a folder on your `PATH` with `@py "C:\path\to\sosmonitor.py" %*`.
|
|
226
|
+
|
|
227
|
+
**`pip install` says `externally-managed-environment`.** That is PEP 668 on Debian, Ubuntu, Fedora and most current server images. Use `pipx`, a virtualenv, or `pip install --user --break-system-packages sosmonitor`.
|
|
228
|
+
|
|
229
|
+
**macOS: `crontab: Operation not permitted`.** Give your terminal Full Disk Access (System Settings > Privacy & Security > Full Disk Access), restart it and run `install` again. The config and command are already in place.
|
|
230
|
+
|
|
231
|
+
**My host has no `crontab`, only a cron panel.** `install` marks the schedule `manual`, prints the exact command to paste in the panel and exits 0.
|
|
232
|
+
|
|
233
|
+
**Does it run in Docker?** Not yet. Inside a container `/proc` reports the host's CPU, memory and load, not the container's limits, so the numbers would describe the host. Run it on the host.
|
|
234
|
+
|
|
235
|
+
**Windows, Alpine?** Windows is untested; it should work (`install` prints the `schtasks` commands). Alpine, musl and busybox work with no dependency: everything is read from `/proc`, with no `ps`.
|
|
236
|
+
|
|
237
|
+
**How do I roll back?** Single file: `mv sosmonitor.py.bak sosmonitor.py`. Package: `pipx install --force sosmonitor==VERSION`. Old versions are on the [Releases](https://github.com/diemsouza/sosmonitor/releases) page. The config, log and state stay as they were.
|
|
238
|
+
|
|
239
|
+
## Development
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
python3 -m unittest discover tests
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The tests use only the standard library and never touch your real config.
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# SOSMonitor
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/sosmonitor/)
|
|
4
|
+
[](https://pypi.org/project/sosmonitor/)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
> Sometimes simple is more than enough.
|
|
8
|
+
|
|
9
|
+
A tiny server monitor that watches **CPU, memory, disk, load average and uptime** and tells you when something crosses a limit or the server reboots, by **webhook** (n8n, Make, Zapier, your own endpoint...) and/or **email**.
|
|
10
|
+
|
|
11
|
+
No agent, no paid service, no dashboard, no root. One Python file run by cron. It fits any server that just needs a simple "hey, the disk is at 90%" alert, and it was born on locked-down hosts (Cloudways and similar).
|
|
12
|
+
|
|
13
|
+
One file (`sosmonitor.py`), Python 3.8+ standard library only (`psutil` optional), scheduled in your own crontab, writing only next to its config. One alert per level change, with a margin so a value hovering around a threshold doesn't flood your inbox.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
Pick by what your host lets you do: the **package** if you can install software (EC2, a VPS), the **single file** if you can't (managed hosts).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Package
|
|
21
|
+
sudo apt install pipx # Debian/Ubuntu. Fedora/Amazon Linux: sudo dnf install pipx
|
|
22
|
+
pipx install sosmonitor
|
|
23
|
+
pipx ensurepath && exec $SHELL
|
|
24
|
+
|
|
25
|
+
# Single file (no pip, no root)
|
|
26
|
+
mkdir ~/sosmonitor && cd ~/sosmonitor
|
|
27
|
+
curl -fsSLO https://github.com/diemsouza/sosmonitor/raw/main/sosmonitor.py
|
|
28
|
+
python3 sosmonitor.py install # this first call replaces `sosmonitor install`
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then, either way:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
sosmonitor install # 1. creates the config, schedules cron, creates the command
|
|
35
|
+
sosmonitor config # 2. opens the config: set server_name, webhook and/or email
|
|
36
|
+
sosmonitor test # 3. prints a test alert and sends it to the enabled channels
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`install` is safe to run again and ends with a summary of each step (`created`, `ok`, `already`, `manual` or `failed`). On macOS and Windows, CPU and memory need `psutil`: `pipx install "sosmonitor[psutil]"`.
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
| Command | What it does |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `sosmonitor` (or `run`) | One check. This is what cron calls. Never creates a config |
|
|
46
|
+
| `sosmonitor test` | Prints a test alert, sends it to every enabled channel and shows the result |
|
|
47
|
+
| `sosmonitor config` | Creates the config if missing and opens it in your editor, then checks the JSON |
|
|
48
|
+
| `sosmonitor install` | Creates the config if missing, adds the crontab entry and the `sosmonitor` command (`--no-shortcut` skips the command) |
|
|
49
|
+
| `sosmonitor uninstall` | Removes the crontab entry, the command and its PATH lines |
|
|
50
|
+
| `sosmonitor --version` | Prints the version ([CHANGELOG](CHANGELOG.md)) |
|
|
51
|
+
|
|
52
|
+
Add `-c /path/to.json` to any command to use another config. Before `install` on a single-file download, use `python3 sosmonitor.py ...`.
|
|
53
|
+
|
|
54
|
+
## config.json
|
|
55
|
+
|
|
56
|
+
Created by `install` or `config` (`chmod 600`, since it holds passwords and tokens):
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"server_name": "MY-SERVER",
|
|
61
|
+
"check_interval_minutes": 1,
|
|
62
|
+
"disk_path": "/",
|
|
63
|
+
"send_every_check": true,
|
|
64
|
+
"sustain_checks": 1,
|
|
65
|
+
"thresholds": {
|
|
66
|
+
"70": "{metric} at {value}%",
|
|
67
|
+
"80": "{metric} at {value}% (WARNING)",
|
|
68
|
+
"90": "{metric} at {value}% (CRITICAL)",
|
|
69
|
+
"100": "{metric} at {value}% (AT LIMIT)"
|
|
70
|
+
},
|
|
71
|
+
"recovery_message": "{metric} at {value}% (BACK TO NORMAL)",
|
|
72
|
+
"reboot_message": "{server} restarted (up for {value})",
|
|
73
|
+
"top_processes": { "enabled": true, "count": 3 },
|
|
74
|
+
"webhook": { "enabled": false, "url": "", "token": "", "token_header": "X-Monitor-Token" },
|
|
75
|
+
"email": {
|
|
76
|
+
"enabled": false, "smtp_host": "smtp.gmail.com", "smtp_port": 587,
|
|
77
|
+
"username": "", "password": "", "from": "", "to": ["you@example.com"]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Key | What it does |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| `server_name` | Name shown in alerts and in the email subject |
|
|
85
|
+
| `check_interval_minutes` | How often cron runs the check (used by `install`, 1 to 59) |
|
|
86
|
+
| `disk_path` | Partition to measure (`/`, `/home`, `C:\` ...) |
|
|
87
|
+
| `send_every_check` | `true`: the webhook receives the metrics on every check. `false`: only when there is an alert. Email is only sent for alerts |
|
|
88
|
+
| `sustain_checks` | Consecutive checks a metric must stay at or above a level before alerting. `1` (default) alerts at once; try `3` on noisy servers. Recovery is never delayed |
|
|
89
|
+
| `thresholds` | Levels in % and the message for each. They apply to CPU, memory and disk. Your object **replaces** the default list, so include every level you want |
|
|
90
|
+
| `recovery_message` | Sent when a metric goes back below the lowest level |
|
|
91
|
+
| `reboot_message` | Sent on the first check after the server restarts. `{value}` is the uptime, like `12m` or `3d 4h 12m` |
|
|
92
|
+
| `top_processes` | `enabled` and `count`: list the top CPU or memory consumers, only when that metric alerts |
|
|
93
|
+
| `webhook` | `url` receives a JSON `POST`. `token`, if set, goes in the header named by `token_header` |
|
|
94
|
+
| `email` | SMTP settings. Port 465 uses SSL; other ports use STARTTLS when offered. For Gmail use an [app password](https://myaccount.google.com/apppasswords). `to` is a list |
|
|
95
|
+
|
|
96
|
+
Placeholders: `{server}`, `{metric}` (CPU, Memory, Disk) and `{value}` (rounded %, or the uptime in `reboot_message`). Messages can be in any language. Keys missing from your file use their default.
|
|
97
|
+
|
|
98
|
+
## How alerts work
|
|
99
|
+
|
|
100
|
+
SOSMonitor remembers the last level of each metric (in `sosmonitor_state.json`) and **only alerts when that level changes**:
|
|
101
|
+
|
|
102
|
+
- **Going up is immediate.** 72% is level 70, 85% is level 80.
|
|
103
|
+
- **Going down needs a 5-point margin**, so a value hovering around a threshold doesn't alternate alerts and recoveries.
|
|
104
|
+
- **CPU is an average since the previous check**, which matches your host's graph and ignores a burst from another cron job. The first check after install or a reboot takes a 1-second sample.
|
|
105
|
+
- **Reboots** alert once: the first check after the server restarts says it started and for how long. It never fires on the first run after installing or updating.
|
|
106
|
+
|
|
107
|
+
Example with levels 70 and 80:
|
|
108
|
+
|
|
109
|
+
| Check | Value | Level | Alert |
|
|
110
|
+
| --- | --- | --- | --- |
|
|
111
|
+
| 1 | 65% | 0 | – |
|
|
112
|
+
| 2 | 71% | 70 | **"CPU at 71%"** |
|
|
113
|
+
| 3 | 69% | 70 | – (still within 70 − 5) |
|
|
114
|
+
| 4 | 83% | 80 | **"CPU at 83% (WARNING)"** |
|
|
115
|
+
| 5 | 77% | 80 | – (still within 80 − 5) |
|
|
116
|
+
| 6 | 74% | 70 | **"CPU at 74%"** |
|
|
117
|
+
| 7 | 64% | 0 | **"CPU at 64% (BACK TO NORMAL)"** |
|
|
118
|
+
|
|
119
|
+
Load average and uptime are collected and sent on every check but have no thresholds, so they never alert by themselves.
|
|
120
|
+
|
|
121
|
+
## What is sent
|
|
122
|
+
|
|
123
|
+
Every alert goes to every enabled channel; if all fail, it is retried on the next check. The title shows **only the most severe alert** plus a counter; the body lists them all:
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
[SOSMonitor] MY-SERVER: Memory at 85% (WARNING) (+1 more)
|
|
127
|
+
|
|
128
|
+
Alerts:
|
|
129
|
+
- Memory at 85% (WARNING)
|
|
130
|
+
- CPU at 75%
|
|
131
|
+
|
|
132
|
+
Top processes by memory:
|
|
133
|
+
1. php-fpm 8.2% (1.3 GB)
|
|
134
|
+
2. mysqld 6.1% (1.0 GB)
|
|
135
|
+
|
|
136
|
+
Current metrics:
|
|
137
|
+
CPU 75% | MEMORY 85% | DISK 54% | UPTIME 3d 4h 12m
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Top processes are looked up only when a CPU or memory alert goes out, by command name only, never arguments. If the host hides them, the alert is sent without the list.
|
|
141
|
+
|
|
142
|
+
The webhook receives this JSON:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"server": "MY-SERVER",
|
|
147
|
+
"hostname": "web-01",
|
|
148
|
+
"timestamp": "2026-11-19T20:15:00-03:00",
|
|
149
|
+
"metrics": {
|
|
150
|
+
"cpu": { "percent": 83.0 },
|
|
151
|
+
"memory": { "percent": 61.2, "total_bytes": 4100000000, "available_bytes": 1590000000, "used_bytes": 2510000000 },
|
|
152
|
+
"disk": { "percent": 47.9, "total_bytes": 80000000000, "used_bytes": 38300000000, "free_bytes": 41700000000, "path": "/" },
|
|
153
|
+
"load": { "1m": 1.2, "5m": 0.9, "15m": 0.7, "cpu_count": 2, "1m_per_cpu": 0.6 },
|
|
154
|
+
"uptime": { "seconds": 273120, "boot_time": 1763400000, "boot_id": "5d0f1c2e-3b4a-4c6d-8e7f-0a1b2c3d4e5f" }
|
|
155
|
+
},
|
|
156
|
+
"alerts": [{ "metric": "cpu", "value": 83.0, "threshold": 80, "previous_threshold": 70,
|
|
157
|
+
"message": "CPU at 83% (WARNING)" }],
|
|
158
|
+
"top_processes": [{ "metric": "cpu", "name": "php-fpm", "percent": 62.5 }],
|
|
159
|
+
"message_title": "[SOSMonitor] MY-SERVER: CPU at 83% (WARNING)",
|
|
160
|
+
"message_body": "Server: MY-SERVER\n..."
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
- `message_title` and `message_body` are the email subject and body, ready to forward to WhatsApp, Telegram or Slack. Without alerts, `alerts` is empty and both are `""`, so in n8n you can filter on `message_title != ""`.
|
|
165
|
+
- `top_processes` is a flat list with a `metric` (`cpu` or `memory`) on each item, present only when there is something to report. Memory items also have `rss_bytes`.
|
|
166
|
+
- A reboot is an alert with `"metric": "reboot"` and `"threshold": 0`; its `value` is the uptime in seconds. `uptime` has no threshold. `boot_id` is `null` where the OS has none.
|
|
167
|
+
- The `test` command fills the message fields and adds `"test": true`.
|
|
168
|
+
|
|
169
|
+
## Platforms
|
|
170
|
+
|
|
171
|
+
| | CPU / memory | Disk / load | Uptime / reboot alert | Scheduling | Dependencies |
|
|
172
|
+
| --- | --- | --- | --- | --- | --- |
|
|
173
|
+
| **Linux** | Native (`/proc`) | Native | Native | User crontab | None |
|
|
174
|
+
| **macOS** | Needs `psutil` | Native | Needs `psutil` | User crontab | `pipx install "sosmonitor[psutil]"` |
|
|
175
|
+
| **Windows** | Needs `psutil` | Disk native, load via `psutil` | Needs `psutil` | Task Scheduler (`install` prints the `schtasks` command) | `pipx install "sosmonitor[psutil]"` |
|
|
176
|
+
|
|
177
|
+
Without `psutil`, the metrics it provides are skipped and nothing breaks.
|
|
178
|
+
|
|
179
|
+
## Files created (always next to the config in use)
|
|
180
|
+
|
|
181
|
+
| File | Content |
|
|
182
|
+
| --- | --- |
|
|
183
|
+
| `sosmonitor.log` | One JSON line per check (metrics, alerts, delivery result). Rotates to `.log.1` at 5 MB |
|
|
184
|
+
| `sosmonitor_state.json` | Last level of each metric, the `sustain_checks` counters, the CPU counters for the next average and the last seen boot (id and time) |
|
|
185
|
+
| `.sosmonitor.lock` | Prevents two checks from running at the same time |
|
|
186
|
+
|
|
187
|
+
## Updating
|
|
188
|
+
|
|
189
|
+
Package: `pipx upgrade sosmonitor`. Single file: back up and re-download it (`cp sosmonitor.py sosmonitor.py.bak`, then the same `curl -fsSLO` as above). Then run `sosmonitor --version && sosmonitor test`.
|
|
190
|
+
|
|
191
|
+
Your config, log and state are never touched. Read the [CHANGELOG](CHANGELOG.md) for the versions in between: each entry has a "Config changes" line. New keys work from their default; to use one, add it by hand (`config.example.json` is the reference).
|
|
192
|
+
|
|
193
|
+
## FAQ
|
|
194
|
+
|
|
195
|
+
**Where does the config live?** Order: `-c file`, then a `config.json` next to `sosmonitor.py` if one already exists (existing installs keep working), otherwise `~/.config/sosmonitor/config.json` (`$XDG_CONFIG_HOME`, or `%APPDATA%\SOSMonitor` on Windows). The log, state and lock always live next to the config in use. Existing files are never moved or copied, and the user folder survives package upgrades.
|
|
196
|
+
|
|
197
|
+
**How does the `sosmonitor` command work?** With the single-file install on Linux/macOS, `install` links `~/.local/bin/sosmonitor` to the script and adds that folder to `PATH` in your shell startup files. Open a new session or run the `export` line it prints; the full path it prints always works. If a package install already provides the command, `install` marks it `already` and touches nothing. `uninstall` removes only what `install` created. On Windows, create `sosmonitor.cmd` in a folder on your `PATH` with `@py "C:\path\to\sosmonitor.py" %*`.
|
|
198
|
+
|
|
199
|
+
**`pip install` says `externally-managed-environment`.** That is PEP 668 on Debian, Ubuntu, Fedora and most current server images. Use `pipx`, a virtualenv, or `pip install --user --break-system-packages sosmonitor`.
|
|
200
|
+
|
|
201
|
+
**macOS: `crontab: Operation not permitted`.** Give your terminal Full Disk Access (System Settings > Privacy & Security > Full Disk Access), restart it and run `install` again. The config and command are already in place.
|
|
202
|
+
|
|
203
|
+
**My host has no `crontab`, only a cron panel.** `install` marks the schedule `manual`, prints the exact command to paste in the panel and exits 0.
|
|
204
|
+
|
|
205
|
+
**Does it run in Docker?** Not yet. Inside a container `/proc` reports the host's CPU, memory and load, not the container's limits, so the numbers would describe the host. Run it on the host.
|
|
206
|
+
|
|
207
|
+
**Windows, Alpine?** Windows is untested; it should work (`install` prints the `schtasks` commands). Alpine, musl and busybox work with no dependency: everything is read from `/proc`, with no `ps`.
|
|
208
|
+
|
|
209
|
+
**How do I roll back?** Single file: `mv sosmonitor.py.bak sosmonitor.py`. Package: `pipx install --force sosmonitor==VERSION`. Old versions are on the [Releases](https://github.com/diemsouza/sosmonitor/releases) page. The config, log and state stay as they were.
|
|
210
|
+
|
|
211
|
+
## Development
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
python3 -m unittest discover tests
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The tests use only the standard library and never touch your real config.
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
|
|
221
|
+
[MIT](LICENSE)
|