Grafana Dashboards - Combining PromQL and LogQL to Follow an Application End to End
1. Recap: Data Ready, Now Visualize It
The previous article’s unified stack already collects metrics from both mini apps, receives their logs and processes their traces. But so far, every query has been run by hand — one PromQL expression at a time in Prometheus, one LogQL query at a time in Grafana’s Explore. This article builds a real dashboard, with several panels side by side, to follow both mini apps without reopening loose queries every time.
2. Creating the Dashboard and the First Panel
In Grafana, under Dashboards → New → New Dashboard → Add visualization, choosing the Prometheus datasource, the first panel is the Python mini app’s request rate:
rate(app_requests_total{job="python-app"}[1m])
Relevant settings for this panel:
- Visualization: Time series (the default, suitable for any metric over time).
- Title: “Request Rate — Python App”.
- Unit (in the Standard options tab): “requests/sec”, so the Y axis is readable without interpreting the raw number.
3. Latency Panel with histogram_quantile
A second panel, using the duration histogram created in article 3 for the PHP mini app:
histogram_quantile(0.50, rate(orders_duration_seconds_bucket{job="php-app"}[5m]))
histogram_quantile(0.95, rate(orders_duration_seconds_bucket{job="php-app"}[5m]))
histogram_quantile(0.99, rate(orders_duration_seconds_bucket{job="php-app"}[5m]))
Adding the three expressions as three queries (A, B, C) in the same Time series panel turns each one into a line — p50, p95 and p99 overlaid on the same chart is the most common way to visualize latency, because the distance between the three lines already shows visually how “long-tailed” the latency is: lines close together indicate consistent latency, while a p99 far above p50 indicates that a small fraction of requests is much slower than the majority.
4. Queue Size Panel (Gauge)
A Gauge panel (a dial/speedometer) for the PHP mini app’s current order queue size — useful because it shows the instantaneous value prominently, without requiring you to interpret a line chart:
orders_queue_size{job="php-app"}
In this panel’s Thresholds tab, it’s worth setting color bands — green up to 5, yellow up to 15, red above that — so the panel communicates “all good” or “attention” at a glance, without having to read the number.
5. Logs Panel with LogQL
Adding a new panel, now with the Loki datasource, of type Logs:
{app=~"python-app|php-app"}
The =~ expression does regex matching on the label value — in this case, bringing logs from both applications into the same panel, stacked by time. A second logs panel, filtered to error events only (useful to keep visible even when the overall log volume is high):
{app=~"python-app|php-app", level="error"}
6. Log Volume Over Time Panel
LogQL also allows numeric aggregations over logs, not just listing lines — useful for visually correlating a spike in error log volume with a metrics panel next to it:
sum(count_over_time({app=~"python-app|php-app", level="error"}[1m]))
This panel, as a Time series (even though it comes from a LogQL query), shows how many error log lines per minute the applications produced — the log equivalent of what rate() does for a Prometheus counter.
7. Organizing the Dashboard
With the five panels created — request rate, p50/p95/p99 latency, queue size, recent logs and error volume — the recommended layout follows a common convention in observability dashboards: from the general to the specific, top to bottom.
┌─────────────────────────┬─────────────────────────┐
│ Request Rate │ p50/p95/p99 Latency │
├─────────────────────────┼─────────────────────────┤
│ Queue Size (gauge) │ Errors / min │
├─────────────────────────┴─────────────────────────┤
│ Recent Logs (filtered by app and level) │
└─────────────────────────────────────────────────────┘
Aggregated metric panels (the “what”) go at the top, and the detailed logs panel (the “why”) goes at the bottom — that way, the natural investigation flow (see the problem at the top, understand the cause at the bottom) follows the dashboard’s own visual order. Saving the dashboard with a name like “Mini Apps — Overview” and an observability tag makes it available in Grafana’s main dashboard list.
8. Template Variable to Switch Between Apps
To avoid duplicating the whole dashboard for Python and PHP, Grafana lets you create a variable that filters the panels dynamically. Under Dashboard settings → Variables → Add variable:
- Name:
app - Type: Query
- Data source: Prometheus
- Query:
label_values(app_requests_total, job)(or, more generically,label_values(job)to list every job configured inprometheus.yml)
With the variable created, each panel query uses $app instead of the fixed value:
rate(app_requests_total{job="$app"}[1m])
A selector appears at the top of the dashboard, letting you switch between python-app and php-app without editing any panel by hand — the same dashboard serves both mini apps, and any new application the stack might gain in the future.
9. Conclusion and Next Steps
We built a real dashboard combining metrics via PromQL (request rate, latency by percentile, queue size) and logs via LogQL (recent events, error volume), organized from the general to the specific and parameterized with a template variable for reuse across applications. In the last article of this series, this dashboard becomes a real investigation tool: we’ll simulate a real incident in the mini apps and use metrics, logs and traces together to find the root cause.
References: