Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikhailvs/rack-fluentd-logger
Rack middleware to send traffic logs to Fluentd
https://github.com/mikhailvs/rack-fluentd-logger
fluentd logging middleware monitoring rack rails request-logging ruby traffic-analysis
Last synced: 2 months ago
JSON representation
Rack middleware to send traffic logs to Fluentd
- Host: GitHub
- URL: https://github.com/mikhailvs/rack-fluentd-logger
- Owner: mikhailvs
- License: mit
- Created: 2018-11-26T21:53:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T19:41:19.000Z (8 months ago)
- Last Synced: 2024-11-07T07:12:22.749Z (3 months ago)
- Topics: fluentd, logging, middleware, monitoring, rack, rails, request-logging, ruby, traffic-analysis
- Language: Ruby
- Size: 26.4 KB
- Stars: 20
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Rack Fluentd Logger
[![Gem Version](https://badge.fury.io/rb/rack-fluentd-logger.svg)](https://badge.fury.io/rb/rack-fluentd-logger)## Install
Gemfile:
```ruby
gem 'rack-fluentd-logger'
```Shell:
```sh
gem install rack-fluentd-logger
```## Usage
config.ru
```rubyrequire 'rack-fluentd-logger'
Rack::FluentdLogger.configure(
name: 'your-app-log-name',
host: 'your-fluentd-host',
port: 24224
)use Rack::FluentdLogger
run YourApplication
```
## Configuration Options
| name | default | description |
| ---- | ------- | ----------- |
| name | `ENV['FLUENTD_NAME']` | application name to use for fluentd logs |
| host | `ENV['FLUENTD_HOST']` | fluentd server hostname/ip |
| port | `ENV['FLUENTD_PORT'] \|\| 24_224` | fluentd server port |
| json_parser | `->(str) { JSON.parse(str) }` | used to parse response bodies if they are `application/json` |
| preprocessor | `->(s) { s }` | callback for any additional processing/scrubbing of data before sending it off |## Event Data
Events sent to fluentd have the following structure
```ruby
{
env: {
# everything from the rack env that's an array/hash/string/number
},
timestamp: Time.now, # current time when the log event is recorded
response_time: 0.012, # length of time in seconds for response from rack
code: 200, # http response code from rack app
body: [], # body from rack app (when the content_type is json, it's parsed)
headers: {} # http headers from the rack app
}
```