1 unstable release
Uses new Rust 2024
new 0.1.0 | Apr 8, 2025 |
---|
#1209 in Database interfaces
21KB
152 lines
dbwarrior ๐ง
Real-time Postgres query monitoring CLI tool that detects long-running or high-row queries, checks indexing, alerts via Slack/email, logs to file or JSON, and integrates with your workflow.
๐ Features
- Detect long-running queries in
pg_stat_activity
- Analyze
WHERE
clause and check if indexes exist - Slack alerts + optional email fallback
- Log alerts to file and structured JSON
- Fingerprint queries to prevent alert spam
- GitHub Actions CI pipeline
- Easy
Makefile
for build/run/test/lint/publish
๐ง Installation
Option 1: Cargo
cargo install dbwarrior
Option 2: Clone & Build
git clone https://github.com/sanctusgee/dbwarrior.git
cd dbwarrior
make build
Run with:
make run
โ๏ธ Configuration
Create a config.toml
in your project root (or pass --config your_file.toml
):
db_url = "postgresql://user:password@localhost/yourdb"
query_time_threshold_secs = 30
row_estimate_threshold = 1000000
slack_webhook_url = "https://hooks.slack.com/services/..."
email_fallback = "alerts@yourcompany.com"
log_file_path = "dbwarrior.log"
json_output_path = "dbwarrior.json"
โ Example Output
โ ๏ธ Long-running query detected (PID 7483)
Duration: 45s
User: redash
Query:
SELECT * FROM events WHERE user_id IS NOT NULL
Table: events
No index on events(user_id) โ
Suggestion:
โ Add index on events(user_id)
๐ฆ Makefile Targets
make build # Compile in release mode
make run # Run using config.toml
make test # Run all tests
make lint # Run Clippy linter
make fmt # Format code
make watch # Rebuild on file changes
make publish # Publish to crates.io
๐งช GitHub Actions CI
Enabled for every push to main
and new release tags:
- ๐งฑ Builds the app
- โ Runs all tests
- ๐ท๏ธ Tags release versions automatically
๐ฌ JSON Output
Each alert is written as a line of JSON:
{
"pid": 7483,
"duration_secs": 45,
"user": "redash",
"query": "SELECT * FROM events WHERE user_id IS NOT NULL",
"table": "events",
"column": "user_id",
"index_exists": false,
"suggestion": "Add index on events(user_id)"
}
๐ Contributing
See CONTRIBUTING.md for setup, linting, and PR guidelines.
๐ก License
MIT ยฉ sanctusgee
โญ Star this repo if dbwarrior helps you keep queries in check!
Dependencies
~15โ29MB
~456K SLoC