Troubleshoot Prometheus data source issues
This document provides troubleshooting information for common errors you may encounter when using the Prometheus data source in Grafana.
Connection errors
The following errors occur when Grafana cannot establish or maintain a connection to Prometheus.
Failed to connect to Prometheus
Error message: “There was an error returned querying the Prometheus API”
Cause: Grafana cannot establish a network connection to the Prometheus server.
Solution:
- Verify that the Prometheus server URL is correct in the data source configuration.
- Check that Prometheus is running and accessible from the Grafana server.
- Ensure the URL includes the protocol (
http://orhttps://). - Verify the port is correct (the Prometheus default port is
9090). - Ensure there are no firewall rules blocking the connection.
- If Grafana and Prometheus are running in separate containers, use the container IP address or hostname instead of
localhost. - For Grafana Cloud, ensure you have configured Private data source connect if your Prometheus instance is not publicly accessible.
Request timed out
Error message: “context deadline exceeded” or “request timeout”
Cause: The connection to Prometheus timed out before receiving a response.
Solution:
- Check the network latency between Grafana and Prometheus.
- Verify that Prometheus is not overloaded or experiencing performance issues.
- Increase the Query timeout setting in the data source configuration under Interval behavior.
- Check the Grafana server timeout configuration for server-level timeout settings.
- Reduce the time range or complexity of your query.
- Check if any network devices (load balancers, proxies) are timing out the connection.
Failed to parse data source URL
Error message: “Failed to parse data source URL”
Cause: The URL entered in the data source configuration is not valid.
Solution:
- Verify the URL format is correct (for example,
http://localhost:9090orhttps://prometheus.example.com:9090). - Ensure the URL includes the protocol (
http://orhttps://). - Remove any trailing slashes or invalid characters from the URL.
Data doesn’t appear in Metrics Drilldown or Explore
Symptom: You’ve successfully tested the data source connection, but no metric data appears in Explore or Metrics Drilldown.
Cause: The wrong data source is selected, or the data source name doesn’t match expectations.
Solution:
- Verify you’ve selected the correct data source from the data source drop-down menu.
- When using
remote_writeto send metrics to Grafana Cloud, the data source name follows the conventiongrafanacloud-<stackname>-prom. - Check that metrics are being actively scraped by querying
upin the Explore view. - If using Grafana Cloud, verify the
remote_writeendpoint URL and credentials are correct.
PDC connectivity errors
Error messages: host unreachable, EOF, network unreachable, connection reset by peer, dial tcp: lookup ... no such host
Symptom: Prometheus queries fail intermittently or consistently when using Private data source connect (PDC) to reach a Prometheus instance behind a private network. The data source test may pass occasionally but queries fail under load.
Cause: PDC tunnels traffic through an SSH connection between Grafana Cloud and your PDC agent. Connectivity failures are most commonly caused by DNS resolution issues, network configuration on the customer side, or the PDC agent’s default connection limits being too low for the query volume.
Solutions:
Verify DNS resolution from the PDC agent host. The PDC agent must be able to resolve the Prometheus hostname from the machine it runs on. Run
nslookupordigfor the Prometheus URL from the agent host to confirm.Check network connectivity from the agent. Ensure the PDC agent can reach the Prometheus endpoint directly (for example,
curl http://prometheus-host:9090/-/healthyfrom the agent machine).Increase parallel SSH connections. The PDC agent defaults to 1 parallel SSH connection, which can bottleneck under load from multiple alert evaluations or dashboard queries. Increase this by setting the
--ssh-connectionsflag (orPDC_SSH_CONNECTIONSenvironment variable) to a higher value (for example, 4 or 8):pdc-agent --ssh-connections=4Check firewall rules. Ensure the PDC agent’s outbound SSH connection to Grafana Cloud isn’t being interrupted by firewall rules, NAT gateways, or idle connection timeouts.
Verify the PDC agent is running and healthy. Check agent logs for connection errors or restarts. The agent must maintain a persistent connection to Grafana Cloud.
Check for idle timeout issues. If the connection drops after periods of inactivity, configure TCP keepalive on the host or add a
keepalivesetting to the PDC agent configuration.
Note
PDC connectivity issues are almost always caused by networking on the customer side (DNS, firewall rules, routing), not by Grafana Cloud. The data source test passing doesn’t guarantee sustained connectivity under load. It only verifies a single query succeeds.
For general PDC setup and configuration, refer to Private data source connect (PDC) and Configure PDC.
Certificate verification failed
Error message: “x509: certificate signed by unknown authority” or “certificate verify failed”
Cause: Grafana cannot verify the TLS certificate presented by Prometheus.
Solution:
- If using a self-signed certificate, enable Add self-signed certificate in the TLS settings and add your CA certificate.
- Verify the certificate chain is complete and valid.
- Ensure the certificate has not expired.
- As a temporary workaround for testing, enable Skip TLS verify (not recommended for production).
TLS handshake error
Error message: “TLS: handshake failure” or “connection reset”
Cause: The TLS handshake between Grafana and Prometheus failed.
Solution:
- Verify that Prometheus is configured to use TLS.
- Check that the TLS version and cipher suites are compatible.
- If using client certificates, ensure they are correctly configured in the TLS client authentication section.
- Verify the server name matches the certificate’s Common Name or Subject Alternative Name.
Authentication errors
The following errors occur when there are issues with authentication credentials or permissions.
Unauthorized (401)
Error message: “401 Unauthorized” or “Authorization failed”
Cause: The authentication credentials are invalid or missing.
Solution:
- Verify that the username and password are correct if using basic authentication.
- Check that the authentication method selected matches your Prometheus configuration.
- If using a reverse proxy with authentication, verify the credentials are correct.
- For AWS SigV4 authentication, verify the IAM credentials and permissions. Alternatively, consider using the Amazon Managed Service for Prometheus data source for simplified AWS authentication.
OAuth token expiration errors (GCP and Azure)
Error messages: “ACCESS_TOKEN_EXPIRED”, “401 Unauthorized” in alerting but not in Explore
Symptom: Queries in Explore and dashboards work correctly, but alert rule evaluations fail intermittently with 401 errors. This is most common with Google Managed Prometheus (GMP) and Azure-managed Prometheus endpoints using OAuth/OIDC authentication.
Cause: The Grafana alerting backend and the interactive query path (Explore, dashboards) handle credential refreshes differently. The alerting evaluator can use a cached OAuth token beyond its expiry window due to a token staleness check issue in the Prometheus data source. This causes alerting to fail with expired credentials while interactive queries succeed because they trigger a fresh token exchange.
Solutions:
For Google Managed Prometheus (GMP):
- Use the GCP datasource-syncer pattern: run a sidecar process that refreshes OAuth tokens and updates the Grafana data source credentials on a schedule shorter than the token lifetime (typically every 45 minutes for a 60-minute token). This ensures the stored token is always valid when the alerting backend uses it.
- Alternatively, use the Google Cloud Monitor data source with its built-in GCP credential management rather than pointing the Prometheus data source at a GMP endpoint.
- If running on GKE with Workload Identity, ensure the Kubernetes service account token refresh is functioning and the projected token volume is mounted correctly.
For Azure Managed Prometheus:
- Verify the Azure AD app registration’s client secret hasn’t expired.
- If using Managed Identity, ensure the Grafana instance’s identity has the Monitoring Data Reader role on the Azure Monitor workspace.
- Check that Forward OAuth identity is not enabled alongside Azure AD authentication. Both use the same HTTP authorization headers and conflict with each other.
General steps:
- Check the Grafana server logs for token refresh errors around the time alerts fail.
- Verify the data source test (Save & test) passes. This confirms current credentials are valid but doesn’t guarantee the alerting backend has a fresh token.
- If the issue persists, set Alert state if execution error or timeout to Keep Last State to prevent false alarms while investigating. Refer to Configure alert state for execution errors.
Note
This token caching behavior is a known issue that has received code fixes in recent Grafana releases. If you’re experiencing this on an older Grafana version, upgrading may resolve it. Check the Grafana changelog for relevant fixes.
LBAC not restricting data on non-Mimir backends
Symptom: You’ve configured Team LBAC rules, but users can still see all metrics regardless of their team assignments.
Cause: Label-Based Access Control (LBAC) for the Prometheus data source only works when the backend is Grafana Cloud Metrics (Mimir) or Grafana Enterprise Metrics (GEM). It doesn’t work with Google Managed Prometheus, self-managed Prometheus, Thanos, or other Prometheus-compatible endpoints. The LBAC enforcement relies on Mimir-specific HTTP headers (X-Scope-OrgID and team-scoped label matchers) that other backends ignore.
Solution:
- Verify your backend is Grafana Cloud Metrics or GEM. If you’re using a different Prometheus-compatible backend, LBAC isn’t supported.
- For Google Managed Prometheus or other external endpoints, use data source permissions to control which teams can access the data source entirely, rather than per-label access control.
- If you need per-label restrictions on a non-Mimir backend, consider proxying through a Mimir instance or using a separate data source per team with different credentials scoped to the appropriate data.
Azure AD or SigV4 authentication options not available
Symptom: The Azure AD or SigV4 authentication options don’t appear in the authentication drop-down when configuring the Prometheus data source.
Cause: These authentication methods require server-side feature flags that aren’t enabled by default, particularly on Grafana Cloud.
Solution:
- Grafana Cloud: Contact Grafana Support to request the feature flag be enabled for your stack. This isn’t a self-service setting.
- Self-managed Grafana: Add the required setting to your Grafana configuration file:
- For Azure AD: set
azure_auth_enabled = trueunder[auth] - For SigV4: set
sigv4_auth_enabled = trueunder[auth]
- For Azure AD: set
- For Amazon Managed Prometheus: Consider using the dedicated Amazon Managed Service for Prometheus data source instead, which handles AWS authentication natively without needing the SigV4 flag.
Forbidden (403)
Error message: “403 Forbidden” or “Access denied”
Cause: The authenticated user does not have permission to access the requested resource.
Solution:
- Verify the user has read access to the Prometheus API.
- Check Prometheus security settings and access control configuration.
- If using a reverse proxy, verify the proxy is not blocking the request.
- For AWS Managed Prometheus, verify the IAM policy grants the required permissions. Alternatively, consider using the Amazon Managed Service for Prometheus data source for simplified AWS authentication.
Query errors
The following errors occur when there are issues with PromQL syntax or query execution.
Query syntax error
Error message: parse error: unexpected character or bad_data: 1:X: parse error
Cause: The PromQL query contains invalid syntax.
Alternative cause: A proxy between Grafana and Prometheus requires authentication. When proxy authentication fails, the proxy redirects the request to an HTML authentication page. Grafana cannot parse the HTML response, which results in a parse error. This appears to be a query issue but is actually a proxy authentication issue.
Solution:
- Check your query syntax for typos or invalid characters.
- Verify that metric names and label names are valid identifiers.
- Ensure string values in label matchers are enclosed in quotes.
- Use the Prometheus expression browser to test your query directly.
- Refer to the Prometheus querying documentation for syntax guidance.
- If you have a proxy between Grafana and Prometheus, verify that proxy authentication is correctly configured. Check your proxy logs for authentication failures or redirects.
Query returns no data for a metric
Symptom: The query returns no data and the visualization is empty.
Cause: The specified metric does not exist in Prometheus, or there is no data for the selected time range.
Solution:
- Verify the metric name is spelled correctly.
- Check that the metric is being scraped by Prometheus.
- Use the Prometheus API to browse available metrics at
/api/v1/label/__name__/values. - Use the target metadata API to verify which metrics a target exposes.
- Verify the time range includes data for the metric.
Query timeout limit exceeded
Error message: “query timed out in expression evaluation” or “query processing would load too many samples”
Cause: The query took longer than the configured timeout limit or would return too many samples.
Solution:
- Reduce the time range of your query.
- Add more specific label filters to limit the data scanned.
- Increase the Query timeout setting in the data source configuration.
- Use aggregation functions like
sum(),avg(), orrate()to reduce the number of time series. - Increase the
query.timeoutorquery.max-samplessettings in Prometheus if you have admin access.
Too many time series
Error message: exceeded maximum resolution of 11,000 points per timeseries or maximum number of series limit exceeded
Cause: The query is returning more time series or data points than the configured limits allow.
Solution:
- Reduce the time range of your query.
- Add label filters to limit the number of time series returned.
- Increase the Min interval or Resolution in the query options to reduce the number of data points.
- Use aggregation functions to combine time series.
- Adjust the Series limit setting in the data source configuration under Other settings.
Memory limit exceeded for high-cardinality queries
Error messages: “max-estimated-memory-consumption-per-query limit exceeded”, “query requires too much memory”, “max samples limit reached”
Symptom: Queries against high-cardinality metrics (thousands of unique label combinations) over long time ranges (days or weeks) fail with memory or sample limit errors. Short time ranges may work but expanding the range causes the failure.
Cause: Prometheus and Mimir enforce per-query memory and sample limits to protect the system from resource exhaustion. High-cardinality metrics (for example, metrics with a pod,