Prometheus Stack Operator Not Scraping Metrics of Cluster Application

Abstract: Resolve Prometheus Stack Operator scraping failures by fixing ServiceMonitor label mismatches, port name errors, and NetworkPolicy blocks.

Created: 2026-09-21 by
The Prometheus Stack Operator fails to scrape cluster application metrics when ServiceMonitor resources are misconfigured, network policies block traffic, or the target pods lack proper annotations. This issue prevents visibility into application performance and can lead to silent failures in production environments. Resolving this requires verifying the ServiceMonitor selector matches the target Service labels, ensuring the correct port name is defined in the Service spec, and confirming that the Prometheus server has network access to the pod endpoints.

Verifying ServiceMonitor Configuration

The most common cause for scraping failures is a mismatch between the ServiceMonitor resource and the Kubernetes Service it attempts to monitor. The ServiceMonitor acts as a bridge, telling the Prometheus operator which services to watch and how to reach them. If the selector does not match the labels on the Service, or if the port name is incorrect, Prometheus will silently ignore the target. To diagnose this, first check the ServiceMonitor definition using kubectl get servicemonitor -n monitoring. Examine the spec.selector.matchLabels field. These labels must exactly match the labels applied to the Kubernetes Service you intend to monitor. For example, if your Service has the label app: my-app, the ServiceMonitor selector must include app: my-app. A single typo here will result in zero targets being discovered. Next, inspect the spec.endpoints section of the ServiceMonitor. Ensure the port field references a named port in the Service definition. Kubernetes Services expose ports by name, not just by number. If the Service defines a port named http-metrics, the ServiceMonitor endpoint must specify port: http-metrics. Using the numeric port value directly in the ServiceMonitor is not supported in standard configurations and will lead to discovery errors. You can also verify the Service itself with kubectl get service -n <namespace>. Look at the PORT(S) column. Confirm that the port name listed there matches what you expect. If the Service exposes port 8080 but names it web, your ServiceMonitor must use port: web. This naming convention is strict and does not allow for ambiguity.

Checking Network Policies and Pod Accessibility

Even with perfect configuration, network restrictions can prevent the Prometheus server from reaching the application pods. In modern Kubernetes clusters, NetworkPolicies are often enabled by default to restrict traffic flow. If a NetworkPolicy exists in the namespace where your application runs, it might be blocking incoming connections from the Prometheus namespace. Review any NetworkPolicies in the application namespace using kubectl get networkpolicy -n <application-namespace>. Check the ingress rules to see if they allow traffic from the Prometheus server pods. The Prometheus server typically runs in a dedicated namespace like monitoring or prometheus. You may need to add an ingress rule that allows traffic from pods with the label app.kubernetes.io/name: prometheus in the monitoring namespace. If no explicit NetworkPolicy is found, consider the default behavior. Some clusters have a default deny-all policy for ingress traffic. In such cases, all incoming traffic is blocked unless explicitly allowed. You can test connectivity by port-forwarding from your local machine to the Prometheus server and checking the targets page. If the targets show as "Down" with a connection timeout error, it strongly suggests a network-level block rather than a configuration error. For a deeper dive into repairing Prometheus configurations, you might find The Prometheus Repair Process: A Comprehensive Guide helpful for understanding broader system integrity checks.

Validating Target Discovery via Prometheus UI

The Prometheus UI provides the most direct evidence of what is happening during the scraping process. Navigate to the Prometheus admin interface, usually accessible via port-forwarding or an Ingress resource. Go to the Status menu and select Targets. This page lists all discovered endpoints and their current health status. Look for your application’s targets. They should appear under the job name defined in your ServiceMonitor. If the targets are missing entirely, the issue lies in service discovery, meaning the ServiceMonitor selector or Service labels are mismatched. If the targets appear but show a state of DOWN, examine the last error message displayed. Common errors include context deadline exceeded (timeout) or connection refused (service not listening). A timeout often indicates that the Prometheus server cannot reach the pod IP, pointing back to network policies or DNS issues. A connection refused error means the pod is reachable, but the application is not listening on the specified port or the port name is wrong. Click on the individual target instance to see detailed scrape logs. This will show the exact HTTP request made and the response received, helping you determine if the application is returning valid metrics in the expected format. If you are dealing with complex routing issues involving external access, reviewing Kubectl Ingress: A Comprehensive Guide for Tech Support can help ensure your ingress controllers are not interfering with internal service discovery.

Ensuring Correct Annotations on Application Pods

While less common with the Stack Operator, which relies heavily on ServiceMonitors, some setups require specific annotations on the application pods themselves. The Prometheus operator uses these annotations to identify metric endpoints if automatic discovery is not fully configured. Check the pod template in your Deployment or StatefulSet. Look for annotations starting with prometheus.io/. Specifically, check for prometheus.io/scrape, which should be set to true, and prometheus.io/port, which should match the container port. However, note that the Stack Operator primarily uses ServiceMonitors for service-based discovery. If you are using ServiceMonitors, these pod annotations are often redundant. But if you have switched to pod-level discovery, ensure these annotations are present and correctly formatted. Verify that the application container is actually exposing metrics. Many applications only expose metrics on specific paths, such as /metrics or /health. If the application serves metrics on a different path, you must configure the path field in the ServiceMonitor endpoint. The default path is usually /metrics, but custom applications may vary.

Conclusion

Resolving Prometheus scraping issues involves a systematic approach: verify label matching, confirm port names, check network policies, and inspect the Prometheus UI for error details. By carefully aligning the ServiceMonitor configuration with the Kubernetes Service and ensuring network accessibility, you can restore full visibility into your cluster applications. Regularly checking the Targets page helps catch these issues early before they impact alerting and dashboards.

Frequently Asked Questions

Why do my Prometheus targets show as Down instead of Up?

Targets show as Down when the Prometheus server cannot successfully scrape the endpoint within the configured timeout period. This is often caused by network policies blocking traffic, incorrect port numbers, or the application failing to respond to health checks. Check the last error message in the Prometheus UI for specific clues like timeouts or connection refusals.

How do I find the correct port name for my ServiceMonitor?

Run kubectl get service <service-name> -n <namespace> and look at the PORT(S) column. The name listed after the port number (e.g., 8080:TCP/http-metrics) is the name you must use in the ServiceMonitor's port field. Do not use the numeric port value directly in the ServiceMonitor configuration.

Can I use Prometheus without the Stack Operator?

Yes, you can run vanilla Prometheus outside of the Stack Operator, but you lose the automated ServiceMonitor reconciliation. Without the operator, you must manually manage Prometheus configurations and reloads. The Stack Operator simplifies this by watching Kubernetes resources and updating the Prometheus config automatically.

What causes a context deadline exceeded error in Prometheus?

This error typically indicates a network timeout, meaning the Prometheus server could not establish a connection to the target pod within the scrape interval. It often points to restrictive NetworkPolicies, DNS resolution failures, or the target pod being stuck in a CrashLoopBackOff state. Verify that the target pod is running and accepting connections.

How can I test if my application is exposing metrics correctly?

Use kubectl port-forward <pod-name> <local-port>:<container-port> to forward traffic locally. Then, use curl localhost:<local-port>/metrics to see if the metrics output is returned in the correct Prometheus text format. If curl returns HTML or an error, the application is not serving metrics at that path.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More