Sprockets InfluxDB

Buffering InfluxDB client and mixin for Tornado applications

Version Status Coverage License

Installation

sprockets-influxdb is available on the Python package index and is installable via pip:

pip install sprockets-influxdb

Documentation

Documentation is available at sprockets-influxdb.readthedocs.io.

Configuration

Configuration can be managed by specifying arguments when invoking sprockets_influxdb.install or by using environment variables.

For programmatic configuration, see the sprockets_influxdb.install documentation.

The following table details the environment variable configuration options.

Variable Definition Default
INFLUXDB_SCHEME The URL request scheme for making HTTP requests https
INFLUXDB_HOST The InfluxDB server hostname localhost
INFLUXDB_PORT The InfluxDB server port 8086
INFLUXDB_USER The InfluxDB server username  
INFLUXDB_PASSWORD The InfluxDB server password  
INFLUXDB_ENABLED Set to false to disable InfluxDB support true
INFLUXDB_INTERVAL How many milliseconds to wait before submitting measurements when the buffer has fewer than INFLUXDB_TRIGGER_SIZE measurements. 60000
INFLUXDB_MAX_BATCH_SIZE Max # of measurements to submit in a batch 10000
INFLUXDB_MAX_BUFFER_SIZE Limit of measurements in a buffer before new measurements are discarded. 25000
INFLUXDB_SAMPLE_PROBABILITY A value that is >= 0 and <= 1.0 that specifies the probability that a batch will be submitted to InfluxDB or dropped. 1.0
INFLUXDB_TRIGGER_SIZE The number of metrics in the buffer to trigger the submission of a batch. 60000
INFLUXDB_TAG_HOSTNAME Include the hostname as a tag in the measurement true

Mixin Configuration

The sprockets_influxdb.InfluxDBMixin class will automatically tag the measurement if the ENVIRONMENT environment variable is set with the environment that the application is running in. Finally, if you are using the Sprockets Correlation Mixin, measurements will automatically be tagged with the correlation ID for a request.

Example

In the following example, a measurement is added to the example InfluxDB database with the measurement name of measurement-name. When the ~tornado.ioloop.IOLoop is started, the stop method is invoked, calling ~sprockets_influxdb.shutdown. ~sprockets_influxdb.shutdown ensures that all of the buffered metrics are written before the IOLoop is stopped.

import logging

import sprockets_influxdb as influxdb
from tornado import ioloop

logging.basicConfig(level=logging.INFO)

io_loop = ioloop.IOLoop.current()
influxdb.install(io_loop=io_loop)

measurement = influxdb.Measurement('example', 'measurement-name')
measurement.set_tag('foo', 'bar')
measurement.set_field('baz', 1.05)

influxdb.add_measurement(measurement)

def stop():
    influxdb.shutdown()
    io_loop.stop()

io_loop.add_callback(stop)
io_loop.start()

Requirements

License

Copyright (c) 2016 AWeber Communications All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Sprockets nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.