Buffering InfluxDB client and mixin for Tornado applications
Find a file
2019-11-14 18:45:01 -05:00
docs Bump release history 2019-11-14 18:45:01 -05:00
requires Include Tornado 6 in the pin 2019-11-14 18:15:53 -05:00
tests Always uses IOLoop.current() 2018-11-21 23:21:38 -05:00
.editorconfig Initial Commit 2016-09-12 21:11:25 -04:00
.gitignore Use tox for testing different versions of Tornado 2018-01-23 00:48:15 -05:00
.travis.yml Test with stable Python 3.7 2018-11-21 23:40:51 -05:00
docker-compose.yml WIP of v1 2016-09-12 21:17:55 -04:00
LICENSE Initial Commit 2016-09-12 21:11:25 -04:00
MANIFEST.in WIP of v1 2016-09-12 21:17:55 -04:00
README.rst Remove download count badge 2018-04-06 21:52:04 -04:00
setup.cfg Include coverage and increase verbosity when testing 2016-11-09 15:45:41 -05:00
setup.py Add Py 3.6, 3.7; remove Py 3.4 2018-09-20 14:35:52 -04:00
sprockets_influxdb.py Include Tornado 6 in the pin 2019-11-14 18:15:53 -05:00
tox.ini Support Tornado<6 2018-11-21 23:23:20 -05:00

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:

.. code:: bash

    pip install sprockets-influxdb

Documentation
-------------
Documentation is available at `sprockets-influxdb.readthedocs.io <https://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 <https://sprockets-influxdb.readthedocs.io/en/latest/api.html#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  | ``60000``     |
|                                 | measurements when the buffer has fewer than      |               |
|                                 | ``INFLUXDB_TRIGGER_SIZE`` measurements.          |               |
+---------------------------------+--------------------------------------------------+---------------+
| ``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     | ``25000``     |
|                                 | measurements are discarded.                      |               |
+---------------------------------+--------------------------------------------------+---------------+
| ``INFLUXDB_SAMPLE_PROBABILITY`` | A value that is >= 0 and <= 1.0 that specifies   | ``1.0``       |
|                                 | the probability that a batch will be submitted   |               |
|                                 | to InfluxDB or dropped.                          |               |
+---------------------------------+--------------------------------------------------+---------------+
| ``INFLUXDB_TRIGGER_SIZE``       | The number of metrics in the buffer to trigger   | ``60000``     |
|                                 | the submission of a batch.                       |               |
+---------------------------------+--------------------------------------------------+---------------+
| ``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 <https://github.com/sprockets/sprockets.mixins.correlation>`_,
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.

.. code:: python

    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
------------
-  `Tornado <https://tornadoweb.org>`_

Version History
---------------
Available at https://sprockets-influxdb.readthedocs.org/en/latest/history.html

.. |Version| image:: https://img.shields.io/pypi/v/sprockets-influxdb.svg?
   :target: http://badge.fury.io/py/sprockets-influxdb

.. |Status| image:: https://img.shields.io/travis/sprockets/sprockets-influxdb.svg?
   :target: https://travis-ci.org/sprockets/sprockets-influxdb

.. |Coverage| image:: https://img.shields.io/codecov/c/github/sprockets/sprockets-influxdb.svg?
   :target: https://codecov.io/github/sprockets/sprockets-influxdb?branch=master

.. |License| image:: https://img.shields.io/pypi/l/sprockets-influxdb.svg?
   :target: https://sprockets-influxdb.readthedocs.org