Monitoring¶
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 (e.g. requests and errors)
start request time (timestamp of the request start)
- 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.
‘Requests’ series. 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-licenses”
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. 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-licenses”
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
Every handler can add additional tags or fields.
‘Licensing’ series. Triggered on license check when starting the service as well as scheduled daily at midnight. Each point contains license check data.
tags
tag name
description
service
always “luna-licenses”
license_status
license status (“ok”, “warning”, “error”)
fields
fields
description
license_period_rest
number of days before the license expires
warnings
license warning messages
errors
license error messages
Database¶
Monitoring is implemented as data sending to an influx database. You can specify your database credentials in configuration file in section “monitoring”.
Classes¶
Module contains points for monitoring.
- class luna_licenses.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 fields 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_licenses.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
- 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_licenses.crutches_on_wheels.cow.monitoring.points.DataForMonitoring(tags=<factory>, fields=<factory>)[source]¶
Class fo storing an additional data for monitoring.
- class luna_licenses.crutches_on_wheels.cow.monitoring.points.InfluxFormatter[source]¶
Format any point filed into inline format
- class luna_licenses.crutches_on_wheels.cow.monitoring.points.MonitoringPointInfluxFormatBuilder(name, bases, namespace, /, **kwargs)[source]¶
Complement point class with explicit fields formatting function for the sake of better performance
To perform type format building target class must have ‘fields’ property return value annotated with TypedDict.
Target class might be configured via ‘Config’ class. Available options:
extraFields: whether class should handle additional fields or not
>>> from typing import TypedDict >>> >>> class MonitoringFields(TypedDict): ... field1: str ... field2: int ... field3: float ... field4: bool >>> >>> class BasePoint(BaseMonitoringPoint, metaclass=MonitoringPointInfluxFormatBuilder): ... ... def __init__(self, fields: dict): ... self._fields = fields ... ... @property ... def tags(self): ... return {} ... ... @property ... def fields(self) -> MonitoringFields: ... return self._fields ... >>> class TestPointNoExtra(BasePoint): ... ... class Config: ... extraFields = False ... >>> class TestPointWithExtra(BasePoint): ... class Config: ... extraFields = True >>> >>> >>> point1 = TestPointNoExtra({"field1": "data", "field2": 1, "field3": 1.0, "field4": False}) >>> point2 = TestPointWithExtra({"field1": "data", "field2": 1, "field3": 1.0, "field4": False, "extra": True}) >>> print(point1.convertFieldsToInfluxLineProtocol()) field1="data",field2=1i,field3=1.000000,field4=False >>> print(point2.convertFieldsToInfluxLineProtocol()) field1="data",field2=1i,field3=1.000000,field4=False,extra=True
- classmethod buildInfluxFormats(annotations, extraFields)[source]¶
Build map with influx formats for corresponding fields
- Parameters:
annotations (dict) – point fields type annotations
extraFields (bool) – whether point uses extra fields or not
- Returns:
dict of fields with their format
- Return type:
dict
- static convertFieldsToInfluxLineProtocolNoExtra(point)[source]¶
Convert point fields into influx line protocol format without extra fields
- class luna_licenses.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_licenses.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 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_licenses.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_licenses.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_licenses.crutches_on_wheels.cow.monitoring.manager.LunaMonitoringManager(settings, pluginManager)[source]¶
Monitoring manager. Sends data to the monitoring storage and monitoring plugins. .. attribute:: settings
monitoring storage settings
- class luna_licenses.crutches_on_wheels.cow.monitoring.manager.MonitoringSettings(*args, **kwargs)[source]¶
Monitoring settings protocol
Module contains classes for sending a data to an influx monitoring.
- class luna_licenses.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
- Returns:
line protocol string
- Return type:
str
- generatePointStr(point)[source]¶
Generate string from point
- Parameters:
point – point
- Returns:
influx line protocol string
- Return type:
str