Grafana does not see loki (docker-compose setup)
Asked Answered
G

2

7

I am trying to log my application into grafana/loki/promtail using the same docker compose ,and I get the following error when connecting to loki :

localhost:3100 -> 404 page not found

and when i try to hook it in grafana :

URL [http://loki:3100 ]-> Loki: Bad Gateway. 502. Bad Gateway

I have seen that you have to put in grafana the name of the container for it to detect it but I get the same error.

Both promtail and loki containers show no errors in their logs.

version: "3.7"

services:   
my-service-to-log:
    image: example:latest
    ports:
      - "8080:8080"
      - "8443:8443"
 loki:
    image: grafana/loki:2.4.1
    ports:
      - "3100:3100"
    volumes:
      - "C:/path/loki-config.yaml:/etc/loki/local-config.yaml"
    command: -config.file=/etc/loki/local-config.yaml

   promtail:
    image: grafana/promtail:2.4.1
    volumes:
      - "C:/path/promtail-config.yaml:/etc/promtail/config.yml"
      - /var/log:/var/log
    command: -config.file=/etc/promtail/config.yml

   grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"

My loki-config.yaml

auth_enabled: false

server:
  http_listen_port: 3100
  grpc_listen_port: 9096

common:
  path_prefix: /tmp/loki
  storage:
    filesystem:
      chunks_directory: /tmp/loki/chunks
      rules_directory: /tmp/loki/rules
  replication_factor: 1
  ring:
    instance_addr: 127.0.0.1
    kvstore:
      store: inmemory

schema_config:
  configs:
    - from: 2020-10-24
      store: boltdb-shipper
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 24h

ruler:
  alertmanager_url: http://localhost:9093

And my promtail-config.yaml

server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

clients:
  - url: http://loki:3100/loki/api/v1/push

scrape_configs:
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      __path__: /opt/app/logs/*.log
/ # nc -vz localhost 3100
localhost (127.0.0.1:3100) open

I have tried to nc from the grafana container to the loki container and it seems to see it .... any ideas ?

Gastrula answered 25/1, 2022 at 19:23 Comment(2)
What problem are you facing? Are you unable to add loki as a datasource in grafana?Zenithal
What does your grafana config look like? You need to add Loki as a data source in the grafana.iniDahlberg
W
1

Loki needs to listen on all interfaces, not just localhost, when you want to access it from another container:

common:
  path_prefix: /tmp/loki
  storage:
    filesystem:
      chunks_directory: /tmp/loki/chunks
      rules_directory: /tmp/loki/rules
  replication_factor: 1
  ring:
    instance_addr: 0.0.0.0
    kvstore:
      store: inmemory
Wooster answered 10/2, 2022 at 17:26 Comment(0)
S
0

When adding Loki as a datasource in Grafana, instead of http://localhost:3100, use an ip address your computer has, instead of localhost. Example http://LAN_IP_ADDR:3100

Substantiate answered 10/3, 2022 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.