Prometheus monitoring webservers

28 views Asked by At

I want to receive and analyze metrics using Prometheus from the endpoint provided by Spring Boot app. Both of them run in docker using docker compose. I want Prometheus to go to backend endpoint {ip}:{port}/metrics/apps and get the metrics. I couldn't find reasonable info about how to do it correctly, and whether I really need to use node exporter or not. prometheus.yml

global:
  scrape_interval: 20s
  evaluation_interval: 20s
  scrape_timeout: 10s
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: [ '127.0.0.1:9090' ]
  - job_name: 'apps'
    metrics_path: "/metrics/apps"
    static_configs:
      - targets: [ "host.docker.internal:8080" ]
  - job_name: 'scheduler'
    metrics_path: "/metrics/scheduler"
    static_configs:
      - targets: [ "host.docker.internal:8080" ]

compose.yml

services:
  backend:
    image: myimage
    ports:
      - 8080:8080
    deploy:
      resources:
        limits:
          cpus: "2"
          memory: 200M
        reservations:
          cpus: "1"
          memory: 50M
  prometheus:
    image: prom/prometheus:latest
    ports:
      - 9090:9090
    volumes:
      - "./prometheus.yml:/etc/prometheus/prometheus.yml"

Dockerfile

FROM runtime-image:java17-alpine-tools

COPY target/my-app-0.0.1-SNAPSHOT.jar .

EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "my-app-0.0.1-SNAPSHOT.jar" ]

Controller.java annotated with @RestController

@GetMapping("/metrics/apps")
    public ResponseEntity<String> convertAppMetrics() throws JAXBException {
        return ResponseEntity.ok("apps{id=\"1\"}");
    }

When I get inside prometheus container and run wget http://{ip}:{port}/metrics/apps or wget host.docker.internal:{port}/metrics/apps I get the data correctly, however the purpose is to delegate it to Prometheus.

When I go to prometheus ui, I see that it didn't scrap anything ( see attachment ).

Tried to specify directly ip of backend instead of host:internal:docker

0

There are 0 answers