| name | explore-datasources |
| description | Discover what datasources, metrics, labels, and log streams are available in a Grafana instance. Use when the user asks what data exists, what metrics are available, what services are being monitored, or needs to find a datasource UID. |
Datasource Discovery
If gcx is not configured, see the setup-gcx skill first.
Instructions
Step 1: List Available Datasources
Start by identifying all datasources in the Grafana instance.
gcx datasources list
gcx datasources list --type prometheus
gcx datasources list --type loki
Expected output: Table showing UID, NAME, TYPE, URL, and DEFAULT columns.
Important: Always use the UID (not the name) in subsequent commands.
Step 2: Explore Datasource Contents
Choose the appropriate exploration path based on datasource type.
For Prometheus Datasources
gcx metrics labels -d <datasource-uid>
gcx metrics labels -d <datasource-uid> --label job
gcx metrics metadata -d <datasource-uid>
gcx metrics query -d <datasource-uid> 'up'
Expected output: Tables showing labels, metrics, or query results depending on command.
For Loki Datasources
gcx logs labels -d <datasource-uid>
gcx logs labels -d <datasource-uid> --label job
gcx logs series -d <datasource-uid> -M '{job="varlogs"}'
Expected output: Tables showing labels or log stream series.
Note: The series command requires at least one -M (match) selector using LogQL syntax.
Step 3: Test Queries (Optional)
Once you've identified available data, verify with a test query.
gcx metrics query -d <datasource-uid> 'up'
gcx metrics query -d <datasource-uid> 'rate(http_requests_total[5m])' --from now-1h --to now
Expected output: Table showing metric values with labels and timestamps.
Step 4: Set Default Datasource (Optional)
To avoid passing -d <uid> repeatedly, configure defaults:
gcx config set contexts.<context-name>.default-prometheus-datasource <uid>
gcx config set contexts.<context-name>.default-loki-datasource <uid>
After setting defaults, you can omit the -d flag in datasource commands.
Examples
Example 1: Finding HTTP metrics
User says: "What HTTP metrics are available?"
Actions:
- List Prometheus datasources:
gcx datasources list --type prometheus
- Get datasource UID from output
- Search for HTTP metrics:
gcx metrics metadata -d <uid> -o json 2>/dev/null | python3 -c "import json,sys; d=json.load(sys.stdin)['data']; [print(k,d[k][0]['type'],d[k][0]['help']) for k in sorted(d) if 'http' in k]"
- Get details on specific metric:
gcx metrics metadata -d <uid> --metric http_requests_total
Result: Metric name, type (counter/gauge), and help text showing what the metric measures.
Example 2: Discovering which services are logging to Loki
User says: "What applications are sending logs to Loki?"
Actions:
- List Loki datasources:
gcx datasources list --type loki
- Get datasource UID from output
- List label names:
gcx logs labels -d <uid>
- Get job values:
gcx logs labels -d <uid> --label job
- List streams for a specific job:
gcx logs series -d <uid> -M '{job="varlogs"}'
Result: List of job names and their associated log streams.
Example 3: Troubleshooting missing dashboard data
User says: "My dashboard shows no data for service X"
Actions:
- Verify datasource exists:
gcx datasources get <uid>
- Check if service is being monitored:
- Prometheus:
gcx metrics query -d <uid> 'up{job="service-x"}'
- Look for service in scrape results
- Verify labels exist:
gcx metrics labels -d <uid> --label job
- Test simple query:
gcx metrics query -d <uid> 'up{job="service-x"}'
Result: Identifies whether datasource is misconfigured, service isn't being scraped, or label selectors are wrong.
Example 4: Finding logs for a specific namespace
User says: "Show me all log streams from the production namespace"
Actions:
- Get Loki datasource UID:
gcx datasources list --type loki
- Verify namespace label exists:
gcx logs labels -d <uid> --label namespace
- List all streams in namespace:
gcx logs series -d <uid> -M '{namespace="production"}'
Result: Table showing all label combinations for log streams in the production namespace.
Troubleshooting
Error: "datasource UID is required"
Cause: The -d flag was omitted and no default datasource is configured.
Solution:
gcx metrics labels -d <datasource-uid>
gcx config set contexts.<context-name>.default-prometheus-datasource <uid>
Error: "at least one --match selector is required"
Cause: The loki series command was called without a -M flag.
Solution: Loki series requires at least one LogQL selector:
gcx logs series -d <uid> -M '{job="varlogs"}'
gcx logs series -d <uid>
Error: "parse error on line 1, column X: bare " in non-quoted-field"
Cause: Shell is interpreting quotes in the LogQL selector incorrectly.
Solution: Use single quotes around the entire selector:
gcx logs series -d <uid> -M '{name="value", cluster="prod"}'
gcx logs series -d <uid> -M {name="value"}
Error: "datasource.prometheus.datasource.grafana.app "" not found"
Cause: The datasource UID doesn't exist or you don't have access to it.
Solution:
- List datasources to verify UID:
gcx datasources list
- Check you're using the correct context:
gcx config current-context
- Verify datasource exists:
gcx datasources get <uid>
No output from labels/series commands
Cause: Datasource has no data or hasn't scraped/ingested anything yet.
Solution:
- For Prometheus: Check targets are active:
gcx metrics query -d <uid> 'up'
- For Loki: Verify labels exist:
gcx logs labels -d <uid>
- Check datasource URL is reachable:
gcx datasources get <uid>
Advanced Usage
For detailed patterns, LogQL syntax guide, and advanced discovery workflows, see:
Output Formats
All commands support -o json or -o yaml for programmatic use:
gcx metrics labels -d <uid> -o json
gcx metrics metadata -d <uid> -o json 2>/dev/null | python3 -c "import json,sys; print(len(json.load(sys.stdin)['data']))"
Default output is table format for human readability.