Config promtail mutil logs

Hi everyone, I am currently configuring promtail to receive log from Nginx, mysql, system but it doesn’t work, promtail.yml file information as below, error level=error ts=2023-05-19T19:08:50.715608519Z caller=main.go:170 msg=“error creating promtail” erro r=“failed to make file target manager: pipeline stage must contain only one key” from the reporting container.

promtail.yml

server:
http_listen_port: 9080
grpc_listen_port: 0

positions:
filename: /tmp/positions.yaml

clients: #khai báo link để log từ promtail push tới

scrape_configs:

  • job_name: Log_VPS
    static_configs:

    • targets:

      • localhost
        labels:
        job: Logs_Nginx
        host: VPS
        agent: Log_Nginx
        path: /var/log/nginx/*log
    • targets:

      • localhost
        labels:
        job: Log_Mysql
        host: VPS_mysql
        agent: Log_Mysql
        path: /var/log/mysql/*log
    • targets:

      • localhost
        labels:
        job: Logs_system
        host: system
        agent: Log_system
        path: /var/log/*log

    pipeline_stages:

    • json:
      expressions:
      http_user_agent:
      request_uri:
    • drop:
      source: http_user_agent
      expression: “(bot|Bot|RSS|Producer|Expanse|spider|crawler|Crawler|Inspect|test)”
    • drop:
      source: request_uri
      expression: “/(assets|img)/”
    • drop:
      source: request_uri
      expression: “/(robots.txt|favicon.ico|index.php)”
    • drop:
      source: request_uri
      expression: “(.php|.xml|.png)$”

docker-compose.yml

version: ‘3.8’

networks:
monitoring:
driver: bridge

volumes:
prometheus_data: {}
grafana_data: {}

grafana-logs: {}

services:
node-exporter:
image: prom/node-exporter
container_name: node-exporter
restart: unless-stopped
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- ‘–path.procfs=/host/proc’
- ‘–path.rootfs=/rootfs’
- ‘–path.sysfs=/host/sys’
- ‘–collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)’
ports:
- “9100:9100”
expose:
- 9100
networks:
- monitoring

prometheus:
image: prom/prometheus
container_name: prometheus
restart: unless-stopped
volumes:
- ./config/prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- ‘–config.file=/etc/prometheus/prometheus.yml’
- ‘–storage.tsdb.path=/prometheus’
- ‘–web.console.libraries=/etc/prometheus/console_libraries’
- ‘–web.console.templates=/etc/prometheus/consoles’
- ‘–web.enable-lifecycle’
ports:
- “9090:9090”
expose:
- 9090
networks:
- monitoring

grafana:
image: grafana/grafana:latest
container_name: grafana
volumes:
- grafana_data:/var/lib/grafana

- ./config/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml

ports:
  - "3000:3000"
networks:
  - monitoring

#Loki-Promtail (Log)
promtail:
image: grafana/promtail
restart: always
container_name: promtail
volumes:
- ./loki/promtail.yml:/etc/promtail/config.yml
- /var/log:/var/log
- /var/log/mysql:/var/log/mysql
- /var/log/nginx:/var/log/nginx
entrypoint:
- /usr/bin/promtail
- -config.file=/etc/promtail/config.yml
ports:
- “9080:9080”
networks:
- monitoring

loki:
container_name: loki
image: grafana/loki
restart: always
volumes:
- ./loki/data:/loki
- ./loki/loki.yml:/etc/loki/local-config.yaml
entrypoint:
- /usr/bin/loki
- -config.file=/etc/loki/local-config.yaml
ports:
- “3100:3100”
networks:
- monitoring

As the error message pointed out, each file target should have their own pipeline stage. You can find example on the github repo such as this: grafana-loki/promtail-examples.md at master · jafernandez73/grafana-loki · GitHub