Through SQLs, we turn EXPLAIN into action.
sql-insight is a MySQL observability MVP focused on slow SQL attribution.
Current implementation delivers:
- MySQL 5.x / 8.x: Level 0 + Level 1
- PostgreSQL 14+: Level 0 + Level 1
- MySQL read-only collection:
SHOW GLOBAL STATUSSHOW VARIABLESINFORMATION_SCHEMA.TABLES(table size)INFORMATION_SCHEMA.STATISTICS(index metadata)SHOW REPLICA STATUS/ fallbackSHOW SLAVE STATUS
- OS metrics collection:
/proc/stat,/proc/meminfo,/proc/loadavg- Optional commands:
vmstat,iostat,sar(if installed)
- Capability-based level negotiation:
- Determines the highest acceptable collection level and emits downgrade reasons.
- Slow log hot-switch collection:
SET GLOBAL slow_query_log = ON- configurable
long_query_time - windowed capture with optional restore of original settings
- PostgreSQL statement-log hot-switch collection:
ALTER SYSTEM SET log_min_duration_statementSELECT pg_reload_conf()- windowed capture with optional restore of original settings
- Slow log digest aggregation:
- SQL fingerprint normalization
- grouped counts, latency totals/averages, rows examined/sent
- Error log alert extraction:
deadlockcrash recoverypurgereplication
- Level 0 read-only collection:
pg_stat_databaseaggregated status counterspg_settings- relation and index metadata (
pg_class/pg_namespace/pg_indexes) - replication state (
pg_stat_replication,pg_stat_wal_receiver,pg_is_in_recovery())
- Level 1 lightweight diagnostics:
- statement log window capture + digest aggregation
- error log alert extraction (
deadlock,crash_recovery,purge/vacuum,replication)
src/main.rs: CLI entrypoint (clap) + runtime logs (tracing)src/level0.rs: Level 0 collectors and report schemasrc/collection.rs: level negotiation and task mappingsrc/pipeline.rs: unified collection contract + scheduler utilitiessrc/lib.rs: module exports
cargo run -- --helpRun Level 1 collection:
MYSQL_URL='mysql://user:pass@127.0.0.1:3306' cargo run -- --collect-level level1 --output pretty-json -vRun Level 0 only:
cargo run -- --collect-level level0 --output jsonRun in scheduler mode (2 cycles):
cargo run -- --run-mode daemon --max-cycles 2 --interval-secs 30 --collect-level level0 --output jsonRun PostgreSQL Level 0:
POSTGRES_URL='postgres://user:pass@127.0.0.1:5432/postgres' cargo run -- --engine postgres --collect-level level0 --output pretty-json -vRun PostgreSQL Level 1:
POSTGRES_URL='postgres://user:pass@127.0.0.1:5432/postgres' cargo run -- --engine postgres --collect-level level1 --slow-log-path /var/log/postgresql/postgresql.log --error-log-path /var/log/postgresql/postgresql.log --output pretty-json -vWithout MYSQL_URL, the tool skips MySQL collection and keeps available local OS metrics.
- Scheduler:
--run-mode once|daemon(envRUN_MODE, defaultonce)--interval-secs/--jitter-pct--timeout-secs/--retry-times/--retry-backoff-ms--max-cycles(optional)
--mysql-url(or envMYSQL_URL)--postgres-url(or envPOSTGRES_URL)--engine mysql|postgres(or envDB_ENGINE, defaultmysql)--collect-level level0|level1(defaultlevel1)--table-limit(or envLEVEL0_TABLE_LIMIT, default200)--index-limit(or envLEVEL0_INDEX_LIMIT, default500)--slow-log-window-secs(envLEVEL1_SLOW_LOG_WINDOW_SECS, default30)--slow-log-long-query-time-secs(envLEVEL1_LONG_QUERY_TIME_SECS, default0.2)--slow-log-path(envLEVEL1_SLOW_LOG_PATH)--error-log-path(envLEVEL1_ERROR_LOG_PATH)--max-slow-log-bytes/--max-error-log-bytes/--max-error-log-lines--no-slow-log-hot-switch/--no-restore-slow-log-settings--output json|pretty-json(defaultpretty-json)-v/--verbose(info->debug->trace)
Collector output now uses a unified record envelope (JSON):
contract_version,run_id,cycleengine,requested_level,selected_levelschedule(mode/interval/timeout/retry policy)window(start/end/duration)attempts(per-attempt status and error)source_status(per-source success flags)warnings,status,errorpayload(engine-specific collection report)
cargo fmt
cargo test
cargo clippy --all-targets --all-featuresRun the multi-version database matrix test (MySQL 5.7/8.0 + PostgreSQL 14/16):
bash tests/scripts/run-matrix.shRun smoke matrix (PR fast gate):
MATRIX_PROFILE=smoke bash tests/scripts/run-matrix.shThe script validates:
- collector compatibility by database/version
- Level 0 capability extraction
- MySQL Level 1 slow-log digest and error-log alert collection
- PostgreSQL Level 1 statement-log digest and error-log alert collection
Set KEEP_CONTAINERS=1 to keep containers running after the script exits.
Validate matrix outputs against the v1 JSON schema and golden summary:
bash tests/scripts/check-contract.shUse CONTRACT_PROFILE=smoke for PR smoke outputs.
Schema file:
contracts/unified-record-v1.schema.json
Golden summary baseline:
tests/contracts/golden/matrix-summary.full.jsontests/contracts/golden/matrix-summary.smoke.json
CI applies this in two layers:
- PR gate: unit tests + parser regression + smoke matrix + contract gate + budget gate
- Nightly gate: unit tests + full matrix + contract gate + budget gate + resilience gate
Check runtime and payload budgets on collected matrix outputs:
bash tests/scripts/check-budget.shRun resilience scenarios (timeout/retry and forced Level 1 downgrade):
bash tests/scripts/run-resilience.shNightly CI additionally runs budget and resilience gates after full matrix.
- Level 2:
performance_schemaandsysenhanced diagnostics (MySQL),pg_stat_statementspath (PostgreSQL) - Level 3: expert-mode short-window deep sampling (
tcpdump/perf/strace)