Is there a way for promtail to add a line number as a tag in loki log extractor?

36 Views Asked by At

I have a system that collects logs from several systems.

When the line is tagged as error, (because it contains loglevel=Error) i might want to look at the original file, however finding the location in the logfile is a nuisance.

-Finding by time, the time format on the logfile is different from loki explorer, so i have to change it anyway.

Can i add the line number as a tag? or is there an other good way..

My promtail config.yaml looks something like this:

server:
...
positions:
#last position send:yaml 
  filename: ./positions.yaml

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

scrape_configs:
  - job_name: mylogs
    static_configs:
      - targets:
          - localhost
        labels:
          job: myslogs
          __path__: "\\sharedlocation\app\logfiles\*.log"
    pipeline_stages:
     - regex:
         expression: '^(?P<timestamp>\d{4}\/\d{2}\/\d{2}.\d{2}:\d{2}:\d{2}\.\d{4}).(?P<hostname>\S+)\t(?P<loglevel>\S+)\t(?P<message>.*)$'
     - multiline:
         firstline: '^\d{4}\/\d{2}\/\d{2}.\d{2}:\d{2}:\d{2}\.\d{4}.'
         max_lines: 512
     - timestamp:
         format: '2006/01/02 15:04:05.0000'
         source: timestamp
     - labels:
         hostname:
         program:
         service:
         level: level
     - output:
         source: message

how can i a a line number of the logfile?

I am not sure how to add tags that are not litterary in the logfile.

https://grafana.com/docs/loki/latest/send-data/promtail/stages/ in the metrics there is something as a counter defined, but that is accesable only as a metric.

0

There are 0 best solutions below