30secs 0.2.6__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.
- 30secs-0.2.6/PKG-INFO +330 -0
- 30secs-0.2.6/README.md +305 -0
- 30secs-0.2.6/pyproject.toml +103 -0
- 30secs-0.2.6/src/thirtysecs/__init__.py +17 -0
- 30secs-0.2.6/src/thirtysecs/__main__.py +6 -0
- 30secs-0.2.6/src/thirtysecs/alerts.py +222 -0
- 30secs-0.2.6/src/thirtysecs/cli.py +623 -0
- 30secs-0.2.6/src/thirtysecs/collectors/__init__.py +21 -0
- 30secs-0.2.6/src/thirtysecs/collectors/base.py +21 -0
- 30secs-0.2.6/src/thirtysecs/collectors/cpu.py +64 -0
- 30secs-0.2.6/src/thirtysecs/collectors/disk.py +70 -0
- 30secs-0.2.6/src/thirtysecs/collectors/memory.py +51 -0
- 30secs-0.2.6/src/thirtysecs/collectors/network.py +83 -0
- 30secs-0.2.6/src/thirtysecs/collectors/process.py +205 -0
- 30secs-0.2.6/src/thirtysecs/collectors/system.py +74 -0
- 30secs-0.2.6/src/thirtysecs/config.py +69 -0
- 30secs-0.2.6/src/thirtysecs/core.py +65 -0
- 30secs-0.2.6/src/thirtysecs/errors.py +18 -0
- 30secs-0.2.6/src/thirtysecs/formatters/__init__.py +30 -0
- 30secs-0.2.6/src/thirtysecs/formatters/base.py +15 -0
- 30secs-0.2.6/src/thirtysecs/formatters/json_fmt.py +15 -0
- 30secs-0.2.6/src/thirtysecs/formatters/prometheus.py +125 -0
- 30secs-0.2.6/src/thirtysecs/formatters/table.py +108 -0
- 30secs-0.2.6/src/thirtysecs/handler.py +112 -0
- 30secs-0.2.6/src/thirtysecs/http.py +47 -0
- 30secs-0.2.6/src/thirtysecs/leak_report.py +147 -0
- 30secs-0.2.6/src/thirtysecs/logging.py +54 -0
- 30secs-0.2.6/src/thirtysecs/metrics.py +19 -0
- 30secs-0.2.6/src/thirtysecs/py.typed +0 -0
30secs-0.2.6/PKG-INFO
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: 30secs
|
|
3
|
+
Version: 0.2.6
|
|
4
|
+
Summary: Collect and expose lightweight system snapshots (CLI).
|
|
5
|
+
Keywords: monitoring,system,metrics,cli,devops,kubernetes,debugging
|
|
6
|
+
Author: jundorok
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: System :: Monitoring
|
|
17
|
+
Classifier: Topic :: System :: Systems Administration
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Dist: psutil>=5.9.8
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Project-URL: Homepage, https://github.com/jundorok/30secs
|
|
22
|
+
Project-URL: Repository, https://github.com/jundorok/30secs
|
|
23
|
+
Project-URL: Issues, https://github.com/jundorok/30secs/issues
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# 30secs
|
|
27
|
+
|
|
28
|
+
`30secs` is an ultra-lightweight system monitoring tool that **takes system snapshots every 30 seconds (default)**, or returns snapshots on-demand via **CLI**.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **Real-time monitoring**: CPU, memory, disk, network, and process metrics
|
|
33
|
+
- **Multiple output formats**: JSON, human-readable table, Prometheus metrics
|
|
34
|
+
- **Alert system**: Configurable threshold-based alerts
|
|
35
|
+
- **Graceful shutdown**: Handles SIGINT/SIGTERM signals
|
|
36
|
+
- **Production-ready**: Structured logging, error handling, modular architecture
|
|
37
|
+
|
|
38
|
+
> ⚠️ Python module names cannot start with a number, so while the project is named `30secs`, the import package is `thirtysecs`.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
### Binary (No Python Required) - Recommended for K8s Nodes
|
|
45
|
+
|
|
46
|
+
Download the pre-built binary for your platform:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Linux AMD64 (most K8s nodes)
|
|
50
|
+
curl -L https://github.com/<your-repo>/30secs/releases/latest/download/30secs-linux-amd64 -o 30secs
|
|
51
|
+
|
|
52
|
+
# Linux ARM64 (Graviton, etc.)
|
|
53
|
+
curl -L https://github.com/<your-repo>/30secs/releases/latest/download/30secs-linux-arm64 -o 30secs
|
|
54
|
+
|
|
55
|
+
# macOS Apple Silicon
|
|
56
|
+
curl -L https://github.com/<your-repo>/30secs/releases/latest/download/30secs-darwin-arm64 -o 30secs
|
|
57
|
+
|
|
58
|
+
# macOS Intel
|
|
59
|
+
curl -L https://github.com/<your-repo>/30secs/releases/latest/download/30secs-darwin-amd64 -o 30secs
|
|
60
|
+
|
|
61
|
+
# Make executable and run
|
|
62
|
+
chmod +x 30secs
|
|
63
|
+
./30secs watch -f table --alerts
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### One-liner for K8s Node Debugging
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
curl -sL https://github.com/<your-repo>/30secs/releases/latest/download/30secs-linux-amd64 -o /tmp/30secs \
|
|
70
|
+
&& chmod +x /tmp/30secs \
|
|
71
|
+
&& /tmp/30secs watch -f table --alerts -i 10
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### pip (PyPI) - Recommended for environments without GitHub access
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Install from PyPI (Python 3.12+ required)
|
|
78
|
+
pip install 30secs
|
|
79
|
+
|
|
80
|
+
# Or use pipx for isolated install
|
|
81
|
+
pipx install 30secs
|
|
82
|
+
|
|
83
|
+
# Or use uv
|
|
84
|
+
uv tool install 30secs
|
|
85
|
+
|
|
86
|
+
# Then run
|
|
87
|
+
30secs watch -f table --alerts -i 10
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### One-liner for K8s Node (pip)
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install 30secs && 30secs watch -f table --alerts -i 10
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### From Source (uv)
|
|
97
|
+
|
|
98
|
+
#### Install uv (official docs)
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Install/sync dependencies
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
uv sync
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Usage
|
|
113
|
+
|
|
114
|
+
### Single snapshot (JSON output)
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
uv run 30secs snapshot
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Human-readable table output
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
uv run 30secs snapshot --format table
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Prometheus metrics format
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
uv run 30secs snapshot --format prometheus
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Continuous monitoring (every 30 seconds)
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
uv run 30secs watch
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Custom interval (every 10 seconds)
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
uv run 30secs watch --interval 10
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Watch with table format (auto-refresh)
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
uv run 30secs watch --format table --interval 5
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Quick snapshot (without processes - faster)
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
uv run 30secs quick
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Enable alerts
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
uv run 30secs watch --alerts
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Save output to file
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
uv run 30secs watch --output metrics.jsonl
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Limit number of snapshots
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
uv run 30secs watch --count 10 --interval 5
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Exclude specific metrics
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
uv run 30secs snapshot --no-processes --no-network
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Memory leak report for a process (table)
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
uv run 30secs leak <PID> --interval 2 --count 30
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Memory leak report as JSON
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
uv run 30secs leak <PID> --format json --interval 1 --count 60
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Output Formats
|
|
195
|
+
|
|
196
|
+
### JSON (default)
|
|
197
|
+
|
|
198
|
+
Complete system metrics in JSON format, suitable for log aggregation and processing.
|
|
199
|
+
|
|
200
|
+
### Table
|
|
201
|
+
|
|
202
|
+
Human-readable format with emojis and organized sections:
|
|
203
|
+
- System info (hostname, OS, uptime)
|
|
204
|
+
- CPU (usage, cores, load average)
|
|
205
|
+
- Memory (used/total, available, swap)
|
|
206
|
+
- Disk (partitions, usage)
|
|
207
|
+
- Network (sent/received, connections)
|
|
208
|
+
- Processes (top by CPU/memory)
|
|
209
|
+
|
|
210
|
+
### Prometheus
|
|
211
|
+
|
|
212
|
+
Metrics in Prometheus exposition format, ready for scraping.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Alerts
|
|
217
|
+
|
|
218
|
+
Built-in alert thresholds:
|
|
219
|
+
- **CPU**: > 90%
|
|
220
|
+
- **Memory**: > 90%, > 95% (critical)
|
|
221
|
+
- **Swap**: > 80%
|
|
222
|
+
|
|
223
|
+
When alerts are enabled (`--alerts`), the tool will:
|
|
224
|
+
- Log warnings when thresholds are exceeded
|
|
225
|
+
- Exit with code 1 if any alert is triggered (for `snapshot` command)
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Development
|
|
230
|
+
|
|
231
|
+
### Run tests
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
uv run pytest
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Linting & Formatting
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
uv run ruff check .
|
|
241
|
+
uv run ruff format .
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Type checking
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
uv run mypy src
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Project Structure
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
src/thirtysecs/
|
|
256
|
+
├── __init__.py # Package init
|
|
257
|
+
├── __main__.py # Entry point
|
|
258
|
+
├── cli.py # CLI interface
|
|
259
|
+
├── config.py # Configuration
|
|
260
|
+
├── core.py # Core snapshot logic
|
|
261
|
+
├── alerts.py # Alert system
|
|
262
|
+
├── errors.py # Error definitions
|
|
263
|
+
├── logging.py # Structured logging
|
|
264
|
+
├── collectors/ # Metric collectors
|
|
265
|
+
│ ├── base.py # Base collector interface
|
|
266
|
+
│ ├── cpu.py # CPU metrics
|
|
267
|
+
│ ├── memory.py # Memory metrics
|
|
268
|
+
│ ├── disk.py # Disk metrics
|
|
269
|
+
│ ├── network.py # Network metrics
|
|
270
|
+
│ ├── process.py # Process metrics
|
|
271
|
+
│ └── system.py # System info
|
|
272
|
+
└── formatters/ # Output formatters
|
|
273
|
+
├── base.py # Base formatter interface
|
|
274
|
+
├── json_fmt.py # JSON output
|
|
275
|
+
├── table.py # Table output
|
|
276
|
+
└── prometheus.py # Prometheus metrics
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Environment Variables
|
|
282
|
+
|
|
283
|
+
| Variable | Default | Description |
|
|
284
|
+
|----------|---------|-------------|
|
|
285
|
+
| `SERVICE_NAME` | `30secs` | Service name for health checks |
|
|
286
|
+
| `DEFAULT_INTERVAL_SECONDS` | `30` | Default watch interval |
|
|
287
|
+
| `INCLUDE_HOSTNAME` | `1` | Include hostname in output |
|
|
288
|
+
| `LOG_LEVEL` | `INFO` | Logging level |
|
|
289
|
+
| `ALERT_CPU_THRESHOLD` | `90.0` | CPU usage alert threshold (%) |
|
|
290
|
+
| `ALERT_MEMORY_THRESHOLD` | `90.0` | Memory usage alert threshold (%) |
|
|
291
|
+
| `ALERT_MEMORY_CRITICAL_THRESHOLD` | `95.0` | Critical memory alert threshold (%) |
|
|
292
|
+
| `ALERT_SWAP_THRESHOLD` | `80.0` | Swap usage alert threshold (%) |
|
|
293
|
+
| `MEMORY_LEAK_WINDOW_SIZE` | `10` | Number of samples for leak detection |
|
|
294
|
+
| `MEMORY_LEAK_GROWTH_THRESHOLD` | `5.0` | Memory growth % to trigger leak alert |
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## Memory Leak Detection
|
|
299
|
+
|
|
300
|
+
30secs includes automatic memory leak detection when using `--alerts`:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
# Monitor with leak detection (default: 10 samples, 5% growth threshold)
|
|
304
|
+
30secs watch -f table --alerts -i 10
|
|
305
|
+
|
|
306
|
+
# Custom thresholds via environment variables
|
|
307
|
+
MEMORY_LEAK_WINDOW_SIZE=20 MEMORY_LEAK_GROWTH_THRESHOLD=3.0 30secs watch --alerts -i 5
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
The detector tracks memory usage over a sliding window and alerts when:
|
|
311
|
+
- Memory growth exceeds the threshold (default: 5%)
|
|
312
|
+
- At least 60% of samples show an increasing trend
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## uv Cheat Sheet
|
|
317
|
+
|
|
318
|
+
| Command | Description |
|
|
319
|
+
|---------|-------------|
|
|
320
|
+
| `uv add <pkg>` | Add a dependency |
|
|
321
|
+
| `uv add --group dev <pkg>` | Add a dev dependency |
|
|
322
|
+
| `uv lock` | Lock dependencies |
|
|
323
|
+
| `uv sync` | Sync dependencies |
|
|
324
|
+
| `uv run --frozen ...` | Run with locked dependencies |
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
MIT
|
30secs-0.2.6/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# 30secs
|
|
2
|
+
|
|
3
|
+
`30secs` is an ultra-lightweight system monitoring tool that **takes system snapshots every 30 seconds (default)**, or returns snapshots on-demand via **CLI**.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Real-time monitoring**: CPU, memory, disk, network, and process metrics
|
|
8
|
+
- **Multiple output formats**: JSON, human-readable table, Prometheus metrics
|
|
9
|
+
- **Alert system**: Configurable threshold-based alerts
|
|
10
|
+
- **Graceful shutdown**: Handles SIGINT/SIGTERM signals
|
|
11
|
+
- **Production-ready**: Structured logging, error handling, modular architecture
|
|
12
|
+
|
|
13
|
+
> ⚠️ Python module names cannot start with a number, so while the project is named `30secs`, the import package is `thirtysecs`.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Binary (No Python Required) - Recommended for K8s Nodes
|
|
20
|
+
|
|
21
|
+
Download the pre-built binary for your platform:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Linux AMD64 (most K8s nodes)
|
|
25
|
+
curl -L https://github.com/<your-repo>/30secs/releases/latest/download/30secs-linux-amd64 -o 30secs
|
|
26
|
+
|
|
27
|
+
# Linux ARM64 (Graviton, etc.)
|
|
28
|
+
curl -L https://github.com/<your-repo>/30secs/releases/latest/download/30secs-linux-arm64 -o 30secs
|
|
29
|
+
|
|
30
|
+
# macOS Apple Silicon
|
|
31
|
+
curl -L https://github.com/<your-repo>/30secs/releases/latest/download/30secs-darwin-arm64 -o 30secs
|
|
32
|
+
|
|
33
|
+
# macOS Intel
|
|
34
|
+
curl -L https://github.com/<your-repo>/30secs/releases/latest/download/30secs-darwin-amd64 -o 30secs
|
|
35
|
+
|
|
36
|
+
# Make executable and run
|
|
37
|
+
chmod +x 30secs
|
|
38
|
+
./30secs watch -f table --alerts
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### One-liner for K8s Node Debugging
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
curl -sL https://github.com/<your-repo>/30secs/releases/latest/download/30secs-linux-amd64 -o /tmp/30secs \
|
|
45
|
+
&& chmod +x /tmp/30secs \
|
|
46
|
+
&& /tmp/30secs watch -f table --alerts -i 10
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### pip (PyPI) - Recommended for environments without GitHub access
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Install from PyPI (Python 3.12+ required)
|
|
53
|
+
pip install 30secs
|
|
54
|
+
|
|
55
|
+
# Or use pipx for isolated install
|
|
56
|
+
pipx install 30secs
|
|
57
|
+
|
|
58
|
+
# Or use uv
|
|
59
|
+
uv tool install 30secs
|
|
60
|
+
|
|
61
|
+
# Then run
|
|
62
|
+
30secs watch -f table --alerts -i 10
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### One-liner for K8s Node (pip)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install 30secs && 30secs watch -f table --alerts -i 10
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### From Source (uv)
|
|
72
|
+
|
|
73
|
+
#### Install uv (official docs)
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### Install/sync dependencies
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
uv sync
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Usage
|
|
88
|
+
|
|
89
|
+
### Single snapshot (JSON output)
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
uv run 30secs snapshot
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Human-readable table output
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
uv run 30secs snapshot --format table
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Prometheus metrics format
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
uv run 30secs snapshot --format prometheus
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Continuous monitoring (every 30 seconds)
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
uv run 30secs watch
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Custom interval (every 10 seconds)
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
uv run 30secs watch --interval 10
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Watch with table format (auto-refresh)
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
uv run 30secs watch --format table --interval 5
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Quick snapshot (without processes - faster)
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
uv run 30secs quick
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Enable alerts
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
uv run 30secs watch --alerts
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Save output to file
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
uv run 30secs watch --output metrics.jsonl
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Limit number of snapshots
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
uv run 30secs watch --count 10 --interval 5
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Exclude specific metrics
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
uv run 30secs snapshot --no-processes --no-network
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Memory leak report for a process (table)
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
uv run 30secs leak <PID> --interval 2 --count 30
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Memory leak report as JSON
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
uv run 30secs leak <PID> --format json --interval 1 --count 60
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Output Formats
|
|
170
|
+
|
|
171
|
+
### JSON (default)
|
|
172
|
+
|
|
173
|
+
Complete system metrics in JSON format, suitable for log aggregation and processing.
|
|
174
|
+
|
|
175
|
+
### Table
|
|
176
|
+
|
|
177
|
+
Human-readable format with emojis and organized sections:
|
|
178
|
+
- System info (hostname, OS, uptime)
|
|
179
|
+
- CPU (usage, cores, load average)
|
|
180
|
+
- Memory (used/total, available, swap)
|
|
181
|
+
- Disk (partitions, usage)
|
|
182
|
+
- Network (sent/received, connections)
|
|
183
|
+
- Processes (top by CPU/memory)
|
|
184
|
+
|
|
185
|
+
### Prometheus
|
|
186
|
+
|
|
187
|
+
Metrics in Prometheus exposition format, ready for scraping.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Alerts
|
|
192
|
+
|
|
193
|
+
Built-in alert thresholds:
|
|
194
|
+
- **CPU**: > 90%
|
|
195
|
+
- **Memory**: > 90%, > 95% (critical)
|
|
196
|
+
- **Swap**: > 80%
|
|
197
|
+
|
|
198
|
+
When alerts are enabled (`--alerts`), the tool will:
|
|
199
|
+
- Log warnings when thresholds are exceeded
|
|
200
|
+
- Exit with code 1 if any alert is triggered (for `snapshot` command)
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Development
|
|
205
|
+
|
|
206
|
+
### Run tests
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
uv run pytest
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Linting & Formatting
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
uv run ruff check .
|
|
216
|
+
uv run ruff format .
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Type checking
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
uv run mypy src
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
## Project Structure
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
src/thirtysecs/
|
|
231
|
+
├── __init__.py # Package init
|
|
232
|
+
├── __main__.py # Entry point
|
|
233
|
+
├── cli.py # CLI interface
|
|
234
|
+
├── config.py # Configuration
|
|
235
|
+
├── core.py # Core snapshot logic
|
|
236
|
+
├── alerts.py # Alert system
|
|
237
|
+
├── errors.py # Error definitions
|
|
238
|
+
├── logging.py # Structured logging
|
|
239
|
+
├── collectors/ # Metric collectors
|
|
240
|
+
│ ├── base.py # Base collector interface
|
|
241
|
+
│ ├── cpu.py # CPU metrics
|
|
242
|
+
│ ├── memory.py # Memory metrics
|
|
243
|
+
│ ├── disk.py # Disk metrics
|
|
244
|
+
│ ├── network.py # Network metrics
|
|
245
|
+
│ ├── process.py # Process metrics
|
|
246
|
+
│ └── system.py # System info
|
|
247
|
+
└── formatters/ # Output formatters
|
|
248
|
+
├── base.py # Base formatter interface
|
|
249
|
+
├── json_fmt.py # JSON output
|
|
250
|
+
├── table.py # Table output
|
|
251
|
+
└── prometheus.py # Prometheus metrics
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Environment Variables
|
|
257
|
+
|
|
258
|
+
| Variable | Default | Description |
|
|
259
|
+
|----------|---------|-------------|
|
|
260
|
+
| `SERVICE_NAME` | `30secs` | Service name for health checks |
|
|
261
|
+
| `DEFAULT_INTERVAL_SECONDS` | `30` | Default watch interval |
|
|
262
|
+
| `INCLUDE_HOSTNAME` | `1` | Include hostname in output |
|
|
263
|
+
| `LOG_LEVEL` | `INFO` | Logging level |
|
|
264
|
+
| `ALERT_CPU_THRESHOLD` | `90.0` | CPU usage alert threshold (%) |
|
|
265
|
+
| `ALERT_MEMORY_THRESHOLD` | `90.0` | Memory usage alert threshold (%) |
|
|
266
|
+
| `ALERT_MEMORY_CRITICAL_THRESHOLD` | `95.0` | Critical memory alert threshold (%) |
|
|
267
|
+
| `ALERT_SWAP_THRESHOLD` | `80.0` | Swap usage alert threshold (%) |
|
|
268
|
+
| `MEMORY_LEAK_WINDOW_SIZE` | `10` | Number of samples for leak detection |
|
|
269
|
+
| `MEMORY_LEAK_GROWTH_THRESHOLD` | `5.0` | Memory growth % to trigger leak alert |
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Memory Leak Detection
|
|
274
|
+
|
|
275
|
+
30secs includes automatic memory leak detection when using `--alerts`:
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
# Monitor with leak detection (default: 10 samples, 5% growth threshold)
|
|
279
|
+
30secs watch -f table --alerts -i 10
|
|
280
|
+
|
|
281
|
+
# Custom thresholds via environment variables
|
|
282
|
+
MEMORY_LEAK_WINDOW_SIZE=20 MEMORY_LEAK_GROWTH_THRESHOLD=3.0 30secs watch --alerts -i 5
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
The detector tracks memory usage over a sliding window and alerts when:
|
|
286
|
+
- Memory growth exceeds the threshold (default: 5%)
|
|
287
|
+
- At least 60% of samples show an increasing trend
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## uv Cheat Sheet
|
|
292
|
+
|
|
293
|
+
| Command | Description |
|
|
294
|
+
|---------|-------------|
|
|
295
|
+
| `uv add <pkg>` | Add a dependency |
|
|
296
|
+
| `uv add --group dev <pkg>` | Add a dev dependency |
|
|
297
|
+
| `uv lock` | Lock dependencies |
|
|
298
|
+
| `uv sync` | Sync dependencies |
|
|
299
|
+
| `uv run --frozen ...` | Run with locked dependencies |
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## License
|
|
304
|
+
|
|
305
|
+
MIT
|