Recording rules
In Yandex Managed Service for Prometheus®, you can use your existing recording rule
Warning
The file name may contain lowercase Latin letters, numbers, hyphens, and underscores. The file may be up to 256 characters long. The group name may not be longer than 256 characters.
The API is represented by REST resources located at https://monitoring.api.cloud.yandex.net/prometheus/workspaces/<workspace_ID>/extensions/v1/rules
. To start executing requests:
- Specify the ID of your workspace in the URL. You can find the workspace ID in the Monitoring UI under Prometheus.
- Install cURL
. - Authenticate in the API.
Creating or replacing a recording rule file
-
Create an RFC 4648 Base64
encoding of the file contents:cat recording-rule.yaml # groups: # - name: example # rules: # - record: example # expr: up base64 -i recording-rule.yaml # Z3JvdXBzOgogIC0gbmFtZTogZXhhbXBsZQogICAgcnVsZXM6CiAgICAtIHJlY29yZDogZXhhbXBsZQogICAgICBleHByOiB1cA==
-
Save the result as a JSON file:
body.json
{ "name": "recording-rules", "content" : "Z3JvdXBzOgogIC0gbmFtZTogZXhhbXBsZQogICAgcnVsZXM6CiAgICAtIHJlY29yZDogZXhhbXBsZQogICAgICBleHByOiB1cA==" }
-
Create or replace a recording rule file:
export IAM_TOKEN=<IAM_token> curl \ --request PUT \ --header "Content-Type: application/json" \ --header "Authorization: Bearer ${IAM_TOKEN}" \ --data "@body.json" \ "https://monitoring.api.cloud.yandex.net/prometheus/workspaces/<workspace_ID>/extensions/v1/rules"
If the request is successful, you will get the 204
HTTP code, if not, the error text.
If any rules or groups of rules are deleted when replacing a file, they will no longer be computed. All new rules and groups of rules will start to be computed.
Getting a list of files
Run the following query:
export IAM_TOKEN=<IAM_token>
curl \
--request GET \
--header "Authorization: Bearer ${IAM_TOKEN}" \
"https://monitoring.api.cloud.yandex.net/prometheus/workspaces/<workspace_ID>/extensions/v1/rules"
Response example:
{
"files": [
"recording-rules"
]
}
Viewing the file contents
Run the following query:
export IAM_TOKEN=<IAM_token>
curl \
--request GET \
--header "Authorization: Bearer ${IAM_TOKEN}" \
"https://monitoring.api.cloud.yandex.net/prometheus/workspaces/<workspace_ID>/extensions/v1/rules/recording-rules"
Response example:
{
"name": "recording-rules",
"content": "Z3JvdXBzOgogIC0gbmFtZTogZXhhbXBsZQogICAgcnVsZXM6CiAgICAtIHJlY29yZDogZXhhbXBsZQogICAgICBleHByOiB1cA=="
}
Viewing file computation status
You can get the computation status for any rule in all file groups by using the snapshots
REST resource. Each snapshot contains information about the status, error, rule name, and computation time.
Run the following query:
export IAM_TOKEN=<IAM_token>
curl \
--request GET \
--header "Authorization: Bearer ${IAM_TOKEN}" \
"https://monitoring.api.cloud.yandex.net/prometheus/workspaces/<workspace_ID>/extensions/v1/rules/recording-rules/snapshots"
Response example:
{
"snapshotByGroup": {
"example": [
{
"state": "OK",
"error": "",
"evaluationTimeMs": 21,
"evaluatedAtTimeEpochMs": 1710490243322,
"record": "example"
}
]
}
}
Possible rule states:
NOT_EVALUATED_YET
: File is uploaded but computation has not started yet.OK
: Computation successful.LIMIT_EXCEEDED
: Number of time series returned by the rule exceeds thelimit
specified in the YAML file. For such rules, partial computation result is not saved.TIMEOUT
: Rule computation timed out.UNEXPECTED_RESULT_TYPE
: Unexpected computation result, e.g., a string.UNKNOWN_ERROR
: Generic error not described by any of the above states.
Deleting a file
Run the following query:
export IAM_TOKEN=<IAM_token>
curl \
--request DELETE \
--header "Authorization: Bearer ${IAM_TOKEN}" \
"https://monitoring.api.cloud.yandex.net/prometheus/workspaces/<workspace_ID>/extensions/v1/rules/recording-rules"
© 2024 Linux Foundation. All rights reserved. The Linux Foundation owns and uses registered trademarks. For a list of Linux Foundation trademarks, see Trademark Usage