2

First of all I tried this solution didn't work for me.

I need to log some custom metrics using Prometheus.

docker-compose.yml

version: "3"
volumes:
  prometheus_data: {}
  grafana_data: {}
services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    hostname: my_service
    ports:
      - 9090:9090
    depends_on:
      - my_service
  my-service:
    build: .
    ports:
      - 8080:8080
  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    hostname: grafana
    ports:
      - 3000:3000
    depends_on:
      - prometheus

prometheus.yml

global:
  scrape_interval: 5s
  scrape_timeout: 10s
  external_labels:
    monitor: 'my-project'
rule_files:
scrape_configs:
  - job_name: myapp
    scrape_interval: 10s
    static_configs:
      - targets:
          - my_service:8080

I tried external ip as well, but i can't see my metrics in prometheus UI. Also, the target page is showing localhost:9090 is up.

What could be the problem? Can anyone correct the docker compose and prometheus file?

Thanks

jinxankit
  • 21
  • 6

1 Answers1

0

So I found it. I have to set my scrape configs with the container name. something like this

scrape_configs:
  - job_name: my-service
    scrape_interval: 15s
    scrape_timeout: 10s
    metrics_path: /metrics
    static_configs:
      - targets:
          - 'prometheus:9090'
          - 'my-service:8080'

Once you fix your Prometheus volumes to your data, you will see your service is up and running at http://localhost:9090/targets

jinxankit
  • 21
  • 6