Problem
I want Prometheus to scrape a Java spring boot app in a K8s cluster. I have setup the config properly it seems, yet the UI page shows the service as "undefined":
Observations:
- Clicking on the undefined "show more" button in the UI shows
__tmp_prometheus_job_name="serviceMonitor/default/java-server-prom-monitoring/0"
. - The Target list page does not have the my new service monitor at all, although the service discovery page does
- I confirmed that the configuration page includes updated information about the java server underneath
scrape_configs
:
scrape_configs:
- job_name: serviceMonitor/default/java-server-prom-monitoring/0
honor_timestamps: true
scrape_interval: 30s
scrape_timeout: 10s
metrics_path: /actuator/prometheus
scheme: http
follow_redirects: true
enable_http2: true
relabel_configs:
- source_labels: [job]
separator: ;
regex: (.*)
target_label: __tmp_prometheus_job_name
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_service_label_app, __meta_kubernetes_service_labelpresent_app]
separator: ;
regex: (java-server);true
replacement: $1
action: keep
- I confirmed that the prometheus config file has
prometheus
as itsrelease
, and tried everything from this SO answer
Configuration File
apiVersion: v1
kind: Service
metadata:
name: java-server-ip-service
spec:
selector:
app: java-server
ports:
- name: http-traffic
protocol: TCP
port: 8080
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: java-server
labels:
release: prometheus
spec:
replicas: 1 # number of replicas
selector:
matchLabels:
app: java-server
template:
metadata:
labels:
app: java-server
spec:
containers:
- name: java-server
image: prometheusdemo/java-server # specify your react image and tag
imagePullPolicy: Never
ports:
- containerPort: 8080 # container will listen here. should correspond to targetPort defined in service.
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: java-server-prom-monitoring
labels:
release: prometheus
namespace: default
spec:
selector:
matchLabels:
app: java-server
release: prometheus
endpoints:
- port: http-traffic
path: "/actuator/prometheus"
Info
- using the helm chart
kube-prometheus-stack-45.20.0
from the prometheus-community repo - using
kubectl
Client Version: v1.25.4
How can I get prometheus to connect to the java-server deployment?