Low commit activity in last 3 years
No release in over a year
A Fluentd output plugin to send logs to Grafana Loki
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 3.1.0

Runtime

~> 1.0
>= 0.14.15, < 2
 Project Readme

fluent-plugin-loki

Fluentd output plugin to Grafana Loki.

  • Can be used to ship docker logs to Loki (using Fluentd docker logging driver)
  • Enable easier transtion to Loki - an alternative to Loki's Promtail

Installation

RubyGems

$ gem install fluent-plugin-loki

Configuration

sample configuration:

<match *>
  @type loki
  endpoint_url    http://127.0.0.1:3100
  labels          {"env":"prod","farm":"a"} # default: nil
  tenant          abcd           # default: nil
  rate_limit_msec 100            # default: 0 = no rate limiting
  raise_on_error  false          # default: true
  authentication  basic          # default: none
  username        alice          # default: ''
  password        bobpop         # default: '', secret: true
  buffered        true           # default: false. Switch non-buffered/buffered mode
  cacert_file     /etc/ssl/endpoint1.cert # default: ''
  token           tokent         # default: ''
  custom_headers  {"token":"arbitrary"} # default: nil
</match>
  • endpoint_url - Loki's endpoint
  • tenant - Loki tenant id
  • labels - Labels for filtering in Grafana (currently they are static)

(generated by running: fluent-plugin-config-format output loki -p lib/fluent/plugin)

Usage examples for common fluentd inputs:

syslog

Setting up rsyslog Open /etc/rsyslog.d/50-default.conf and append the following line: *.* @127.0.0.1:5140 Then restart the rsyslogd service: sudo systemctl restart syslog sample fluentd config:

<source>
  @type syslog
  port 5140
  bind 0.0.0.0
  tag system
</source>

simulate data: logger "came from syslog"

file

sample fluentd config:

## File input
## read apache logs with tag=apache.access
#<source>
#  @type tail
#  format apache
#  path /var/log/httpd-access.log
#  tag apache.access
#</source>

HTTP

sample fluentd config:

# HTTP input
# http://localhost:8888/<tag>?json=<json>
# for ex: http://localhost:8888/baz?json={"src":"http"}
<source>
  @type http
  @id http_input

  port 8888
</source>

simulate data:

curl -X POST -d 'json={"src":"http"}' http://localhost:8888

tcp

sample fluentd config:

## built-in TCP input
## $ echo <json> | fluent-cat <tag>
<source>
  @type forward
  @id forward_input
</source>

simulate data:

echo '{"src":"tcp"}' | fluent-cat tcp

Development (using Docker)

  • Set up Loki and Grafana (can be done by running their docker-compose)
  • Add loki data source to grafana
  • Run Fluentd container with volume mapping to the dummy configuration and to the plugin:
docker run -d \
  -p 9880:9880 \
  -v $(pwd)/development/conf:/fluentd/etc \
  -v $(pwd)/lib/fluent/plugin:/etc/fluent/plugin -e FLUENTD_CONF=fluentd.conf \
  fluent/fluentd
  • Execute to send log: curl -X POST -d 'json={"foo":"baz"}' http://localhost:9880

Copyright

  • Copyright(c) 2018- Edan Shahmoon
  • License
    • Apache License, Version 2.0

Heavily based on fluent-plugin-out-http