docs/sources/datasources/mysql/annotations/index.md
Annotations overlay event data on your dashboard graphs, helping you correlate events with metrics. You can use MySQL as a data source for annotations to display events such as deployments, alerts, or other significant occurrences on your visualizations.
For general information about annotations, refer to Annotate visualizations.
Before creating MySQL annotations, ensure you have:
To add a MySQL annotation to your dashboard:
Your annotation query must return a time column and can optionally include timeend, text, and tags columns.
| Column | Required | Description |
|---|---|---|
time | Yes | The timestamp for the annotation. Can be a SQL datetime or UNIX epoch value. |
timeend | No | The end timestamp for range annotations. Creates a shaded region instead of a vertical line. |
text | No | The annotation description displayed when you hover over the annotation. |
tags | No | Tags for the annotation as a comma-separated string. Helps categorize and filter annotations. |
The following examples show common annotation query patterns.
Display events using UNIX epoch timestamps:
SELECT
epoch_time as time,
description as text,
CONCAT(tag1, ',', tag2) as tags
FROM events
WHERE $__unixEpochFilter(epoch_time)
Display events with a single tag value:
SELECT
epoch_time as time,
message as text,
category as tags
FROM event_log
WHERE $__unixEpochFilter(epoch_time)
Display events with duration as shaded regions:
SELECT
start_time as time,
end_time as timeend,
description as text,
CONCAT(type, ',', severity) as tags
FROM incidents
WHERE $__unixEpochFilter(start_time)
Display events using native MySQL datetime columns:
SELECT
event_date as time,
message as text,
CONCAT(category, ',', priority) as tags
FROM system_events
WHERE $__timeFilter(event_date)
Display deployment events:
SELECT
deployed_at as time,
CONCAT('Deployed ', version, ' to ', environment) as text,
environment as tags
FROM deployments
WHERE $__timeFilter(deployed_at)
Display maintenance windows as range annotations:
SELECT
start_time as time,
end_time as timeend,
CONCAT('Maintenance: ', description) as text,
'maintenance' as tags
FROM maintenance_windows
WHERE $__timeFilter(start_time)
Use these macros in your annotation queries to filter by the dashboard time range:
| Macro | Description |
|---|---|
$__timeFilter(column) | Filters by time range using a native SQL datetime column. |
$__unixEpochFilter(column) | Filters by time range using a column with UNIX epoch timestamps. |
Follow these best practices when creating MySQL annotations:
$__timeFilter() or $__unixEpochFilter() to limit results to the dashboard time range.text column to make annotations useful.