Promtail configuration for haproxy logs

I am sending logs to loki using promtail . For Haproxy logs i need to parse and fetch labels such as Status code, Client Ip etc. I am using this configuration for promtail but it is not working

  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

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

scrape_configs:
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: haproxy
      __path__: /var/log/haproxy/haproxy.log
  pipeline_stages:
  - match:
      - selector: '{job="haproxy"}'
        stages:
        - regex:
            expression: '^(?<c_ip>[\w\.]+):(?<c_port>\d+) \[(?<time>.+)\] (?<f_end>[\w\~\-]+) (?<b_end>[\w-]+)\/(?<b_server>[<>\w\.-]+) (?<tq>[\d\-]+)\/(?<tw>[\d\-]+)\/(?<tc>[\d\-]+)\/(?<tr>[\d\-]+)\/(?<tt>[\d\-]+) (?<status_code>\d+) (?<bytes>\d+) (?<req_cookie>\S?) 
(?<res_cookie>\S?) (?<t_state>[\w\-]+) (?<actconn>\d+)\/(?<feconn>\d+)\/(?<beconn>\d+)\/(?<srv_conn>\d+)\/(?<retries>\d+) (?<srv_queue>\d+)\/(?<backend_queue>\d+) \{?(?<req_headers>[^}"]*)\}? ?"(?<request>[^"]*)"'
        - labels:
            c_ip:

Log Examples

192.168.25.38:57356 [04/Aug/2021:07:23:26.480] http_front artifact_backend/artifact01 0/0/0/2/2 404 232 - - ---- 13/13/0/0/0 0/0 {Artifactory/6.1.0} "HEAD /artifactory/all-repos/com/xyz/log-processor/1.0.0-SNAPSHOT/maven-metadata.xml HTTP/1.1"

192.168.25.38:60428 [04/Aug/2021:07:23:25.187] http_front ci_cluster/ci01 0/0/1/1/2 403 915 - - ---- 13/13/0/0/0 0/0 {Go-http-client/1.1} "GET / HTTP/1.1"

Kindly help me to solve this by fixing it and creating the right config.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.