Repository navigation
Recipe Loki Grafana Stack
For teams with no log platform. One docker compose up on any host
that can reach the RDS API gives you:
- full-text search over every RDS log line (Grafana Explore + a search box)
- an RDS logs dashboard: security counters, errors by database, slow queries, security events
-
alerts for destructive DDL, privilege changes, failed-login bursts,
DELETE/UPDATEwithoutWHERE, connection exhaustion, FATAL/PANIC lines and repeated deadlocks, routed to Slack, email or any webhook
Everything lives in examples/stack-loki-grafana/.
rdstail ──http──▶ vector ──▶ Loki ──▶ Grafana (dashboard, Explore)
disk │
buffer └─ ruler ──▶ Alertmanager ──▶ Slack / email / webhook
cd examples/stack-loki-grafana
export AWS_REGION=us-east-1
export AWS_PROFILE=my-profile # or AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY
export GRAFANA_ADMIN_PASSWORD='choose-one'
docker compose up -d- Grafana: http://localhost:3000. The RDS logs dashboard is the home page.
- Alertmanager: http://localhost:9093
- rdstail metrics: http://localhost:9090/metrics
By default rdstail discovers every supported instance in AWS_REGION
and starts at the end of each log (only new lines). To narrow it, edit
rdstail.yaml: list instances:, tag databases rdstail=off to exclude
them, or add regions:. The IAM rdstail needs:
rdstail iam-policy -c rdstail.yamlRunning on EC2 with an instance role? Containers reach IMDSv2 only when the instance's metadata hop limit is ≥ 2 (
aws ec2 modify-instance-metadata-options --http-put-response-hop-limit 2).
| Panel | Shows |
|---|---|
| Destructive DDL / Privilege changes / Failed logins / ERROR+ | Counts over the selected time range; anything non-zero turns red/orange |
| Log lines by severity, Errors by instance | Volume over time. A sudden ERROR wall is visible at a glance |
| Security events | The lines behind the counters, prefixed with the database |
| Errors | ERROR / FATAL / PANIC lines |
| Slow queries | MySQL slow-query entries, PostgreSQL duration: lines |
| Search | Every line matching the Search box (case-insensitive regex) |
Filter by Instance and Engine at the top. For ad-hoc digging use Explore with LogQL:
{job="rdstail", instance="orders-db"} |~ `(?i)deadlock|lock wait`
{job="rdstail", log_type="slowquery"} |~ `Rows_examined: \d{7,}`
{job="rdstail", severity=~"ERROR|FATAL"} | log_file=~"error/.*" != "canceling statement"
Labels (cheap to filter on): instance, engine, severity (NONE for
continuation lines), log_type (error, slowquery, general, audit).
log_file and batch_id are structured metadata. Filter them with
| log_file=~"…" after the selector.
Rules live in
loki-rules/fake/rds-security.yaml
and are evaluated every minute by Loki's ruler:
| Alert | Fires when | Severity |
|---|---|---|
RDSDestructiveDDL |
DROP TABLE/DATABASE/SCHEMA/VIEW/INDEX/FUNCTION/…, TRUNCATE
|
critical |
RDSPrivilegeChange |
GRANT, REVOKE, CREATE/ALTER/DROP/RENAME USER/ROLE, SET PASSWORD
|
warning |
RDSFailedLoginBurst |
≥ 10 failed authentications in 5 min | warning |
RDSUnboundedWrite |
DELETE FROM / UPDATE … SET with no WHERE
|
warning |
RDSConnectionExhaustion |
"too many connections" / "remaining connection slots are reserved" | critical |
RDSFatalErrors |
FATAL/PANIC lines (auth failures excluded) | warning |
RDSDeadlocks |
≥ 3 deadlocks in 10 min | info |
These only fire if the engine logs the statements. DDL, GRANTs and DML are not in RDS logs by default. Security detections lists the exact parameter-group / option-group settings per engine.
Send them somewhere: in
alertmanager.yml,
uncomment the Slack, email or webhook receiver, set route.receiver to it,
and docker compose restart alertmanager. For Slack, mount a file holding
the webhook URL at the api_url_file path. Out of the box nothing leaves
the host: alerts show in Alertmanager and Grafana → Alerting.
Tune false positives by adding a negative filter to a rule, e.g. ETL jobs that drop scratch tables:
{job="rdstail"} |~ `(?i)\bdrop\s+table` !~ `(?i)drop\s+table\s+(if\s+exists\s+)?tmp_`
Latency: a statement reaches Loki one rdstail poll after RDS writes it
(p50 ≈ 3.5 s at poll_interval: 5s; this stack uses 10 s and backs quiet
databases off to 2 min). The ruler evaluates every minute, and
Alertmanager waits group_wait (30 s). Expect alerts 1–3 minutes after the
statement. That's fast enough for detection, but these alerts are not a
prevention control.
-
rdstail's
httpsink gets a 2xx from vector only after the batch is in vector's disk buffer (acknowledgementson the Loki sink). rdstail checkpoints after that 2xx, so nothing is lost between them. -
vector's 1 GiB disk buffer rides out a Loki restart; when full it blocks, which back-pressures rdstail (its checkpoints simply stop advancing).
-
If vector is down, rdstail retries with backoff and then parks batches in its DLQ (
rdstail_dlq_depthon :9090). Once vector is back, replay them:docker compose stop rdstail docker compose run --rm rdstail dlq replay -c /etc/rdstail/config.yaml docker compose start rdstail
-
Loki dedupes identical (timestamp, line) entries in a stream, so an at-least-once re-send after a crash does not double-count.
RDS logs contain SQL text, user names and client IPs. That's why every port
is bound to 127.0.0.1. Before letting others in:
- put Grafana behind your SSO / reverse proxy, or at least change the admin password and create viewer accounts
- keep Loki (3100) and Alertmanager (9093) private: neither has auth here
- consider dropping noisy or sensitive lines in the vector
remap(e.g.abortonlog_type == "general")
- Loki keeps 30 days (
retention_period: 720hinloki.yaml); keep S3 as the long-term archive by adding an S3 sink tordstail.yaml. Every sink receives every record. - A single-node Loki on local disk is right for this stack's audience:
a handful to a few dozen databases with error/slow/audit logs. If you're
shipping
general_logfrom busy databases, read Performance and throughput first. The RDS API, not Loki, is usually the limit. - Keep labels low-cardinality. Never turn
log_file,batch_idor anything from the message into a label.
docker compose down # keep data volumes
docker compose down -v # also delete logs, state and dashboards