TimelessMetrics exposes a Prometheus-compatible query endpoint that works with Grafana's built-in Prometheus data source.
Adding as a data source
In Grafana, go to Configuration > Data Sources > Add data source
Select Prometheus
Set the URL to your TimelessMetrics instance with the
/prometheusprefix:http://your-host:8428/prometheusIf authentication is enabled, add a custom header:
- Header:
Authorization - Value:
Bearer your-token
- Header:
Click Save & Test
Supported PromQL patterns
The /prometheus/api/v1/query_range endpoint supports a subset of PromQL that covers the most common dashboard queries:
Simple selectors
cpu_usage{hostname="host_0"}Regex label matching
cpu_usage{hostname=~"host_0|host_1"}Range vector functions
max_over_time(cpu_usage{hostname="host_0"}[1h])
avg_over_time(mem_usage{hostname="host_0"}[5m])
rate(http_requests_total{job="web"}[5m])Supported functions:
avg_over_timemin_over_timemax_over_timesum_over_timecount_over_timerateirate
Outer aggregation with group-by
max(max_over_time(cpu_usage{hostname=~"host_.*"}[1h])) by (hostname)Supported outer aggregations: avg, min, max, sum, count
Threshold filtering
max(max_over_time(cpu_usage{hostname="host_0"}[1h])) by (hostname) > 90Multi-metric with regex __name__
max(max_over_time({__name__=~"cpu_.*",hostname=~"host_0"}[1h])) by (hostname)Negative matching
cpu_usage{hostname!="host_0"}
cpu_usage{hostname!~"host_0|host_1"}Dashboard examples
Time series panel
Create a panel with a Prometheus data source query:
avg_over_time(cpu_usage{hostname=~"$hostname"}[5m])This returns a time series for each matching host, plotted as separate lines.
Grouped aggregation
max(max_over_time(cpu_usage{region=~"$region"}[1h])) by (hostname)Rate queries
rate(http_requests_total{job="web"}[5m])Variable queries
Use Grafana's variable feature to create dynamic dropdowns:
- Add a variable of type Query
- Data source: your TimelessMetrics Prometheus source
- Query type: Label values
- Label: the label key (e.g.,
hostname) - Metric: the metric name (e.g.,
cpu_usage)
The label values endpoint is:
/api/v1/label/{label_name}/values?metric={metric_name}List all metric names
For a metric name variable, use label __name__:
/api/v1/label/__name__/valuesAnnotation queries
Grafana can display TimelessMetrics annotations on panels:
Go to Dashboard Settings > Annotations
Add a new annotation source
Use a Generic HTTP data source or query the annotations API directly:
http://your-host:8428/api/v1/annotations?from=${__from:date:seconds}&to=${__to:date:seconds}Or filter by tags:
http://your-host:8428/api/v1/annotations?from=${__from:date:seconds}&to=${__to:date:seconds}&tags=deploy
Authentication setup
Bearer token
If bearer_token is configured on the HTTP server:
- In the Grafana data source configuration, under Custom HTTP Headers:
- Header:
Authorization - Value:
Bearer your-token
- Header:
No authentication
If no bearer token is set, Grafana connects without authentication. This is suitable for trusted networks where the TimelessMetrics instance is not publicly accessible.
Native query endpoint
In addition to the Prometheus-compatible endpoint, you can use TimelessMetrics' native query_range endpoint with Grafana's JSON API data source plugin:
http://your-host:8428/api/v1/query_range?metric=cpu_usage&from=${__from:date:seconds}&to=${__to:date:seconds}&step=${__interval_ms:raw}This supports additional features like:
group_byfor cross-series aggregationcross_aggregatefor specifying the cross-series functionmetricsfor multi-metric queriesthreshold_gt/threshold_ltfor server-side filteringtransformfor data transforms likeratelimitfor top-N queries
See API Reference for the full query_range documentation.