项目作者: davidedantonio

项目描述 :
:evergreen_tree: send pino logs to Fluentd
高级语言: JavaScript
项目地址: git://github.com/davidedantonio/pino-fluentd.git
创建时间: 2019-01-15T12:30:27Z
项目社区:https://github.com/davidedantonio/pino-fluentd

开源协议:MIT License

下载


pino-fluentd

Build Status js-standard-style Greenkeeper badge npm-version

Send pino logs to Fluentd. This plugin is fully inspired to pino-elasticsearch

Under the hood the official fluent-logger-node module is used.

What is Fluentd?

Fluentd is an open source data collector for unified logging layer. Fluentd allows you to unify data collection and consumption for a better use and understanding of data.

Install

If you want to use pino-fluentd you must first install globally on your machine

  1. npm install pino-fluentd -g

Usage

  1. pino-fluentd
  2. To send pino logs to fluentd:
  3. cat log | pino-fluentd --tag debug --trace-level info
  4. Flags
  5. -h | --help Display Help
  6. -v | --version Display Version
  7. -H | --host the IP address of fluentd; default: 127.0.0.1
  8. -p | --port the port of fluentd; default: 24224
  9. -t | --tag the name of the tag to use; default: pino
  10. -k | --key the name of the type to use; default: log
  11. -T | --timeout set the socket to timetout after timeout milliseconds of inactivity
  12. -ri | --reconnect-interval The reconnect interval in milliseconds
  13. -fi | --flush-interval The flush interval in milliseconds
  14. -l | --trace-level trace level for the fluentd client, default 'error' (trace, debug, info, warn, error, fatal)

You can then use Elasticsearch and Kibana to browse and visualize your logs, or whatever you want. A full list of Data Output is here.

Setup and testing

Setting up pino-fluentd is easy and you can use the bundled docker-compose-*.yml file to bring up a Fluentd with or without Elasictsearch and Kibana containers.

You will need docker and docker-compose, then in this project folder, launch docker-compose -f docker-compose-*.yml up.

You can test it by launching node example | pino-fluentd, in this project folder. You will need to have pino-fluentd installed globally.

Forward to Elasticsearch

Fluentd can be configured to forward your logs to ElasticSearch (and search them with Kibana maybe?).
In order to use fluentd with ElasticSearch you need to install the fluent-plugin-elasticsearch plugin on your fluentd instance:

  1. gem install fluent-plugin-elasticsearch

In your Fluentd configuration file, use @type elasticsearch. Additional configuration is optional, default values would look like this:

  1. # File fluent.conf
  2. <source>
  3. @type forward
  4. port 24224
  5. bind 0.0.0.0
  6. </source>
  7. <match pino.*>
  8. @type copy
  9. <store>
  10. @type elasticsearch
  11. host elasticsearch
  12. port 9200
  13. flush_interval 10s
  14. </store>
  15. <store>
  16. @type stdout
  17. </store>
  18. </match>

When Fluentd receives some logs from pino-fluentd and has flushed them to Elasticsearch after a certain interval (in this example 10 seconds), you can view, search and visualize, the log data using Kibana.

License

Licensed under MIT