Skip to main content

Grafana with logfiles

First start Grafana:

brew services start grafana

This service will run instantly.

Next start Loki the service getting log files and show them to Grafana:

loki -config.file /Users/cox/.local/loki/config.yaml

Current config is:

auth_enabled: false

server:
  http_listen_port: 3100

ingester:
  lifecycler:
    address: 127.0.0.1
    ring:
      kvstore:
        store: inmemory
      replication_factor: 1
    final_sleep: 0s
  chunk_idle_period: 5m
  chunk_retain_period: 30s

schema_config:
  configs:
    - from: 2018-04-15
      store: boltdb
      object_store: filesystem
      schema: v9
      index:
        prefix: index_
        period: 168h

storage_config:
  boltdb:
    directory: /tmp/loki/index

  filesystem:
    directory: /tmp/loki/chunks

limits_config:
  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 168h

chunk_store_config:
  max_look_back_period: 0

table_manager:
  chunk_tables_provisioning:
    inactive_read_throughput: 0
    inactive_write_throughput: 0
    provisioned_read_throughput: 0
    provisioned_write_throughput: 0
  index_tables_provisioning:
    inactive_read_throughput: 0
    inactive_write_throughput: 0
    provisioned_read_throughput: 0
    provisioned_write_throughput: 0
  retention_deletes_enabled: false
  retention_period: 0

Now start Promtail:

promtail -config.file /Users/cox/.local/promtail/config.yaml

This given config file includes the logfile you want to discover:

# Promtail Server Config
server:
  http_listen_port: 9080
  grpc_listen_port: 0

# Positions
positions:
  filename: /tmp/positions.yaml

# Loki Server URL
clients:
  - url: http://localhost:3100/loki/api/v1/push

scrape_configs:
  - job_name: AME
    static_configs:
      - targets:
          - localhost
        labels:
          job: AME
          host: localhost
          __path__: /Users/cox/Downloads/AMEEncodingLog.txt
    pipeline_stages:
    - match:
        selector: '{job="AME"}'
        stages:
        - regex:
            expression: '^(?P<start>\d\d\/\d\d\/\d\d\d\d\s\d\d:\d\d:\d\d\s[AP]M)\s:\sWarteschlange gestartet'

        - labels:
            start:

        - timestamp:
            format: 02/01/2006 03:04:05 PM
            source: start
    - match:
        selector: '{job="AME"}'
        stages:
        - regex:
            expression: '^(?P<stop>\d\d\/\d\d\/\d\d\d\d\s\d\d:\d\d:\d\d\s[AP]M)\s:\sWarteschlange gestoppt'

        - labels:
            stop:

        - timestamp:
            format: 02/01/2006 03:04:05 PM
            source: stop

Now surf to http://localhost:3000/explore?orgId=1&left=%5B%22now-1h%22,%22now%22,%22Loki%22,%7B%22refId%22:%22A%22,%22expr%22:%22%22%7D%5D

Warning: pipeline_stages in promtail currently not working as intended.