Monitoring¶
Data for monitoring¶
  Now we monitor two types of events for monitoring: request and error. The first type is all requests, second is failed requests only. Every event is a point in the time series. The point is represented as the 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 route status_code
“luna-python-matcher” or “luna-matcher-proxy” concatenation of a request method and a request resource (POST:/matcher) http status code of response
fields
fields
description
request_id execution_time
request id request execution time
‘Errors’ series. Triggered on failed request. Each point contains error_code of luna error.
tags
tag name
description
service route status_code error_code
“luna_python_matcher” or “luna-matcher-proxy” concatenation of a request method and a request resource (POST:/matcher) http status code of response luna error code
fields
fields
description
request_id
request id
Every handler can add additional tags or fields.
Database¶
Monitoring is implemented as data sending to an influx database. You can set up your database credentials in configuration file in section “monitoring”.
Classes¶
Module contains points for monitoring’s.
- class luna_python_matcher.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_python_matcher.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_python_matcher.crutches_on_wheels.cow.monitoring.points.DataForMonitoring(tags=<factory>, fields=<factory>)[source]¶
Class fo storing an additional data for monitoring.
- class luna_python_matcher.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_python_matcher.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_python_matcher.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_python_matcher.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_python_matcher.crutches_on_wheels.cow.monitoring.base_monitoring.BaseLunaMonitoring[source]¶
Base class for monitoring
- class luna_python_matcher.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
Module contains classes for sending a data to an influx monitoring.
- class luna_python_matcher.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:
- flushingPeriod¶
period of flushing points (in seconds)
- Type:
float
- _influxSettings¶
current influx settings
- Type:
- _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