Raman
Raman

Reputation: 35

How to extract log level using prom tail scrape_configs

I have multiple pods in cluster and Promtail is configured as DaemonSet to pump logs to Loki. but not sure how to create extra label for log level from specific pod logs to query in grafana.

Logs from pods:

[2021-12-14 11:11:11] INFO forcetask[id=pod-0] message2
[2021-12-14 11:11:11] INFO forcetask[id=pod-0] message1

but output when query {app="loki"} in Grafana

{log="[2021-12-14 11:11:11] INFO forcetask[id=pod-0] message2", stream="stdout", timestamp ="..."}
{log="[2021-12-14 11:11:11] ERROR forcetask[id=pod-0] Error1", stream="stderr", timestamp="..."}

I have configured scrape_congs on Promtail as below but no luck. Can someone please point me what am I missing here?

scrape_configs:
- job_name: my-custom-labels
  pipeline_stages:
  - docke: {}
  - json:
      log: log
      stream: stream
      timestamp: timestamp
  - labels: 
       log:
  - match:
      selector: '{app="loki"}'.    -- this is one of the labels of Loki instance 
      stages:
      - regex: 
          expression: '\\[(?P<timestamp>\\d{4}-\\d{2}-\\d{2}\\s\\d{2}:\\d{2}:\\d{2})\\]\\s(?P<level>\\w+)\\s(?P<message>.*)'
      - labels:
          level:
      - timestamp:
          format: RFC3339Nano
          source: timestamp

Upvotes: 0

Views: 3355

Answers (1)

Roman Plevka
Roman Plevka

Reputation: 1

I'd say that your expression is not matching because you double-escape while using single quotes. Either try to to get rid of the double escapes or use double quotes.

Upvotes: 0

Related Questions