Lambda monitoring ================= 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 data about corresponding request (execution time and etc). - tags +--------------+----------------------------------------------------------------------------+ | tag name | description | +==============+============================================================================+ | service | always "lambda-" | +--------------+----------------------------------------------------------------------------+ | route | concatenation of a request method and a request resource (POST:/main) | +--------------+----------------------------------------------------------------------------+ | 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 "lambda-" | +--------------+----------------------------------------------------------------------------+ | route | concatenation of a request method and a request resource (POST:/main) | +--------------+----------------------------------------------------------------------------+ | status_code | http status code of response | +--------------+----------------------------------------------------------------------------+ | error_code | luna error code | +--------------+----------------------------------------------------------------------------+ - fields +----------------+------------------------+ | fields | description | +================+========================+ | request_id | request id | +----------------+------------------------+ Custom Monitoring ----------------- For base monitoring usage information see `monitoring <./monitoring.html>`_. It is possible to create custom monitoring points. For example, there is a need to send data about how long it took to download or process images. It is possible to specify your own **series**, **tags** and **fields**, but there will always be a mandatory **tag** "service" with the "lambda-" value. For add custom monitoring point follow steps: 1) Add file **monitoring_points.py** to lambda archive with the following content: .. literalinclude:: examples/201/monitoring_lambda/lambda/monitoring_points.py :caption: monitoring_points.py :language: python There are several rules for this file: - The number of points can be any. - Each point class name may be specify by any unique name. - Each point class must be inherited by **CustomMonitoringPoint** - Each point class must contain **series** attribute to specify monitoring series. 2) Set monitoring points from **monitoring_points.py** to **lambda_main.py** and specify **tags** and **fields**: There are several general rules for this file: - Enable monitoring. See **INFLUX_MONITORING** setting in basic `principles of configuration <./config.html>`_. - If monitoring is unavailable, the points will not be sent without any errors. - Specify tags by set dictionary with tags to **pointTags** named argument. - Specify fileds by set dictionary with fields to **pointFields** named argument. .. warning:: There are diferencies between standalone, handlers and tasks lambda monitoring mechanism. See description below. Send points using **request.sendToMonitoring** function for **standalone** or **handlers** lambda: .. literalinclude:: examples/201/monitoring_lambda/lambda/lambda_main.py :caption: lambda_main.py :language: python .. literalinclude:: examples/201/monitoring_lambda/make_request.py :caption: request example :language: python Send points using **self.sendToMonitoring** function for **tasks** lambda: To run lambda tasks example, refer to the task processing description `here <./tasks.html#task-processing>`_. .. literalinclude:: examples/201/monitoring_lambda_task/lambda/lambda_main.py :caption: lambda_main.py :language: python .. literalinclude:: examples/201/monitoring_lambda_task/make_request.py :caption: request example :language: python Database -------- Monitoring is implemented as data sending to an `influx database `_.