0.0
The project is in a healthy, maintained state
A rack middleware for logging requests to InfluxDB
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 1.17, < 3.0
~> 2.0
~> 13.0
~> 3.13

Runtime

>= 1.0, < 4
>= 0
>= 0
>= 0
 Project Readme

rack-influxdb

Github Chimpy

Continuous Integration codecov License: MIT Ruby Style Guide Reek Badge Brakeman Badge

This gem provides a Rack middleware for InfluxDB.

  • Installation
  • Usage
    • Configuration
    • Basic usage

Installation

Add this line to your application's Gemfile:

gem 'rack-influxdb'

Then run:

bundle

Usage

Configuration

The Rack::InfluxDB gem can be easily configured

Rack::InfluxDB.configure do |config|
  # The name of your measurement
  config.name = "http_requests"

  # Custom tags
  config.tags = { app: "my-awesome-api", env: "production" }

  # The URL of your InfluxDB instance
  config.url = "https://test.influxdb.example.com"

  # The API token provided by InfluxDB
  config.token = "topsecret"

  # A lambda that returns a hash containing the fields to write.
  # E.g. to just track the HTTP status:
  config.fields = lambda { |env, response| return { status: response[0] } }

  # Handle errors individually
  config.handle_errors = lambda { |err| report_error(err) }

  # Options like Org, Bucket and Precision
  config.options = {
    org: 'my-org',
    bucket: 'my-bucket',
    precision: InfluxDB2::WritePrecision::MILLISECOND
  }

  # Write options - it's highly recommended to use batching and not
  # synchronous writing.
  config.write_options = {
    write_type: InfluxDB2::WriteType::BATCHING,
    batch_size: 1_000
  }
end

Basic usage

All you have to do is to include the middleware in your Rack stack.

In Rails:

# config/application.rb

class Application < Rails::Application
  ...
  config.middleware.use Rack::InfluxDB
end