Monitoring

Data for monitoring

Now we monitor several types of events:

  • request, all http and ws requests.
  • error, all failed http and ws requests.
  • ws requests, all messages send by websockets (ws) to clients.
  • subscription error, all errors, generated during redis messages processing or during the subscription
    establishment to redis.
  • redis messages, all messages from redis

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 http or websockets request. Each point contains data about the corresponding request (execution time and etc).

  • tags

    tag name description
    service always “luna-sender”
    route concatenation of a request method and a request resource (GET:/version)
    status_code http status code of response
  • fields

    fields description
    request_id request id
    execution_time request execution time

‘Errors’ series. Triggered on failed http or websockets request. Each point contains error_code of luna error.

  • tags

    tag name description
    service always “luna-sender”
    route concatenation of a request method and a request resource (GET:/version)
    status_code http status code of response
    error_code luna error code
  • fields

    fields description
    request_id request id

‘Subscription errors’ series. Triggered on an error in a pipeline of processing messages from redis or redis subscription. Each point contains error_code of luna error.

  • tags

    tag name description
    service always “luna-sender”
    error_code luna error code
  • fields, now nothing

‘ws requests’ series. Triggered on every request by ws to a client. Each point contains a time of processing

  • tags

    tag name description
    service always “luna-sender”
    account_id account id or none
  • fields

    fields description
    transport_time time between getting message from redis and finish sending request to a client
    request_id request id

Can be to add additional tags or fields in ‘subscription_error’.

Database

Monitoring is implemented as data sending to an influx database. You can setup your database credentials in configuration file in section “monitoring”.

Classes

Points. For monitoring events in the redis context

class luna_sender.app.monitoring.points.BaseSenderMonitoringPoint(eventTime)[source]

Base point for Sender messages monitoring

classmethod initialize(serviceName)[source]

Initialize :param serviceName: service name

service = None

service name

class luna_sender.app.monitoring.points.ErrorPoint(eventTime, errorCode, additionalTags=None, additionalFields=None)[source]

Point for monitoring errors of processing messages from redis or connecting to redis

additionalTags

dict – additional tags for point

errorCode

str – error code

additionalFields

dict – additional fields for point

fields

Get point fields

Returns:dict with additional fields
Return type:dict
series = 'subscription_error'

series

tags

Get point tags

Returns:dict with service as keys + additionalTags
Return type:dict
class luna_sender.app.monitoring.points.SubscribeRedisPoint(requestId, chanel, eventTime)[source]

Point for monitoring receiving message from redis

requestId

str – request id from luna

chanel

str – redis chanel (‘{chane name}:{account id}’)

fields

Get point fields :returns: dict with request id id as keys

Return type:dict
series = 'redis_message'

series

tags

Get point tags

Returns:dict with chanel and service as keys
Return type:dict
class luna_sender.app.monitoring.points.WSRequestPoint(eventTime, requestId, transportTime, accountId)[source]

Point for monitoring sending message to ws

accountId

str – account id

requestId

str – request id from luna

transportTime

float – time between getting message from redis and sending it to a ws (seconds)

fields

Get point fields :returns: dict with request id id and transport time as keys

Return type:dict
series = 'ws_requests'

series

tags

Get point tags

Returns:dict with account id and service as keys
Return type:dict

Module contains points for monitoring’s.

class luna_sender.crutches_on_wheels.monitoring.points.BaseMonitoringPoint(eventTime)[source]

Abstract class for points

eventTime

float – event time as timestamp

fields

Get tags from point. We supposed that fields are not indexing data

Returns:dict with fields.
Return type:Dict[str, Union[int, float, str]]
tags

Get tags from point. We supposed that tags are indexing data

Returns:dict with tags.
Return type:Dict[str, Union[int, float, str]]
class luna_sender.crutches_on_wheels.monitoring.points.BaseRequestMonitoringPoint(requestId, resource, method, requestTime, service, statusCode)[source]

Base class for point which is associated with requests.

requestId

str – request id

route

str – concatenation of a request method and a request resource

service

str – service name

requestTime

float – a request processing start timestamp

statusCode

int – status code of a request response.

fields

Get fields

Returns:“request_id”
Return type:dict with following keys
Return type:Dict[str, Union[int, float, str]]
tags

Get tags

Returns:“route”, “service”, “status_code”
Return type:dict with following keys
Return type:Dict[str, Union[int, float, str]]
class luna_sender.crutches_on_wheels.monitoring.points.DataForMonitoring(tags=<factory>, fields=<factory>)[source]

Class fo storing an additional data for monitoring.

class luna_sender.crutches_on_wheels.monitoring.points.RequestErrorMonitoringPoint(requestId, resource, method, errorCode, service, requestTime, statusCode, additionalTags=None, additionalFields=None)[source]

Request monitoring point is suspended for monitoring requests errors (error codes)

errorCode

int – error code

additionalTags

dict – additional tags which was specified for the request

additionalFields

dict – additional fields which was specified for the request

fields

Get fields.

Returns:dict with base fields and additional tags
Return type:Dict[str, Union[int, float, str]]
series = 'errors'

series “errors”

tags

Get tags.

Returns:dict with base tags, “error_code” and additional tags
Return type:Dict[str, Union[int, float, str]]
class luna_sender.crutches_on_wheels.monitoring.points.RequestMonitoringPoint(requestId, resource, method, executionTime, requestTime, service, statusCode, additionalTags=None, additionalFields=None)[source]

Request monitoring point is suspended for monitoring all requests and measure a request time and etc.

executionTime

float – execution time

additionalTags

dict – additional tags which was specified for the request

additionalFields

dict – additional fields which was specified for the request

fields

Get fields.

Returns:dict with base fields, “execution_time” and additional tags
Return type:Dict[str, Union[int, float, str]]
series = 'requests'

series “request”

tags

Get tags.

Returns:dict with base tags and additional tags
Return type:Dict[str, Union[int, float, str]]
luna_sender.crutches_on_wheels.monitoring.points.getRoute(resource, method)[source]

Get a request route, concatenation of a request method and a request resource :param resource: resource :param method: method

Returns:{resource}”
Return type:“{method}
Return type:str
luna_sender.crutches_on_wheels.monitoring.points.monitorTime(monitoringData, fieldName)[source]

Context manager for timing execution time.

Parameters:
  • monitoringData – container for saving result
  • fieldName – field name

Module implement base class for monitoring

class luna_sender.crutches_on_wheels.monitoring.base_monitoring.BaseLunaMonitoring[source]

Base class for monitoring

flushPoints(points)[source]

Flush point to monitoring.

Parameters:points – point
Return type:None
class luna_sender.crutches_on_wheels.monitoring.base_monitoring.LunaRequestInfluxMonitoring(credentials, host='localhost', port=8086, version=2, ssl=False, flushingPeriod=1)[source]

Class for sending data which is associated with request to influx .. attribute:: settings

Union[Influx1Settings, Influx2Settings] – influxdb settings
flushingPeriod

int – period of flushing points (in seconds)

flushPoints(points)[source]

Flush point to influx.

Parameters:points – point
Return type:None
initializeMonitoring()[source]

Initialize monitoring

Return type:None
static prepareSettings(credentials, host, port, version, ssl)[source]

Prepare influxdb settings :param credentials: database credentials :param host: influx host :param port: influx port :param version: influxdb version :param ssl: use or not ssl for connecting to influx

Returns:influxdb settings container
Return type:Union[Influx1Settings, Influx2Settings]
reInitializeMonitoring(credentials, host='localhost', port=8086, version=2, ssl=False, flushingPeriod=1, force=False)[source]

Re-initialize monitoring. :param credentials: database credentials :param host: influx host :param port: influx port :param version: influxdb version :param ssl: use or not ssl for connecting to influx :param flushingPeriod: flushing data period :param force: force reload all settings and connections

Return type:None
stopMonitoring()[source]

Stop monitoring.

Return type:None

Module contains classes for sending a data to an influx monitoring.

class luna_sender.crutches_on_wheels.monitoring.influx_adapter.BaseMonitoringAdapter(settings, flushingPeriod)[source]

Base monitoring adapter.

client

Union[InfluxDB1Client, InfluxDB2Client] – influx client

backgroundScheduler

AsyncIOScheduler – runner for periodic flushing monitoring points

_buffer

List[BaseRequestMonitoringPoint] – list of buffering points which is waiting sending to influx

flushingPeriod

float – period of flushing points (in seconds)

logger

Logger – logger

_influxSettings

InfluxSettings – current influx settings

_job

Job – sending monitoring data job

addPointsToBuffer(points)[source]

Add points to buffer.

Parameters:points – points
Return type:None
static convertPointToDict(point)[source]

Convert point to influx client point :param point: point

Returns:
  • ‘time’ - timestamp in nanoseconds
  • ’measurement’ - time series
  • ’tags’ - dict of tags (values are str)
  • ’fields’ - dict of fields
Return type:dict
Return type:dict
static getClient(settings)[source]

Prepare influx client.

initializeScheduler()[source]

Start the loop for sending data from the buffer to monitoring.

Return type:None
reInitializeScheduler(flushingPeriod, force)[source]

Re-initialize scheduler :param flushingPeriod: flushing data period :param force: whether to force reload settings

stopScheduler()[source]

Stop monitoring.

Return type:None
updateFlushingPeriod(newPeriod)[source]

Update flushing period :param newPeriod: new period

class luna_sender.crutches_on_wheels.monitoring.influx_adapter.Influx1MonitoringAdapter(settings, flushingPeriod)[source]

Influx 1.x adaptor. Suspended to send points to an influxdb

client

InfluxDB1Client – influx 1.x client

dbName

str – influx database name

static getClient(settings)[source]

Initialize influx 1.x client. :param settings: influx 1.x settings

Returns:influx 1.x client
Return type:InfluxDBClient
initializeMonitoring()[source]

Initialize monitoring.

Return type:None
reInitialize(newSettings, flushingPeriod, force)[source]

Re-initialize adapter :param newSettings: influx settings :param flushingPeriod: flushing data period :param force: force reload all settings and connections

stopMonitoring()[source]

Stop monitoring (cancel all request and stop getting new).

Return type:None
class luna_sender.crutches_on_wheels.monitoring.influx_adapter.Influx1Settings(dbName, host, port, username, password, ssl)[source]

Container for influx 1.x settings

class luna_sender.crutches_on_wheels.monitoring.influx_adapter.Influx2MonitoringAdapter(settings, flushingPeriod)[source]

Influx 2.x adaptor. Suspended to send points to an influxdb

client

InfluxDB2Client – influx 2.x client

bucket

str – influx bucket name

static getClient(settings)[source]

Initialize influx 2.x client. :param settings: influx 2.x settings

Returns:influx 2.0 write api
Return type:WriteApi
initializeMonitoring()[source]

Initialize monitoring.

Return type:None
reInitialize(newSettings, flushingPeriod, force)[source]

Re-initialize adapter :param newSettings: influx settings :param flushingPeriod: flushing data period :param force: force reload all settings and connections

stopMonitoring()[source]

Stop monitoring (cancel all request and stop getting new).

Return type:None
class luna_sender.crutches_on_wheels.monitoring.influx_adapter.Influx2Settings(bucket, host, port, organization, token, ssl)[source]

Container for influx 2.x settings