{# Server tab "database": one card per monitored database from smp.database. Context: s, smp, rules, fmt_bytes, latest_custom #} {% set dbs = smp.get('database') or [] %} {% if dbs %}
| Top queries (by total time) | Calls | Mean | Total |
|---|---|---|---|
| {{ q.get('calls') }} | {{ '%.1f'|format(q.mean_ms) if q.get('mean_ms') is not none else '—' }} ms | {{ '%.0f'|format(q.total_ms) if q.get('total_ms') is not none else '—' }} ms |
pg_stat_statements (PostgreSQL) or performance_schema (MySQL) to see the slowest queries.db:{{ d.get('name') }}:connections, tps, cache_hit_pct, replication_lag_s — set limits under Alert rules → Custom metric limits.Credentials stay on the server: add a databases list to /etc/vigil-agent.json and restart the agent (systemctl restart vigil-server-agent). The agent uses the local CLI clients (psql, mysql, redis-cli) with 10 s timeouts and never sends passwords to Vigil.
{
"databases": [
{"system": "postgresql", "name": "main", "dsn": "postgresql://vigil:secret@127.0.0.1:5432/app"},
{"system": "mysql", "name": "shop", "dsn": "mysql://vigil:secret@127.0.0.1:3306/shop"},
{"system": "redis", "name": "cache", "dsn": "redis://:secret@127.0.0.1:6379/0"}
]
}
PostgreSQL: a read-only role is enough (GRANT pg_monitor TO vigil;). For the top-queries table enable pg_stat_statements (shared_preload_libraries = 'pg_stat_statements', then CREATE EXTENSION pg_stat_statements;). MySQL: GRANT PROCESS, REPLICATION CLIENT, SELECT ON performance_schema.* TO vigil. Alerts: unreachable database, connections ≥ {{ rules.get('db_connections_pct', 90) }}% of max, cache hit < {{ rules.get('db_cache_hit_pct', 90) }}%, replication lag ≥ {{ rules.get('db_replication_lag_s', 30) }} s (change under Alert rules).