Writing metrics to Monitoring
Monitoring allows you to collect and store metrics, as well as display them as charts on dashboards. Data sent to Monitoring includes metrics and their descriptive labels.
For example, to track application failures, you can use the failure count per time interval as a metric. Data describing a failure, e.g., a host name and application version, serve as labels. The Monitoring interface allows you to aggregate metrics by label.
Query example for writing metrics from Yandex Query into Monitoring
INSERT INTO `monitoring`.custom
SELECT
`my_timestamp`,
host_name,
app_version,
exception_count,
"exception_monitor" as service_type
FROM $query;
During stream processing, Yandex Query can send query results to Monitoring as metrics and their labels.
Setting up a connection
To send metrics to Monitoring:
-
Navigate to the Connections section of the Yandex Query interface and click Create new.
-
In the window that opens, specify the Monitoring connection name in the Name field.
-
In the Type dropdown, select
Monitoring. -
In the Service account field, select an existing service account or create a new one. Assign it the
monitoring.editorpermissions allowing it to write metrics.To use the service account on your behalf, you need the
iam.serviceAccounts.userrole. -
Click Create to create a connection.
Data model
To write metrics to Monitoring, use 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 include a timestamp, metrics, and their labels.<query>: Yandex Query source data query.
Note
When writing metrics, use the INSERT INTO <connection>.custom statement, where custom is the name reserved in Monitoring for user-defined metrics.
To write metrics, use the write Monitoring API method. When writing metrics, provide the following information:
- Timestamp.
- List of metrics and their types. Yandex Query supports
DGAUGEandIGAUGEmetric types. - List of labels.
Yandex Query automatically infers parameter semantics from the SQL query.
| Field type | Description | Limitations |
|---|---|---|
Time: Date, Datetime, Timestamp, TzDate, TzDatetime, or TzTimestamp |
Common timestamp for all metrics | A query can have only one timestamp field. |
Integer: Bool, Int8, Uint8, Int16, Uint16, Int32, Uint32, Int64, or Uint64 |
Metric values, IGAUGE |
The field name in the SQL statement is the metric name. A single query may contain an unlimited number of metrics. |
Floating point: Float or Double |
Metric values, DGAUGE |
The field name in the SQL statement is the metric name. A single query may contain an unlimited number of metrics. |
Text: String or Utf8 |
Label values | The field name in the SQL statement serves as the label name, and its text value as the label value. A single query may contain an unlimited number of metrics. |
No other data types are permitted in these fields.
Metrics writing example
Query example 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. It can be a YQL subquery or a data source connection | |
my_timestamp |
Timestamp | Data source: my_timestamp column in the source data stream |
exception_count |
Metric | Data source: exception_count column in the source data stream |
host_name |
Label | Data source: host column in the source data stream |
app_version |
Label | Data source: app_version column in the source data stream |
Example of query results in Monitoring:
