Directory Structure
.monitors/
├── config.json # Global settings (alert defaults, retention)
├── monitors/ # One script per monitor
│ ├── web-mysite.sh
│ ├── twitter-elonmusk.py
│ └── api-stripe-health.sh
├── logs/ # Structured logs per monitor
│ ├── web-mysite/
│ │ └── 2024-03.jsonl
│ └── twitter-elonmusk/
│ └── 2024-03.jsonl
└── alerts/ # Alert history
└── 2024-03.jsonl
Monitor Scripts
- Each monitor is a standalone script (bash, python, node) in
.monitors/monitors/
- Script must exit 0 for success, non-zero for failure
- Script outputs JSON to stdout:
{"status": "ok|warn|fail", "value": any, "message": "human readable"}
- Keep scripts simple and fast — they run on schedule, not continuously
- Name pattern:
{type}-{target}.{ext} (e.g., web-api-prod.sh, content-competitor-blog.py)
Log Format
- One JSONL file per monitor per month:
logs/{monitor-name}/YYYY-MM.jsonl
- Entry:
{"ts": "ISO8601", "status": "ok|warn|fail", "value": ..., "latency_ms": N, "message": "..."}
- Append-only — never modify past entries
- Retention: keep 12 months by default, configurable in config.json
Creating Monitors
When user requests monitoring, create appropriate script:
Web uptime: curl with timeout, check status code
#!/bin/bash
START=$(date +%s%3N)
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$URL")
LATENCY=$(($(date +%s%3N) - START))
if [ "$STATUS" = "200" ]; then
echo "{\"status\":\"ok\",\"value\":$STATUS,\"latency_ms\":$LATENCY}"
else
echo "{\"status\":\"fail\",\"value\":$STATUS,\"message\":\"HTTP $STATUS\"}"
exit 1
fi
Content changes: hash page content, compare to last
API health: call endpoint, validate response schema
Social media: fetch latest posts, check for new content
Custom metrics: run any command, parse output
Running Monitors
- Monitors run via cron or scheduled task — agent sets up schedule on user request
- Suggested intervals: critical (1m), important (5m), standard (15m), daily (24h)
- Runner script reads all monitors, executes each, appends to logs, triggers alerts
- Log runner output:
logs/runner.log for debugging schedule issues
Alert Configuration
Store in config.json:
{
"alerts": {
"default": {"type": "log"},
"channels": {
"pushover": {"token": "...", "user": "..."},
"agent": {"enabled": true},
"webhook": {"url": "..."}
}
},
"monitors": {
"web-mysite": {"alert": ["pushover", "agent"], "interval": "5m"}
}
}
Alert types:
- log: Write to alerts/YYYY-MM.jsonl only
- agent: Flag for agent to mention in next conversation
- pushover/ntfy: Push notification
- webhook: POST to URL
- email: Send via configured SMTP
Alert Logic
- Alert on status change (ok→fail, fail→ok) — avoid spam on repeated failures
- Include consecutive failure count in alert
- Recovery alerts: "Monitor X back to OK after 3 failures (12 minutes)"
- Configurable thresholds: alert only after N consecutive failures
Insights (Agent Analysis)
When user asks about monitoring:
- Parse recent logs, calculate uptime percentage
- Identify patterns: "Site slower on weekends", "API fails every Monday 9am"
- Suggest new monitors based on what user cares about
- Generate weekly summary if requested: uptime stats, incidents, trends
Efficient Patterns
- Don't store full response bodies — only status, latency, relevant extracted values
- For content monitoring, store hash + diff summary, not full content
- Compress logs older than 30 days if storage is concern
- Index by status for quick "show all failures" queries
1---2name: monitor3description: Create flexible monitoring scripts with structured logs, alerts, and intelligent insights for any target.4---56## Directory Structure78```9.monitors/10├── config.json # Global settings (alert defaults, retention)11├── monitors/ # One script per monitor12│ ├── web-mysite.sh13│ ├── twitter-elonmusk.py14│ └── api-stripe-health.sh15├── logs/ # Structured logs per monitor16│ ├── web-mysite/17│ │ └── 2024-03.jsonl18│ └── twitter-elonmusk/19│ └── 2024-03.jsonl20└── alerts/ # Alert history21 └── 2024-03.jsonl22```2324## Monitor Scripts2526- Each monitor is a standalone script (bash, python, node) in `.monitors/monitors/`27- Script must exit 0 for success, non-zero for failure28- Script outputs JSON to stdout: `{"status": "ok|warn|fail", "value": any, "message": "human readable"}`29- Keep scripts simple and fast — they run on schedule, not continuously30- Name pattern: `{type}-{target}.{ext}` (e.g., `web-api-prod.sh`, `content-competitor-blog.py`)3132## Log Format3334- One JSONL file per monitor per month: `logs/{monitor-name}/YYYY-MM.jsonl`35- Entry: `{"ts": "ISO8601", "status": "ok|warn|fail", "value": ..., "latency_ms": N, "message": "..."}`36- Append-only — never modify past entries37- Retention: keep 12 months by default, configurable in config.json3839## Creating Monitors4041When user requests monitoring, create appropriate script:4243**Web uptime**: curl with timeout, check status code44```bash45#!/bin/bash46START=$(date +%s%3N)47STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$URL")48LATENCY=$(($(date +%s%3N) - START))49if [ "$STATUS" = "200" ]; then50 echo "{\"status\":\"ok\",\"value\":$STATUS,\"latency_ms\":$LATENCY}"51else52 echo "{\"status\":\"fail\",\"value\":$STATUS,\"message\":\"HTTP $STATUS\"}"53 exit 154fi55```5657**Content changes**: hash page content, compare to last58**API health**: call endpoint, validate response schema59**Social media**: fetch latest posts, check for new content60**Custom metrics**: run any command, parse output6162## Running Monitors6364- Monitors run via cron or scheduled task — agent sets up schedule on user request65- Suggested intervals: critical (1m), important (5m), standard (15m), daily (24h)66- Runner script reads all monitors, executes each, appends to logs, triggers alerts67- Log runner output: `logs/runner.log` for debugging schedule issues6869## Alert Configuration7071Store in `config.json`:72```json73{74 "alerts": {75 "default": {"type": "log"},76 "channels": {77 "pushover": {"token": "...", "user": "..."},78 "agent": {"enabled": true},79 "webhook": {"url": "..."}80 }81 },82 "monitors": {83 "web-mysite": {"alert": ["pushover", "agent"], "interval": "5m"}84 }85}86```8788Alert types:89- **log**: Write to alerts/YYYY-MM.jsonl only90- **agent**: Flag for agent to mention in next conversation91- **pushover/ntfy**: Push notification92- **webhook**: POST to URL93- **email**: Send via configured SMTP9495## Alert Logic9697- Alert on status change (ok→fail, fail→ok) — avoid spam on repeated failures98- Include consecutive failure count in alert99- Recovery alerts: "Monitor X back to OK after 3 failures (12 minutes)"100- Configurable thresholds: alert only after N consecutive failures101102## Insights (Agent Analysis)103104When user asks about monitoring:105- Parse recent logs, calculate uptime percentage106- Identify patterns: "Site slower on weekends", "API fails every Monday 9am"107- Suggest new monitors based on what user cares about108- Generate weekly summary if requested: uptime stats, incidents, trends109110## Efficient Patterns111112- Don't store full response bodies — only status, latency, relevant extracted values113- For content monitoring, store hash + diff summary, not full content114- Compress logs older than 30 days if storage is concern115- Index by status for quick "show all failures" queries