Data Sources (Prometheus)
Connect Grafana with Prometheus, validate queries, and troubleshoot common datasource issues.
Simple Explanation (ELI5)
Grafana needs a data source to draw charts. Prometheus is the most common one for metrics. Connect once, then all panels can query it.
Technical Explanation
A Grafana Prometheus datasource points to the Prometheus base URL. Grafana sends PromQL queries to that endpoint and renders results. In Kubernetes, this URL is often a service DNS name in the monitoring namespace.
Visual Section
Hands-on Commands
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus-server.monitoring.svc.cluster.local:9090
isDefault: true# Prometheus health check curl http://prometheus-server.monitoring.svc.cluster.local:9090/-/ready # Grafana health check curl http://localhost:3000/api/health # Kubernetes port-forward test kubectl -n monitoring port-forward svc/prometheus-server 9090:9090
Debugging Scenarios
- Datasource test fails: URL unreachable, DNS issue, network policy, or auth mismatch.
- No metrics in Grafana but Prometheus has data: wrong datasource selected in panel.
- Intermittent query errors: Prometheus overload or long query timeout.
Real-world Use Case
A team connects Grafana to HA Prometheus and uses one default datasource across all service dashboards for consistent metrics access.
Interview Questions
Beginner
A configured backend Grafana queries for visualization and alerts.
Prometheus provides time-series metrics that Grafana visualizes.
HTTP/HTTPS to the Prometheus API endpoint.
Validates datasource connectivity and basic query capability.
Yes, panels can point to different data sources.
Intermediate
Use provisioning files under Grafana provisioning/datasources.
Proxy mode routes queries via Grafana server; direct mode uses browser-to-datasource path.
To prevent unauthorized query access and accidental exposure.
Use service DNS names and namespace-aware endpoints.
Measure query response times and panel render durations.
Scenario-based
Grafana server network path differs from your laptop path.
Check panel datasource selection, time range, and variable filters.
Configure proper CA cert/auth settings and endpoint URL.
Use datasource variables and environment-specific provisioning.
Heavy PromQL queries, large time windows, and frequent refresh.
Summary
Prometheus integration is the foundation of practical Grafana usage. If datasource setup is solid, dashboard development becomes reliable and fast.