Writing metrics to Monitoring
Monitoring allows you to collect and store metrics and display them as charts on dashboards. Data sent to Monitoring represents measured values (metrics
) and labels
that describe them.
For example, to track the number of application failures, you can use the failure count per time interval as a metric. Data describing a failure, such as host name and application version, are labels. The Monitoring interface allows you to aggregate metrics by label.
Example of writing metrics from Yandex Query to Monitoring:
INSERT INTO `monitoring`.custom
SELECT
`my_timestamp`,
host_name,
app_version,
exception_count,
"exception_monitor" as service_type
FROM $query;
Under streaming processing, Yandex Query can send query results to Monitoring as metrics and their labels.
Setting up a connection
To send metrics to Monitoring:
-
Go to Connections in the Yandex Query interface and click Create new.
-
In the window that opens, specify a name for a connection to Monitoring in the Name field.
-
In the drop-down list under Type, select
Monitoring
. -
In the Service account field, select the service account to use for metric writes. You can also create a new service account with the
monitoring.editor
permissions.To use a service account, the
iam.serviceAccounts.user
role is required. -
Click Create to create a connection.
Data model
Metrics are written to Monitoring using the following SQL statement:
INSERT INTO
<connection>.custom
SELECT
<fields>
FROM
<query>;
Where:
<connection>
: Name of the Monitoring connection created in the previous step.<fields>
: List of fields that contain a timestamp, metrics, and their labels.<query>
: Yandex Query data source query.
Note
When writing metrics, use INSERT INTO <connection>.custom
, where custom
is the name reserved in Monitoring for writing custom metrics.
Metrics are written using the write Monitoring API method. Pass the following when writing metrics:
- Timestamp.
- List of metrics with their type specified. Yandex Query supports the
DGAUGE
andIGAUGE
metric types. - List of labels.
Yandex Query automatically prints the semantics of parameters from the SQL query.
Field type | Description | Limitations |
---|---|---|
Time: Date , Datetime , Timestamp , TzDate , TzDatetime , and TzTimestamp |
Timestamp common for all metrics | A query may only contain one field with the timestamp. |
Integer: Bool , Int8 , Uint8 , Int16 , Uint16 , Int32 , Uint32 , Int64 , and Uint64 |
Metric values, IGAUGE |
The SQL query field name is the metric name. A single query may contain an unlimited number of metrics. |
With a floating point: Float and Double |
Metric values, DGAUGE |
The SQL query field name is the metric name. A single query may contain an unlimited number of metrics. |
Text: String and Utf8 |
Label values | The SQL query field name is the label name, while a text value is the label value. A single query may contain an unlimited number of metrics. |
No other data types are allowed in the fields.
Example of writing metrics
Sample query for writing metrics from Yandex Query to Monitoring:
INSERT INTO
`monitoring`.custom
SELECT
`my_timestamp`,
host AS host_name,
app_version,
exception_count,
"exception_monitor" as service_type
FROM $query;
Where:
Field | Type | Description |
---|---|---|
monitoring |
Monitoring connection name | |
$query |
SQL query data source, can be a YQL subquery, including a connection to the data source | |
my_timestamp |
Timestamp | Data source (my_timestamp column in the source stream ) |
exception_count |
Metric | Data source (exception_count column in the source stream ) |
host_name |
Label | Data source (host column in the source stream ) |
app_version |
Label | Data source (app_version column in the source data stream ) |
Sample query execution result in Monitoring.