Monitoring
==========

.. _`monitoring`:

.. _influx database: https://www.influxdata.com/products/influxdb-overview/

Data for monitoring
-------------------


Now we monitor two types of events for monitoring: *request*  and *error*. First type is all requests, second is
failed requests only. Every event is a point in the time series. The point is represented as union of the following
data:

    - series name (now *requests* and *errors*)
    - start request time
    - tags, indexed data in storage, dictionary: keys - string tag names, values - string, integer, float
    - fields, non indexed data in storage, dictionary: keys - string tag names, values - string, integer, float

*'Requests'* series. Triggered on every request. Each point contains a data about corresponding request (execution time and etc).

    - tags

        +--------------+----------------------------------------------------------------------------+
        | tag name     |                                description                                 |
        +==============+============================================================================+
        | service      | always "luna-streams"                                                      |
        +--------------+----------------------------------------------------------------------------+
        | route        | concatenation of a request method and a request resource (POST:/streams)   |
        +--------------+----------------------------------------------------------------------------+
        | status_code  | http status code of response                                               |
        +--------------+----------------------------------------------------------------------------+

    - fields

        +----------------+------------------------+
        |     fields     |      description       |
        +================+========================+
        | request_id     | request id             |
        +----------------+------------------------+
        | execution_time | request execution time |
        +----------------+------------------------+

*'Errors'* series. Triggered on failed request. Each point contains *error_code* of luna error.

    - tags

        +--------------+----------------------------------------------------------------------------+
        | tag name     |                                description                                 |
        +==============+============================================================================+
        | service      | always "luna-streams"                                                      |
        +--------------+----------------------------------------------------------------------------+
        | route        | concatenation of a request method and a request resource (POST:/streams)   |
        +--------------+----------------------------------------------------------------------------+
        | status_code  | http status code of response                                               |
        +--------------+----------------------------------------------------------------------------+
        | error_code   | luna error code                                                            |
        +--------------+----------------------------------------------------------------------------+

    - fields

        +----------------+------------------------+
        |     fields     |      description       |
        +================+========================+
        | request_id     | request id             |
        +----------------+------------------------+

*'Licensing'* series. Triggered when the service starts and every 60 seconds.
Each point contains license check data.

    - tags

        +-----------------+--------------------------------------------------------+
        | tag name        |                     description                        |
        +-----------------+--------------------------------------------------------+
        | service         | always "luna-streams"                                  |
        +-----------------+--------------------------------------------------------+
        | license_status  | license status ("ok", "warning", "error", "exception") |
        +-----------------+--------------------------------------------------------+

    - fields

        +----------------------------+--------------------------------+
        |     fields                 |      description               |
        +----------------------------+--------------------------------+
        | license_streams_limit_rate | the percentage of used streams |
        +----------------------------+--------------------------------+
        | warnings                   | license warning messages       |
        +----------------------------+--------------------------------+
        | errors                     | license error messages         |
        +----------------------------+--------------------------------+


Database
--------

Monitoring is implemented as data sending to an `influx database`_. You can setup your database credentials in
`configuration file <config.html>`_ in section *"monitoring"*.

Classes
-------

.. automodule:: luna_streams.crutches_on_wheels.cow.monitoring.points
   :members:

.. automodule:: luna_streams.crutches_on_wheels.cow.monitoring.base_monitoring
   :members:

.. automodule:: luna_streams.crutches_on_wheels.cow.monitoring.influx_adapter
   :members:
