0

Am I missing something ?

I'm new to Prometheus, Trying to monitor a service, I followed the doc as it is, however when I run prometheus to supervise my springboot application it shows me always that its status is down :

enter image description here

when I get : http://localhost:8080/prometheus

enter image description here

that's the docker-compose I'm using:

version: '3.8'

services:
  prometheus:
    image: prom/prometheus:v2.33.1
    container_name: prometheus
    ports:
      - 9090:9090
    volumes:
      - ./prometheus.yaml:/etc/prometheus/prometheus.yml:ro

  grafana:
    image: grafana/grafana:8.2.2
    container_name: grafana
    ports:
      - 3000:3000
    environment:
      - GF_INSTALL_PLUGINS=grafana-piechart-panel
    volumes:
      - grafana_data:/var/lib/grafana

volumes:
  grafana_data:

and the Prometheus.yaml file :

global:
  scrape_interval:     15s
  evaluation_interval: 15s

  external_labels:
      monitor: 'codelab-monitor'

rule_files:

scrape_configs:
  - job_name: 'prometheus'

    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'spring-boot-app'

    scrape_interval: 5s

    metrics_path: '/prometheus'

    static_configs:
      - targets: ['localhost:8080']

Am I missing something ?

docker inspect network of Prometheus and Grafana network

docker inspect prometheus-grafana_default
[
    {
        "Name": "prometheus-grafana_default",
        "Id": "b3396f20e2d469f2b58cae086c744d7dd2fa762739e78d184da210ce39d4f76b",
        "Created": "2023-05-05T11:48:40.775115395Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "b997dabca9a209a74e604439a579635a1a396469077bcb6c77c5c155a8658115": {
                "Name": "prometheus-grafana-prometheus-1",
                "EndpointID": "a01a7c0001aa8159a1844d7bf63788f774480fbf19318e29ae349f97ff36564e",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "dc68bc1b86be8e3b4b97553f0e44b7984914dc41d81f1bed667a33a9faca8d40": {
                "Name": "prometheus-grafana-grafana-1",
                "EndpointID": "e56f01bb9b2c66fbdc6b4c51cccb26c99b7c6b1fd60f785d8808178de5655322",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "prometheus-grafana",
            "com.docker.compose.version": "2.10.2"
        }
    }
]
Bihi23
  • 66
  • 6
  • i tried to expose it using ngrok but still displaying service down – Bihi23 May 05 '23 at 12:48
  • Your containers should be in the same network,check that. – Richard Rublev May 05 '23 at 13:16
  • @RichardRublev is it necessary since the scrapper reads from localhost:8080/prometheus xxxxxx.ngrok.app/prometheus after exposing the app into ngrok, so why it is necessary ? – Bihi23 May 05 '23 at 13:20
  • To make containers discoverable,try to inspect your network. – Richard Rublev May 05 '23 at 13:43
  • Show us docker network inspect output. – Richard Rublev May 05 '23 at 13:44
  • 1
    I updated the question wirh docker inspect that network but the application is out of the compose – Bihi23 May 05 '23 at 14:04
  • 1
    If prometheus is running in a container, then your scrape url of `http://localhost:8080` is almost guaranteed to be incorrect. Unless your service is running in the same container as prometheus it's not available at `localhost`. You need to provide the appropriate hostname or address for this service. – larsks May 05 '23 at 14:08
  • what does curl -I 172.18.0.2 from your terminal show? – Richard Rublev May 05 '23 at 14:35
  • 1
    You have incorrect scrape config: [localhost in this case wouldn't work.](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – markalex May 05 '23 at 14:49
  • Does this answer your question? [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – markalex May 08 '23 at 06:38

0 Answers0