Querying Metrics in Explore
Explore provides powerful capabilities for querying and analyzing time-series metrics data from sources like Prometheus, Graphite, InfluxDB, and other metrics databases.Metrics Visualization
When you query metrics data, Explore displays results in multiple formats:Graph View
The primary visualization for time-series data shows:- Line, bar, or points visualization styles
- Multiple series overlaid on the same graph
- Time-based X-axis with automatic scaling
- Interactive tooltips showing values at specific times
- Zoom capabilities by selecting a time range
Table View
The table displays metric data in a structured format:- Time-indexed rows
- Columns for each series and label
- Sorting and filtering capabilities
- Export to CSV option
Raw Data View
For Prometheus specifically, the Raw Prometheus view shows:- Native Prometheus response format
- Instant query results
- Metadata about the query execution
Prometheus Queries
Basic Queries
Prometheus is the most common metrics data source in Grafana. Here are essential query patterns:Instant Vector Queries
Query current values of a metric:up metric for all time series.
Range Vector Queries
Query values over a time range:Query Builder
The Prometheus query builder helps construct queries visually:Select metric
Start by choosing a metric from the dropdown. Metrics are autocompleted based on what’s available in your Prometheus instance.
Common Query Patterns
Calculate Rate of Change
For counter metrics, userate() to calculate per-second increase:
Aggregation
Sum metrics across dimensions:handler label and sums them.
Percentiles
Calculate percentiles from histogram metrics:Filtering by Labels
Use label matchers to filter time series:Advanced Techniques
Offset Queries
Compare current values with historical data:Multiple Aggregations
Combine different aggregation functions:Subqueries
Perform calculations over aggregated results:Graph Customization
Graph Styles
Explore supports multiple visualization styles:- Lines - Default style showing connected data points
- Bars - Vertical bars representing each data point
- Points - Individual markers for each measurement
Multiple Series Display
By default, Explore shows up to 20 time series. If your query returns more, you’ll see a warning with an option to show all series.
- Use label filters to reduce the number of series
- Apply aggregations to combine related series
- Click “Show all series” if you need to see everything
Time Controls
Time Picker
Control the time range for your queries:- Relative time ranges: Last 5m, 15m, 1h, 6h, 24h, etc.
- Absolute time ranges: Specify exact start and end times
- Fiscal year settings: Configure fiscal year start month
Zoom and Navigation
- Click and drag on the graph to zoom into a time range
- Use the ← → buttons to shift the time range backward/forward
- Click Zoom out to return to the previous time range
- Use Time sync in split view to synchronize time ranges across panes
Auto-refresh
Enable auto-refresh to continuously update metrics:- Click the refresh interval dropdown
- Select an interval (5s, 10s, 30s, 1m, etc.)
- Queries re-run automatically at the selected interval
Query Inspector
The Query Inspector provides detailed information about query execution:Logs Volume (Metrics from Logs)
When querying log sources that support metrics (like Loki), Explore can show a metrics overlay:- Histogram showing log volume over time
- Colored by log level (error, warning, info, etc.)
- Click bars to filter to that time range
- Toggle on/off with the Logs volume button
Exemplars
If your Prometheus instance has exemplars enabled, you can:- See exemplar markers on the graph (small diamonds)
- Click an exemplar to view associated trace
- Follow the link to the trace in the tracing data source
Exemplars require Prometheus 2.26+ and must be explicitly recorded by your instrumentation.
Exporting and Sharing
Share Query
- Click the Share button in the toolbar
- Copy the generated URL
- Share with team members - the URL contains all query and time range information
Export Data
From the table view:- Click the download icon
- Choose CSV format
- Data exports with all columns and time formatting
Create Dashboard Panel
Convert your Explore query into a dashboard panel:- Click Add to dashboard (when available)
- Select target dashboard
- Configure panel options
- Save the dashboard
Best Practices
Optimize query performance
Optimize query performance
- Use specific label filters to reduce series cardinality
- Avoid queries that select thousands of time series
- Use appropriate time ranges - longer ranges require more processing
- Apply
rate()before aggregation functions likesum()
Use the query builder for exploration
Use the query builder for exploration
- Start with the visual query builder when exploring unfamiliar metrics
- Switch to code mode for advanced PromQL features
- Use metrics browser to discover available metrics and labels
Leverage split view for correlation
Leverage split view for correlation
- Compare metrics before and after a deployment
- View related metrics side-by-side (CPU vs. memory, requests vs. errors)
- Use time sync to ensure consistent time ranges
Save frequently used queries
Save frequently used queries
- Use query history to access recent queries
- Star important queries for quick access
- Consider creating dashboards for regularly-reviewed metrics
Troubleshooting
No data returned
- Verify the time range includes data for your metric
- Check label filters aren’t too restrictive
- Confirm the metric exists in your Prometheus instance
- Use the metrics browser to explore available metrics
Query timeout
- Reduce the time range
- Add more specific label filters
- Simplify complex aggregations
- Check Prometheus performance and resource limits
Too many series
- Add label filters to reduce cardinality
- Use aggregation to combine related series
- Consider if you need all the data or just a subset
Next Steps
Querying Logs
Learn how to explore and analyze log data
Distributed Tracing
Investigate traces and service dependencies