How It Works
Architecture
Spyd runs as a background daemon that continuously monitors your server, detects anomalies, and provides AI-powered diagnosis when things go wrong.
Metrics
Collector
Logs
Watcher
Baselines
Learner
▼
Anomaly Detector
▼
AI Investigator
(Claude / GPT-4)
▼
Alert Manager
▼
Email
Slack
Telegram
Discord
Desktop
What Spyd Monitors
System Metrics
Collected every 60 seconds (configurable):
CPU
Overall %, per-core breakdown
Memory
RAM usage, swap usage
Load
1m, 5m, 15m averages
Processes
Top 20 by CPU with full command
Log Monitoring
Real-time pattern matching on configured log files:
Error Patterns:
ERROR, FATAL, CRITICAL, Exception, panic
Security Patterns:
authentication failed, permission denied, unauthorized
Performance Patterns:
timeout, slow query, out of memory, OOM
Anomaly Detection
Spyd uses three complementary detection methods to catch issues:
1. Threshold Detection
Simple, fast checks against configured limits:
CPU > 80% → Warning
Memory > 85% → Warning
Disk > 90% → Warning
Any > 95% → Critical
2. Statistical Detection (Baseline Learning)
Learns what's "normal" for YOUR server over ~7 days, then flags deviations:
Mean: 30% | StdDev: 5%
Z-score = (60 - 30) / 5 = 6.0
Z-score > 3.0 → Anomaly!
3. Log Pattern Detection
Real-time matching triggers immediate anomalies:
"sshd: Failed password for root from 192.168.1.100"
↓
Matches: "Failed password"
↓
Security anomaly created → Alert sent
AI Diagnosis
When an anomaly is detected, Spyd gathers context and consults AI for root cause analysis:
Context Provided to AI
Anomaly Details
Type, metric, actual vs threshold, severity
System State
Current CPU, memory, disk, load snapshot
Top Processes
PID, name, CPU%, memory%, user, full command
Correlation Hints
High CPU + High Load = CPU-bound, etc.
Process Patterns
Fork bombs, single dominators, suspicious users
Recent Logs
Matched error/security events
AI Capabilities
The AI is configured as an L3+ Senior SysAdmin who:
1. Recognizes attack signatures (crypto miners, DDoS, brute force, fork bombs)
2. Performs triage (urgency, blast radius, trend analysis)
3. Identifies root cause with confidence level
4. Provides actionable fix commands
Smart Alerting: Alerts are deduplicated (same alert suppressed for 5 min) and throttled (max 10/hour) to prevent notification fatigue. Only actionable alerts reach you.
Command Reference
Core Commands
init
spyd init
Interactive setup wizard that guides you through initial configuration including AI provider, monitoring thresholds, and notification channels.
$ spyd init
Welcome to Spyd Setup!
AI Configuration
? Enable AI analysis? Yes
? AI Provider: OpenAI
? API Key: sk-...
? Model: gpt-4o-mini
Monitoring Thresholds
? CPU Threshold (%): 80
? Memory Threshold (%): 85
? Disk Threshold (%): 90
Configuration saved to ~/.config/spyd/config.yaml
start
spyd start
Starts the Spyd daemon in the background. The daemon collects system metrics every 60 seconds (configurable) and triggers AI analysis when thresholds are exceeded.
$ spyd start
Daemon started (PID: 12345)
stop
spyd stop
Gracefully stops the running daemon. Completes the current metric collection cycle before shutting down.
$ spyd stop
Daemon stopped
restart
spyd restart
Stops and restarts the daemon. Useful after configuration changes.
$ spyd restart
Daemon stopped
Daemon started (PID: 12346)
status
spyd status
Displays current system health snapshot including CPU, memory, disk usage, load average, and the most recent AI analysis.
$ spyd status
+---------------------------------------------------------------+
| Spyd Status |
+---------------------------------------------------------------+
Daemon: Running (PID: 12345)
Uptime: 2h 15m 30s
System Metrics:
CPU: 45.2% [========----------]
Memory: 62.1% [============------]
Disk: 55.3% [===========-------]
Load: 1.2, 0.8, 0.6
AI Analysis:
Last checked: 2m ago
Status: System healthy
Provider: OpenAI (gpt-4o-mini)
Notifications:
Telegram: Enabled
Email: Enabled
start --foreground
spyd start -f
Runs daemon in foreground with verbose logging. Useful for debugging or running in Docker/systemd.
$ spyd start --foreground
Spyd daemon started (PID: 12345)
2024-01-15T10:30:00Z INF Collecting metrics...
2024-01-15T10:30:01Z INF CPU: 45.2%, Memory: 62.1%, Disk: 55.3%
2024-01-15T10:30:01Z INF All metrics within thresholds
Monitoring & Logs
logs
spyd logs [-n COUNT] [--since DURATION]
View detected log events that matched configured patterns (ERROR, FATAL, etc.).
$ spyd logs
$ spyd logs -n 50
$ spyd logs --since 1h
alerts
spyd alerts [-n COUNT] [--since DURATION] [--ack ID]
View and manage alerts generated by Spyd.
$ spyd alerts
Alerts (last 5):
=================
2024-01-15 10:30:00 [critical]
ID: abc12345
CPU usage 95.3% exceeds threshold 80.0%
Metric: cpu | Value: 95.30 | Threshold: 80.00
AI: Fork bomb detected...
$ spyd alerts --since 24h
$ spyd alerts --ack abc12345
explain
spyd explain "question" [--context "additional context"]
Ask AI about a specific error, log, or topic. Get expert-level explanations for server issues.
$ spyd explain "what does OOM killer mean?"
Asking AI (openai)...
===============================================================
AI EXPLANATION
===============================================================
The OOM (Out of Memory) Killer is a Linux kernel mechanism that
activates when the system runs critically low on memory. It
selects and terminates processes to free up RAM and prevent a
complete system crash.
When triggered, you'll see messages like:
"Out of memory: Killed process 1234 (nginx)"
Common causes:
1. Memory leak in an application
2. Insufficient RAM for workload
3. Too many processes running simultaneously
To investigate:
$ dmesg | grep -i "out of memory"
$ grep -i "killed process" /var/log/syslog
$ spyd explain "nginx error: upstream timed out" --context "high traffic spike"
test-alert
spyd test-alert [--channel CHANNEL] [--severity LEVEL]
Send a test alert through configured notification channels to verify setup.
$ spyd test-alert
+---------------------------------------------------------------+
| Spyd Test Alert |
+---------------------------------------------------------------+
Sending test alert...
Severity: warning
Message: This is a test notification to verify your Spyd alert configuration.
Channel: all
Channels tested:
telegram: @your_chat_id
email: [admin@example.com]
$ spyd test-alert --channel telegram
$ spyd test-alert --severity critical
analyze
spyd analyze [--mode MODE]
Trigger manual AI analysis of current system state. Collects metrics, runs anomaly detection, and provides AI insights.
$ spyd analyze
$ spyd analyze --mode basic
$ spyd analyze --mode hybrid
Configuration Commands
configure ai
spyd configure ai [flags]
Update AI provider settings. Shows full configuration summary when run without flags.
$ spyd configure ai
$ spyd configure ai --provider openai --model gpt-4o-mini
$ spyd configure ai --command-enable
$ spyd configure ai --command-disable
configure monitoring
spyd configure monitoring
Interactive configuration for monitoring thresholds (CPU, Memory, Disk, Load Average).
configure alerts
spyd configure alerts [--channel CHANNEL]
Set up notification channels. Use --channel flag to configure a specific channel directly.
$ spyd configure alerts
$ spyd configure alerts --channel telegram
$ spyd configure alerts --channel email
$ spyd configure alerts --channel slack
$ spyd configure alerts --channel discord
$ spyd configure alerts --channel desktop
$ spyd configure alerts --channel webhook
configure show
spyd configure show
Display complete configuration summary including AI settings, monitoring thresholds, alert channels, and storage settings.
$ spyd configure show
Configuration: ~/.config/spyd/config.yaml
AI:
Provider: openai
Model: gpt-4o-mini
Command Execution: enabled
Monitoring:
Interval: 60s
CPU Threshold: 80%
Memory Threshold: 85%
Disk Threshold: 90%
Notifications:
Telegram: Enabled (chat: -123456789)
Email: Enabled (to: admin@example.com)
Slack: Disabled
Discord: Disabled
Desktop: Disabled
Storage:
Database: ~/.local/share/spyd/spyd.db
Retention: 30 days
Utility Commands
upgrade
spyd upgrade [--check] [--force]
Check for and install the latest version. Automatically stops the daemon, installs the new binary, and restarts the daemon.
$ spyd upgrade
Current version: 0.1.0
Checking for updates...
Latest version: 0.2.0
Downloading spyd_linux_amd64...
Stopping daemon...
Installing new version...
Restarting daemon...
Successfully upgraded to v0.2.0!
$ spyd upgrade --check
$ spyd upgrade --force
uninstall
spyd uninstall [--yes]
Complete uninstallation with zero traces. Removes binary, configuration, data, logs, and service files. Use --yes to skip confirmation prompts.
$ spyd uninstall
Spyd Complete Uninstaller
This will remove Spyd and all its data with zero traces.
Continue with complete uninstall? [y/N] y
[1/7] Stopping Spyd daemon...
Stopping daemon (PID: 12345)...
[2/7] Removing systemd services...
[3/7] Skipping launchd (not macOS)
[4/7] Removing binary...
Removed: /usr/local/bin/spyd
[5/7] Removing v1 artifacts...
[6/7] Removing configuration, data, and logs...
Remove configuration? [y/N] y
Removed: ~/.config/spyd
Remove data and database? [y/N] y
Removed: ~/.local/share/spyd
[7/7] Cleaning up PID files...
Verifying cleanup...
Spyd has been completely uninstalled.
$ spyd uninstall --yes
version
spyd version [-f|--full]
Show version information. Use --full for banner and build details.
$ spyd version
Spyd Version 0.1.0
$ spyd version --full
[ASCII banner]
Version: 0.1.0
Commit: abc1234
Built: 2024-01-15T10:00:00Z
Go: go1.21.5
doctor
spyd doctor
Diagnose configuration and connectivity issues. Checks AI provider, notification channels, and system requirements.
$ spyd doctor
Spyd Doctor - Diagnosing your setup...
[Configuration]
Config file: ~/.config/spyd/config.yaml
Status: Valid
[AI Provider]
Provider: OpenAI
API Key: sk-...xxxx (set)
Connection: OK
[Notifications]
Telegram: OK (message sent)
Email: OK (SMTP connection successful)
[System]
OS: linux
Architecture: amd64
Memory: 8GB
Disk: 100GB free
All checks passed!
Alert Channels
Spyd supports 6 notification channels. Configure them using spyd configure alerts or by editing the config file.
Email
SMTP-based email notifications. Supports Gmail, Outlook, and custom SMTP servers.
notifications:
email:
enabled: true
smtp_host: smtp.gmail.com
smtp_port: 587
smtp_user: alerts@example.com
smtp_pass: your-app-password
from: spyd@yourserver.com
to:
- admin@example.com
- ops@example.com
use_tls: true
📧 Sample Email Alert
Subject: [Spyd] CRITICAL - cpu on my-server
CRITICAL - cpu
CPU usage 95.3% exceeds threshold 80.0%
Server: my-server
Time: 2024-01-15 10:30:00
WHAT HAPPENED:
Your server is being hammered by automated scripts. Multiple
bash processes are consuming all CPU - this looks like a
stress test or denial-of-service attempt. Confidence: 90%
FIX BY RUNNING:
$ kill -15 3685587 3685588 3685589 3685590
CAUTION: Review command before executing. Ensure you
understand what it does.
--
Spyd Monitoring
Slack
Send alerts to Slack channels using incoming webhooks.
notifications:
slack:
enabled: true
webhook_url: https://hooks.slack.com/services/T00/B00/XXX
channel: #alerts
💬 Sample Slack Alert
┌─────────────────────────────────────────────────────┐
│ 🚨 CRITICAL - cpu │
├─────────────────────────────────────────────────────┤
│ CPU usage 95.3% exceeds threshold 80.0% │
│ │
│ *WHAT HAPPENED:* │
│ Your server is being hammered by automated scripts. │
│ Multiple bash processes are consuming all CPU - │
│ this looks like a stress test or denial-of-service │
│ attempt. _Confidence: 90%_ │
│ │
│ *FIX BY RUNNING:* │
│ `kill -15 3685587 3685588 3685589 3685590` │
│ │
│ :warning: _CAUTION: Review command before │
│ executing._ │
├─────────────────────────────────────────────────────┤
│ Spyd • my-server Jan 15, 10:30 │
└─────────────────────────────────────────────────────┘
Telegram
Instant notifications via Telegram bot. Create a bot with @BotFather.
notifications:
telegram:
enabled: true
bot_token: 123456789:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
chat_id: 123456789
Setup:
- Message @BotFather on Telegram
- Send
/newbot and follow the prompts
- Copy the bot token
- Start a chat with your bot or add it to a group
- Get your chat ID by messaging @userinfobot
📱 Sample Telegram Alert
🚨 CRITICAL - cpu
CPU usage 95.3% exceeds threshold 80.0%
WHAT HAPPENED:
Your server is being hammered by automated scripts.
Multiple bash processes are consuming all CPU - this
looks like a stress test or denial-of-service attempt.
Confidence: 90%
FIX BY RUNNING:
kill -15 3685587 3685588 3685589 3685590
⚠️ CAUTION: Review command before executing.
Discord
Send rich embed notifications to Discord channels via webhooks.
notifications:
discord:
enabled: true
webhook_url: https://discord.com/api/webhooks/123/abc...
Setup: In Discord, go to Server Settings → Integrations → Webhooks → New Webhook. Copy the webhook URL.
🎮 Sample Discord Alert
┌──────────────────────────────────────────────────────┐
│ 🚨 CRITICAL - cpu [RED] │
├──────────────────────────────────────────────────────┤
│ CPU usage 95.3% exceeds threshold 80.0% │
│ │
│ **WHAT HAPPENED:** │
│ Your server is being hammered by automated scripts. │
│ Multiple bash processes are consuming all CPU - │
│ this looks like a stress test or denial-of-service │
│ attempt. *Confidence: 90%* │
│ │
│ **FIX BY RUNNING:** │
│ `kill -15 3685587 3685588 3685589 3685590` │
│ │
│ ⚠️ *CAUTION: Review command before executing.* │
├──────────────────────────────────────────────────────┤
│ Spyd • my-server 2024-01-15T10:30 │
└──────────────────────────────────────────────────────┘
Desktop (ntfy)
Cross-platform push notifications via ntfy.sh. Works on phones, desktops, and browsers.
notifications:
desktop:
enabled: true
server: https://ntfy.sh
topic: my-server-alerts
token:
priority:
Setup:
- Install the ntfy app on your phone or desktop
- Subscribe to your topic (e.g.,
my-server-alerts)
- Configure Spyd with the same topic name
- That's it! Alerts will push to all subscribed devices
🔔 Sample Desktop (ntfy) Alert
Title: 🚨 CRITICAL - cpu
Priority: urgent
Tags: rotating_light, skull
CPU usage 95.3% exceeds threshold 80.0%
WHAT HAPPENED:
Your server is being hammered by automated scripts.
Multiple bash processes are consuming all CPU - this
looks like a stress test or denial-of-service attempt.
Confidence: 90%
FIX BY RUNNING:
$ kill -15 3685587 3685588 3685589 3685590
⚠️ CAUTION: Review command before executing.
Webhooks
Generic HTTP webhooks for custom integrations, PagerDuty, Opsgenie, or any service that accepts webhooks.
notifications:
webhook:
enabled: true
url: https://your-service.com/webhook/spyd
method: POST
🔗 Sample Webhook Payload (JSON)
{
"id": "alert-1705312200",
"title": "CRITICAL - cpu",
"message": "CPU usage 95.3% exceeds threshold 80.0%",
"severity": "critical",
"metric": "cpu",
"value": 95.3,
"threshold": 80.0,
"server": "my-server",
"timestamp": "2024-01-15T10:30:00Z",
"diagnosis": {
"summary": "Your server is being hammered by automated scripts...",
"root_cause": "Fork bomb pattern detected. PIDs 3685587, 3685588...",
"suggestions": [
"kill -15 3685587 3685588 3685589 3685590"
],
"confidence": 0.90
}
}
Testing Alerts: Use spyd test-alert to verify your notification setup is working correctly before relying on it for real alerts.
AI Providers
Spyd supports multiple AI providers. Choose based on your needs: cloud providers for convenience, or local models for privacy.
OpenAI
Fast, accurate analysis with GPT-4o-mini or other OpenAI models. Requires API key.
ai:
enabled: true
provider: openai
api_key: sk-...
model: gpt-4o-mini
Anthropic (Claude)
Claude models for detailed, nuanced analysis. Requires API key.
ai:
enabled: true
provider: anthropic
api_key: sk-ant-...
model: claude-3-haiku-20240307
Ollama (Local)
Run AI locally with Ollama. 100% private, zero cost, no API key required.
ai:
enabled: true
provider: ollama
base_url: http://localhost:11434
model: llama3
$ curl -fsSL https://ollama.ai/install.sh | sh
$ ollama pull llama3
LiteLLM
Unified API for 100+ LLM providers. Use any model through a single interface.
ai:
enabled: true
provider: litellm
base_url: http://localhost:4000
model: gpt-4o-mini
Azure OpenAI
For enterprise deployments with Azure compliance requirements.
ai:
enabled: true
provider: azure
api_key: your-azure-key
base_url: https://your-resource.openai.azure.com
model: your-deployment-name
Privacy Note: When using cloud providers (OpenAI, Anthropic, Azure), only redacted system summaries are sent for analysis. Sensitive information (usernames, paths, IPs) is automatically removed using configurable privacy patterns.