Capture application metrics
What you’ll accomplish
Section titled “What you’ll accomplish”Configure Prometheus to scrape metrics from your application using the UDS Package CR’s monitor block. Once configured, your application’s metrics will appear alongside the built-in platform metrics in Prometheus, making them available for dashboards and alerting.
Prerequisites
Section titled “Prerequisites”- UDS CLI installed
- Access to a Kubernetes cluster with UDS Core deployed
- A deployed application that exposes a metrics endpoint (e.g.,
/metrics)
Before you begin
Section titled “Before you begin”UDS Core’s Prometheus instance automatically scrapes metrics from all platform components out of the box. This guide shows how to add your application’s metrics to that collection.
The Package CR monitor block is the UDS-native approach for defining metrics targets. When you specify a monitor entry, the UDS Operator automatically creates the underlying ServiceMonitor or PodMonitor resources and configures the necessary network policies for Prometheus to reach your application’s metrics endpoint.
-
Add a ServiceMonitor via the Package CR
Define a
monitorentry in your Package CR’sspecblock. Theselectorlabels must match the Kubernetes Service that fronts your application, andportNamemust match a named port on that Service.package.yaml apiVersion: uds.dev/v1alpha1kind: Packagemetadata:name: my-appnamespace: my-appspec:monitor:- selector:app: my-appportName: metricstargetPort: 8080Field Description selectorLabel selector matching the Kubernetes Service to monitor portNameNamed port on the Service where metrics are exposed targetPortNumeric port on the pod/container (used for network policy) -
Optional: Use a PodMonitor instead
If your application does not have a Kubernetes Service (e.g., a DaemonSet or standalone pod), use a
PodMonitorby settingkind: PodMonitor. Theselectorlabels must match the pod labels directly.package.yaml apiVersion: uds.dev/v1alpha1kind: Packagemetadata:name: my-appnamespace: my-appspec:monitor:- selector:app: my-appportName: metricstargetPort: 8080kind: PodMonitor -
Optional: Customize the metrics path or add authorization
By default, Prometheus scrapes the
/metricspath. If your application exposes metrics on a different path, or if the endpoint requires authentication, add thepathandauthorizationfields.package.yaml apiVersion: uds.dev/v1alpha1kind: Packagemetadata:name: my-appnamespace: my-appspec:monitor:- selector:app: my-appportName: metricstargetPort: 8080path: "/custom/metrics"description: "My App Metrics"authorization:credentials:key: "token"name: "metrics-auth-secret"optional: falsetype: "Bearer"Field Description pathCustom metrics endpoint path (defaults to /metrics)descriptionOptional label to customize the monitor resource name authorizationBearer token auth using a Kubernetes Secret reference -
Deploy your Package
(Recommended) Include the Package CR in your Zarf package and create/deploy. See Packaging applications for general packaging guidance.
Terminal window uds zarf package create --confirmuds zarf package deploy zarf-package-*.tar.zst --confirmOr apply the Package CR directly for quick testing:
Terminal window uds zarf tools kubectl apply -f package.yamlThe UDS Operator will reconcile the Package CR and create the corresponding
ServiceMonitororPodMonitorresource along with the required network policies.
Verification
Section titled “Verification”Connect to the Prometheus UI to confirm your application target is being scraped:
uds zarf connect prometheusIn the Prometheus UI, navigate to Status > Targets. Your application’s target should appear in the list and show a status of UP.
Success criteria:
- Your application appears as a target in Prometheus
- Target status shows UP
- Metrics from your application are queryable in the Prometheus expression browser
Troubleshooting
Section titled “Troubleshooting”Problem: Target not appearing in Prometheus
Section titled “Problem: Target not appearing in Prometheus”Symptom: Your application does not show up in the Prometheus targets list.
Solution: Verify that the selector labels and portName in your Package CR match the actual Service (or pod) labels and port names. Check that the ServiceMonitor was created:
uds zarf tools kubectl get servicemonitor -AIf using a PodMonitor:
uds zarf tools kubectl get podmonitor -AAlso confirm the Package CR was reconciled successfully:
uds zarf tools kubectl describe package my-app -n my-appProblem: Target shows as DOWN
Section titled “Problem: Target shows as DOWN”Symptom: The target appears in Prometheus but the status is DOWN or shows scrape errors.
Solution: The metrics endpoint is not responding correctly. Verify the port is correct and the application is serving metrics:
uds zarf tools kubectl port-forward -n my-app svc/my-app 8080:8080curl http://localhost:8080/metricsCheck that targetPort matches the actual container port and that path matches the endpoint your application exposes.
Related Documentation
Section titled “Related Documentation”- Prometheus Operator: ServiceMonitor API — full ServiceMonitor field reference
- Prometheus Operator: PodMonitor API — full PodMonitor field reference
Next steps
Section titled “Next steps”These guides may be useful to explore next: