Denis
Denis

Reputation: 11

How to add springboot application monitoring to prometheus in Kubernetes?

Good afternoon everyone, I have a question about adding monitoring of the application itself to prometheus. I am using spring boot actuator and see the values for prometheus accordingly: https://example.com/actuator/prometheus I have raised prometheus via the default helm chart ( helm -n monitor upgrade -f values.yaml pg prometheus-community/kube-prometheus-stack )by adding default values for it:

additionalScrapeConfigs:
  job_name: prometheus
  scrape_interval: 40s
  scrape_timeout: 40s
  metrics_path: /actuator/prometheus
  scheme: https

Prometheus itself can be found at http://ex.com/prometheus The deployment.yaml file of my springboot application is as follows:

apiVersion : apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
      annotations:
        prometheus.io/path: /actuator/prometheus
        prometheus.io/scrape: "true"
        prometheus.io/port: "8080"
    spec:
      containers:
      - env:
        - name: DATABASE_PASSWORD
          value: {{ .Values.DATABASE_PASSWORD }}
        - name: DATASOURCE_USERNAME
          value: {{ .Values.DATASOURCE_USERNAME }}
        - name: DATASOURCE_URL
          value: jdbc:postgresql://database-postgresql:5432/dev-school
        name : {{ .Release.Name }}
        image: {{ .Values.container.image }}
        ports:
        - containerPort : 8080

However, after that prometheus still can't see my values. Can you tell me what the error could be?

Upvotes: 1

Views: 1512

Answers (1)

YwH
YwH

Reputation: 1150

In prometheus-operator,

additionalScrapeConfigs is not used in this way.

According to documentation Additional Scrape Configuration: AdditionalScrapeConfigs allows specifying a key of a Secret containing additional Prometheus scrape configurations.

The easiest way to add new scrape config is to use a servicemonitor, like the example below:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: example-app
  labels:
    team: frontend
spec:
  selector:
    matchLabels:
      app: backend
  endpoints:
  - port: web

Upvotes: 3

Related Questions