Add a VictoriaMetrics scrape target
Step-by-step guide for figuring out why a Grafana panel shows "No data" against a VictoriaMetrics-backed cluster, and wiring up a new scrape target once you know why.
Step 1 — Identify what metric the panel actually needs¶
Read the panel's query (expr). Note the exact metric name (e.g. apisix_http_requests_total) — this tells you whether it's:
- A generic Kubernetes metric (
kube_pod_info,kube_pod_status_phase,container_cpu_usage_seconds_total,kubelet_volume_stats_*) — always available viakube-state-metrics/cAdvisor, regardless of the target application. If a panel using one of these shows "No data," the problem is almost always a wrongnamespace=/pod=~filter, not a missing scrape target. - An application-specific metric (a custom prefix like
apisix_*,cnpg_*) — only exists if that application (a) actually exports Prometheus metrics, and (b) something is configured to scrape it.
Step 2 — For application-specific metrics: find the real port and path¶
Don't assume the tool's documented default path is what's actually configured. Check the Service first:
kubectl get svc <service-name> -n <namespace> -o jsonpath='{range .spec.ports[*]}{.name}{"="}{.port}{"\n"}{end}'
Look for a port plausibly named for metrics (prometheus, metrics). Then test the documented default path for that tool:
kubectl port-forward -n <namespace> svc/<service-name> <port>:<port> &
curl -s http://localhost:<port>/<default-metrics-path>
kill %1
If you get a 404, don't conclude the metrics plugin is disabled — check the application's own config first:
Look for whatever field controls the metrics export path (e.g. plugin_attr.prometheus.export_uri). It's common for a metrics exporter to be fully enabled but configured with a non-default path. Retest with the actual configured path before concluding anything is broken.
Step 3 — Confirm the metrics endpoint actually works¶
kubectl port-forward -n <namespace> svc/<service-name> <port>:<port> &
curl -s http://localhost:<port>/<actual-path> | head -20
kill %1
You should see real Prometheus-format output (# HELP ..., # TYPE ..., then metric lines). If this works, the application side is fine — the only missing piece is telling your metrics-scraping operator to actually scrape it.
Step 4 — Identify which scrape-config CRD your stack uses¶
Check your vmagent/vmalert Helm values (or Prometheus Operator values, if that's what you run) for the selector field names:
serviceScrapeSelector/serviceScrapeNamespaceSelector→ you're on the VictoriaMetrics Operator; useVMServiceScrape/VMPodScrape.serviceMonitorSelector→ you're on the Prometheus Operator; useServiceMonitor/PodMonitor.
If the selector fields are empty ({}), your scraper auto-discovers scrape-config objects cluster-wide — you just need to create one, no further registration step needed.
Step 5 — Write the scrape config¶
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMServiceScrape
metadata:
name: <app>-scrape
namespace: <where-your-other-scrape-configs-live, e.g. monitoring>
labels:
app.kubernetes.io/name: <app>
spec:
namespaceSelector:
matchNames:
- <namespace-the-target-service-actually-lives-in>
selector:
matchLabels:
app.kubernetes.io/name: <app>
endpoints:
- port: <the-named-port-from-step-2>
path: <the-real-path-from-step-2>
interval: 30s
Two things worth calling out:
- Follow your repo's existing convention for where scrape configs live. If other scrape configs in your repo live in a shared
monitoringnamespace with anamespaceSelectorpointing at the target's real namespace (rather than living inside the target's own namespace), match that pattern for consistency. - Matching by named port, not raw port number, is a safety feature, not just a preference. If the target's Service has multiple ports and shares its labels with sibling services (e.g. an admin API service with the same
app.kubernetes.io/namelabel as the actual data-plane service), matching by a port name that only the intended metrics endpoint actually has prevents the scrape config from accidentally also trying to scrape an unrelated (and non-Prometheus-format) port.
Step 6 — Apply and verify¶
Wait roughly one scrape interval, then check the panel again.
Common pitfalls¶
- Assuming a 404 on the documented default path means the metrics plugin is disabled — always check the app's actual config for a custom path first.
- Matching scrape targets by bare port number instead of port name, risking an accidental match against an unrelated service port.
- Placing the scrape config object in a namespace inconsistent with the rest of your repo's scrape configs.