Monitoring

Monitoring is implemented as sending data to the influx database.

Data for monitoring

There are two types of events that are monitored: request (all requests) and error (failed requests only).

Every event is a point in the time series. The point is represented using the following data:

  • series name (requests or errors)

  • timestamp of the request start

  • tags

  • fields

The tag is an indexed data in storage. It is represented as a dictionary, where * keys - string tag names, * values - string, integer or float.

The field is a non-indexed data in storage. It is represented as a dictionary, where * keys - string field names, * values - string, integer or float.

Saving data for ‘Requests’ is triggered on every request. Each point contains data about the corresponding request (execution time and etc.).

  • tags

    tag name

    description

    service

    always “luna-api”

    account_id

    account id or none

    route

    concatenation of a request method and a request resource (POST:/extractor)

    status_code

    http status code of response

  • fields

    fields

    description

    request_id

    request id

    execution_time

    request execution time

Saving data for ‘Errors’ is triggered when a request fails. Each point contains error_code of LUNA error.

  • tags

    tag name

    description

    service

    always “luna-api”

    account_id

    account ID or none

    route

    concatenation of a request method and a request resource (POST:/extractor)

    status_code

    http status code of response

    error_code

    LUNA PLATFRORM error code

  • fields

    fields

    description

    request_id

    request id

Every handler can add additional tags or fields. For example, handler of resource /handlers/{handlerId}/events adds tag handler_id.

For a resource “/detector”, “/extractor”, “/handlers/{handler_id}/events” there are additional fields:

  • fields

    fields

    description

    task_execution_time

    sdk task execution time

    results_queue_transport_time

    transport time by results queue

    detector_queue_transport_time

    transport time by detector queue

    extractor_queue_transport_time

    transport time by extractor queue

    warp_attributes_estimator_queue_transport_time

    transport time by warp attributes queue

    detector_stage_time

    detector stage time

    extractor_stage_time

    extractor stage time

    warp_estimator_stage_time

    warp estimator stage time

    faces_detect_time

    face detect time

    descriptors_extract_time

    descriptors extract time

    basic_attributes_extract_time

    basic attributes extract time

    gaze_direction_estimation_time

    gaze direction estimation time

    head_pose_estimation_time

    head pose execution time

    eyes_attributes_estimation_time

    eyes attributes execution time

    ags_estimation_time

    ags estimation time

    quality_estimation_time

    quality estimation time

    emotions_estimation_time

    emotions estimation time

    mouth_attributes_estimation_time

    mouth attributes estimation time

    save_samples_time

    save samples to image store time

    save_face_attributes_time

    save face attributes to luna-faces time

    load_samples_time

    load samples from image-store time

    load_images_for_processing_time

    load images for processing time

Database

You can set your database credentials in configuration file in section “monitoring”.

Plugins

You can create your plugin for sending monitoring data. See plugins

class luna_api.plugins.plugins.request_monitoring_example_plugin.RequestMonitoringClass[source]

Example plugin sends a request data for monitoring to third-party source. Only one instance of this class exist during the program execution.

async flushPointToMonitoring(points, logger)[source]

Callback for sending a request monitoring data.

Parameters:
  • points – point for monitoring which corresponding the request

  • logger – logger

Return type:

None

Classes

Module contains points for monitoring’s.

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

Abstract class for points

eventTime

event time as timestamp

Type:

float

abstract property fields: Dict[str, int | float | str]

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

Returns:

dict with fields.

Return type:

Dict[str, Union[int, float, str]]

abstract property tags: Dict[str, int | float | str]

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_api.crutches_on_wheels.cow.monitoring.points.BaseRequestMonitoringPoint(requestId, resource, method, requestTime, service, statusCode)[source]

Base class for point which is associated with requests.

requestId

request id

Type:

str

route

concatenation of a request method and a request resource

Type:

str

service

service name

Type:

str

requestTime

a request processing start timestamp

Type:

float

statusCode

status code of a request response.

Type:

int

property fields: Dict[str, int | float | str]

Get fields

Returns:

“request_id”

Return type:

dict with following keys

Return type:

Dict[str, Union[int, float, str]]

property tags: Dict[str, int | float | str]

Get tags

Returns:

“route”, “service”, “status_code”

Return type:

dict with following keys

Return type:

Dict[str, Union[int, float, str]]

class luna_api.crutches_on_wheels.cow.monitoring.points.DataForMonitoring(tags=<factory>, fields=<factory>)[source]

Class fo storing an additional data for monitoring.

class luna_api.crutches_on_wheels.cow.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

error code

Type:

int

additionalTags

additional tags which was specified for the request

Type:

dict

additionalFields

additional fields which was specified for the request

Type:

dict

property fields: Dict[str, int | float | str]

Get fields.

Returns:

dict with base fields and additional tags

Return type:

Dict[str, Union[int, float, str]]

series: str = 'errors'

series “errors”

property tags: Dict[str, int | float | str]

Get tags.

Returns:

dict with base tags, “error_code” and additional tags

Return type:

Dict[str, Union[int, float, str]]

class luna_api.crutches_on_wheels.cow.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

execution time

Type:

float

additionalTags

additional tags which was specified for the request

Type:

dict

additionalFields

additional fields which was specified for the request

Type:

dict

property fields: Dict[str, int | float | str]

Get fields.

Returns:

dict with base fields, “execution_time” and additional tags

Return type:

Dict[str, Union[int, float, str]]

series: str = 'requests'

series “request”

property tags: Dict[str, int | float | str]

Get tags.

Returns:

dict with base tags and additional tags

Return type:

Dict[str, Union[int, float, str]]

luna_api.crutches_on_wheels.cow.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_api.crutches_on_wheels.cow.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_api.crutches_on_wheels.cow.monitoring.base_monitoring.BaseLunaMonitoring[source]

Base class for monitoring

abstract flushPoints(points)[source]

Flush point to monitoring.

Parameters:

points – point

Return type:

None

class luna_api.crutches_on_wheels.cow.monitoring.base_monitoring.LunaRequestInfluxMonitoring(credentials, host='localhost', port=8086, ssl=False, flushingPeriod=1)[source]

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

influxdb settings

type:

InfluxSettings

flushingPeriod

period of flushing points (in seconds)

Type:

int

async close()[source]

Stop monitoring.

Return type:

None

flushPoints(points)[source]

Flush point to influx.

Parameters:

points – point

Return type:

None

async initialize()[source]

Initialize monitoring

Return type:

None

static prepareSettings(credentials, host, port, ssl)[source]

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

Returns:

influxdb settings container

Return type:

InfluxSettings

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

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

Base monitoring adapter.

backgroundScheduler

runner for periodic flushing monitoring points

Type:

AsyncIOScheduler

_buffer

list of buffering points which is waiting sending to influx

Type:

List[BaseRequestMonitoringPoint]

flushingPeriod

period of flushing points (in seconds)

Type:

float

logger

logger

Type:

Logger

_influxSettings

current influx settings

Type:

InfluxSettings

_job

sending monitoring data job

Type:

Job

addPointsToBuffer(points)[source]

Add points to buffer.

Parameters:

points – points

Return type:

None

static convertFieldsToInfluxLineProtocol(fields)[source]

Convert field value to influx line protocol format

Parameters:

fields – dict with values to convert

Retruns:

line protocol string

Return type:

str

generatePointStr(point)[source]

Generate string from point

Parameters:

point – point

Returns:

influx line protocol string

Return type:

str

initializeScheduler()[source]

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

Return type:

None

stopScheduler()[source]

Stop monitoring.

Return type:

None

updateFlushingPeriod(newPeriod)[source]

Update flushing period :param newPeriod: new period

class luna_api.crutches_on_wheels.cow.monitoring.influx_adapter.InfluxMonitoringAdapter(settings, flushingPeriod)[source]

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

bucket

influx bucket name

Type:

str

initializeMonitoring()[source]

Initialize monitoring.

Return type:

None

async stopMonitoring()[source]

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

Return type:

None

class luna_api.crutches_on_wheels.cow.monitoring.influx_adapter.InfluxSettings(url, bucket, organization, token, ssl)[source]

Container for influx 2.x settings