Writing metrics to Monitoring
Monitoring allows you to collect and store metrics and display them as charts on dashboards. Data sent to Monitoring consists of 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, e.g., a host name or application version, serves as 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.editorpermissions.To use a service account, the
iam.serviceAccounts.userrole is required. -
Click Create to create a connection.
Data model
To write metrics to Monitoring, use this 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 with 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. Yandex Query supports
DGAUGEandIGAUGEmetrics. - List of labels.
Yandex Query automatically prints the semantics of parameters from the SQL query.
| Field type | Description | Constraints |
|---|---|---|
Time: Date, Datetime, Timestamp, TzDate, TzDatetime, or TzTimestamp |
Timestamp common for all metrics | A query may only contain one timestamp field. |
Integer: Bool, Int8, Uint8, Int16, Uint16, Int32, Uint32, Int64, or 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 or 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 or Utf8 |
Label values | The field name in an SQL statement is the label name, and the 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
Example of a query to write 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 |
Data source in the SQL query. This may be a YQL subquery, including a connection to the data source. | |
my_timestamp |
Timestamp | Data source: my_timestamp column in the data source stream (stream) |
exception_count |
Metrica | Data source: exception_count column in the data source stream (stream) |
host_name |
Label | Data source: host column in the data source stream (stream) |
app_version |
Label | Data source: app_version column in the data source stream (stream) |
Result example for a query to Monitoring:
