3

I've created some monitoring with grafana, loki and promtail. The container i'm getting the logs from outputs them in JSON format i.e.

{"level":"info","ts":"2022-02-17T01:12:50.304Z","logger":"balance_log","caller":"services/balance_monitor.go:122","msg":"New ETH balance for 0x00: 50.492508167015966629","evmChainID":"137","address":"0x00","ethBalance":"50.492508167015966629","weiBalance":"50492508167015966629"}
{"level":"info","ts":"2022-02-17T01:19:35.350Z","logger":"DirectRequest.DirectRequest","caller":"directrequest/delegate.go:280","msg":"Oracle request received","contract":"0x00","jobName":"","jobID":0,"externalJobID":"b93c6769-1bd4-474b-9a01-e8ada08825f7","specId":"0000","requester":"0x00","requestId":"000","payment":"1500000000000000","callbackAddr":"0x00","callbackFunctionId":"4357855e","cancelExpiration":"1645061075","dataVersion":"1","data":"000"}

Currently grafana will display the table named log with the content as string i.e. :

"log": "{\"level\": \"info\"....

What would be the correct way to set-up the promtail config so that I can get all data formated for use in the table view?

This is what I currently have:

server:
  http_listen_address: 0.0.0.0
  http_listen_port: 9080

positions:
  filename: /tmp/positions.yaml

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

scrape_configs:

- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      __path__: /var/log/*log

- job_name: containers
  entry_parser: raw

  static_configs:
  - targets:
      - localhost
    labels:
      job: containerlogs
      __path__: /var/lib/docker/containers/*/*log

  # --log-opt tag="{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
  pipeline_stages:

  - json:
      expressions:
        stream: stream
        attrs: attrs
        tag: attrs.tag
  - regex:
      expression: (?P<image_name>(?:[^|]*[^|])).(?P<container_name>(?:[^|]*[^|])).(?P<image_id>(?:[^|]*[^|])).(?P<container_id>(?:[^|]*[^|]))
      source: "tag"

  - labels:
      tag:
      stream:
      image_name:
      container_name:
      image_id:
      container_id:
Inbell1s
  • 31
  • 2

1 Answers1

1

You need to use the pipeline stage for Docker at first.

Like this:

      pipeline_stages:
        - docker: {}
PRIHLOP
  • 1,441
  • 1
  • 16
  • 16