You need to enable JavaScript to run this app.
Volcengine Managed Service for Prometheus

Volcengine Managed Service for Prometheus

Copy page
Download PDF
Notification template
Extension functions and variables
Copy page
Download PDF
Extension functions and variables
You can use preset alert variables in notification templates. This topic describes the structure and parameters of preset alert variables.​
Data structure​
This topic demonstrates the variables, parameters, and data structure contained in the alert information of Volcengine Managed Service for Prometheus (VMP) by using the following sample JSON code. This helps you understand common Go template syntax and its usage.​
​
{​
"Region": "cn-beijing",​
"AlertingRuleName": "The CPU utilization is greater than 80%",​
"AlertingRuleDescription": "Alert description",​
"AlertingRuleDetailURL": "https://console.volcanicengine.com/prometheus/***3503d49e/detail",​
"Level": "P0",​
"PromQL": "rate(cpu_total[1m])",​
"Comparator": ">",​
"Threshold": "0.8",​
"For": "3m",​
"Alerts": [​
{​
"Id": "cdwaihonj434390ad",​
"Labels": {​
"cluster": "ccmp26s0bjh01jhk860f0",​
"namespace": "default",​
"service": "nginx",​
"pod": "nginx-85996***"​
},​
"Value": "0.84",​
"StartsAt": "2024-02-02 17:13:32.065 +0800 CST",​
"EndsAt": "2024-02-02 17:13:32.065 +0800 CST",​
"DetailURL": "https://console.volcanicengine.com/prometheus/***/alert/alerting?detail_id=***"​
}​
]​
}​
​
Parameter description​
The following table describes the parameters and descriptions of preset variables that can be used in the notification template.​
​
Variable​
Type​
Sample Value​
Description​
Region​
String​
cn-beijing​
The region where the alert was triggered. Valid values:​
  • cn-beijing: China (Beijing)​
  • cn-shanghai: China (Shanghai)​
  • cn-guangzhou: China (Guangzhou)​
tip​
For more details, refer to Regions and Availability Zones.​
AlertingRuleName​
String​
The CPU utilization is greater than 80%​
The name of the alerting rule.​
AlertingRuleDescription​
String​
Alert description​
The description of the alerting rule.​
AlertingRuleDetailURL​
String​
https://console.volcanicengine.com/prometheus/***3503d49e/detail​
The URL of the alerting rule. This URL can redirect you to the corresponding alerting rule.​
Level​
String​
P0​
The alert level. Valid values: P0, P1, and P2.​
PromQL​
String​
rate(cpu_total[1m])​
The PromQL statement that is used to trigger the alert in the alerting rule.​
Comparator​
String​
>​
The alert comparison condition. Valid values:​
  • >: greater than​
  • >=: greater than or equal to​
  • <: less than​
  • <=: less than or equal to​
  • ==: equal to​
  • !=: not equal to​
Threshold​
String​
0.8​
The threshold of the alert.​
For​
String​
3m​
The duration of the alert.​
Alerts​
Object Alerts​
-​
The details of the alert resource, which is displayed in a nested structure.​
​
Alerts​
​
Variable​
Type​
Sample Value​
Description​
Id​
String​
cdwaihonj434390ad​
The alert ID.​
Labels​
map[string]string​
​
"cluster": "ccmp26s0bjh01jhk860f0",​
"namespace": "default",​
"service": "nginx",​
"pod": "nginx-85996***"""
​
The details of the failed resource in the alert.​
Value​
Float64​
0.84​
The alert value.​
tip​
This parameter only applies to the alerting notification templates and does not apply to the alerting restoration notification template.​
StartsAt​
time.Time​
2024-02-02 17:13:32.065 +0800 CST​
The start time of the alert.​
EndsAt​
time.Time​
2024-02-02 17:13:32.065 +0800 CST​
The end time of the alert.​
tip​
This parameter applies to the alerting restoration notification templates and does not apply to the alerting notification template.​
DetailURL​
String​
https://console.volcanicengine.com/prometheus/***/alert/alerting?detail_id=***​
The URL of the alert in the console. This URL can redirect you to the corresponding alert.​
​
Extension functions​
​
Function​
Description​
​
vkeClusterName​
Obtains a cluster name based on the clusterID of a Volcengine Kubernetes Engine (VKE) cluster.​
The VKE metrics written through the collection add-on in a VKE cluster will contain the cluster label, whose value is the cluster ID. You can also use the extension function to obtain a cluster name in an alerting notification. You can perform the following configuration to obtain the cluster name:​
  1. Ensure that the triggered alerts contain the cluster label. For example, you can use sum(up)by(job,cluster) to achieve aggregation by cluster when you configure alerts. In this case, the labels of the alerts will contain the cluster label.​
  1. When you configure an alerting notification template, use the vkeClusterName function to obtain the cluster name. Line 4 of the following sample code shows how to obtain the cluster name.​
​
{{ range $i, $alert := .Alerts -}}​
{{ if lt $i 5 -}}​
No. {{ add1 $i }} resource{{ if $alert.Annotations }}:​
Cluster name: {{ $alert.Labels.cluster | vkeClusterName }}​
{{- range $key, $value := $alert.Labels }}​
{{ $key }}: {{ $value }}​
{{- end }}​
Current value: {{ $alert.Value }}​
Alert ID: {{ $alert.Id }}​
Alert start time: {{ date "2006-01-02T15:04:05Z07:00" $alert.StartsAt }}​
​
---​
​
{{ else if eq $i 5 -}}​
The details of only top 5 failed resources are displayed. Click [alert content details]({{ $.AlertListConsoleURL }}) to view more details.​
{{- end }}​
{{- end }}​
​
arkEndpointName​
Obtains an endpoint name based on endpointID.​
The metrics written by ModelArk are all added with the ark_endpoint label, whose value is an endpoint ID. You can also use the extension function to obtain an endpoint name in an alerting notification. You can perform the following configuration to obtain the endpoint name:​
  1. Ensure that the triggered alerts contain the ark_endpoint label. For example, you can use sum by(ark_endpoint,api)(rate(ark_api_proxy_request_total{}[2m])) to achieve aggregation by ark_endpoint when you configure alerts. In this case, the labels of the alerts will contain the ark_endpoint label.​
  1. When you configure an alerting notification template, use the arkEndpointName function to obtain the endpoint name. Line 4 of the following sample code shows how to obtain the endpoint name.​
​
{{ range $i, $alert := .Alerts -}}​
{{ if lt $i 5 -}}​
No. {{ add1 $i }} resource{{ if $alert.Annotations }}:​
Endpoint name: {{ $alert.Labels.ark_endpoint | arkEndpointName }}​
{{- range $key, $value := $alert.Labels }}​
{{ $key }}: {{ $value }}​
{{- end }}​
Current value: {{ $alert.Value }}​
Alert ID: {{ $alert.Id }}​
Alert start time: {{ date "2006-01-02T15:04:05Z07:00" $alert.StartsAt }}​
​
---​
​
{{ else if eq $i 5 -}}​
The details of only top 5 failed resources are displayed. Click [alert content details]({{ $.AlertListConsoleURL }}) to view more details.​
{{- end }}​
{{- end }}​
​
​
Configuration example​
In addition to the preset alerting templates of the system, you can specify custom content of a notification template based on the data structure of alert variables, Go template syntax, and Markdown syntax. The following section shows the configuration example.​
warning​
  • The details of failed resources are obtained through the .Alerts.Labels variable, and the value of the Labels parameter may vary based on different resources. In this example, parameters that contain Labels.* such as $alert.Labels.instance) are used for illustration only. In actual configuration, you need to specify the existing Labels variable of resources.​
  • If your notification template includes multiple resource types, you can also choose not to specify a specific Label variable and instead view the details of each failed resource. For the configuration method, refer to the Template example description section of the Creating a notification template topic.​
​
**Alert information**:​
​
---​
​
Alert region: {{ .Region }}​
Alerting rule name: {{ .AlertingRuleName }}​
Alerting rule description: {{ .AlertingRuleDescription }}​
Alerting rule URL: {{ .AlertingRuleDetailURL }}​
Alert level: {{ .Level }}​
PromQL statement of Alerting rule: {{ .PromQL }}​
Alert comparison condition: {{ .Comparator }}​
Alert threshold: {{ .Threshold }}​
Alert duration: {{ .For }}​
​
---​
{{- $alertCount := len .Alerts }}​
{{- $maxAlerts := 10 }}​
​
**Failed resource details ({{ $alertCount }})**:​
{{- range $idx, $alert := .Alerts }}​
{{- if lt $idx 10 }}​
{{- $labels := "" -}}​
<br>​
Failed resource ID: {{- $alert.Id }}​
Failed resource cluster: {{- $alert.Labels.cluster }}​
Failed resource instance: {{- $alert.Labels.instance }}​
Failed resource job: {{- $alert.Labels.job }}​
Value of failed resource metric: {{- $alert.Value }}​
Failure start time: {{- $alert.StartsAt }}​
Alert URL: {{- $alert.DetailURL}}​
{{- end }}​
{{- end }}​
​
---​
​
{{- if gt $alertCount $maxAlerts }}​
**The number of resources has exceeded {{ $maxAlerts }}. For complete alert, go to the console**.​
{{- end }}​
​
​
Last updated: 2026.07.10 11:37:26