You need to enable JavaScript to run this app.
文档中心
全栈可观测平台

全栈可观测平台

复制全文
下载 pdf
通知模板
应用性能监控扩展函数与变量
复制全文
下载 pdf
应用性能监控扩展函数与变量
通知内容模板中允许使用预置的告警变量,本文为您介绍应用性能监控预置的告警变量结构和参数含义。​
扩展函数​
应用性能监控通知内容模版中,支持 Go Template 内置函数和扩展函数。详情如下表所示:​
​
函数​
说明​
Go Template 内置函数​
通知内容模版支持使用 range、if、with、len 等 Go Template 内置函数,详情请参见 官方文档。​
translate(typ, lang, val)​
将 Type、Region 等值转为自然语言。示例:{{ translate "Type" "zh" .Type }}。​
levelColor(level, isRecovered)​
根据级别和是否恢复返回渠道颜色值。示例:{{ levelColor .Level false }}。​
levelCss(level, isRecovered)​
根据级别和是否恢复返回 CSS class。示例:{{ levelCss .Level false }}。​
formatKeyValues(kvs)​
将 []KeyValues 格式化为 k={v1,v2} 文本。示例:{{ formatKeyValues .Labels }}。​
getMetrics(typ, metrics)​
按告警类型筛出更适合展示的指标列表。示例:{{ range $m := getMetrics .Type $resource.Metrics }}。​
时间格式化​
time.Time 字段支持 .Format。示例:{{ .HappenedAt.Format "2006-01-02 15:04:05" }}。​
​
数据结构​
本文通过以下 JSON 示例代码,展示应用性能监控告警信息所包含的变量、参数和数据结构。方便您理解 Go Template 的常用语法和使用方式。​
​
{​
"Type": "Metric",​
"SiteName": "APMPlus",​
"AccountName": "AlertAccount",​
"AccountId": "210xxxxx7",​
"Region": "cn-beijing",​
"HappenedAt": "2026-06-24T21:23:25+08:00",​
"Level": "Fatal",​
"ProjectName": "default",​
"Domain": "",​
"MaxTitleLen": 512,​
"MaxContentLen": 16384,​
"MaxCount": 5,​
"LarkNotifyVerify": {​
"NeedVerify": false,​
"Timestamp": 0,​
"Sign": ""​
},​
"EmailFooterLogo": "volc_logo",​
"RuleName": "Alert",​
"RuleURL": "https://console.volcengine.com/observe/apmplus-server/region:apmplus-server+cn-beijing/server/alarm/detail?name=......%26rule_id=......",​
"RuleType": "Service Alert",​
"RuleDesc": "Template: Test Template, Rule: Test Rule, Application: ......",​
"CreateSilenceURL": "",​
"Workspace": "Test-Workspace",​
"RelatedServices": [​
"test1......",​
"test2-......"​
],​
"Labels": [],​
"ContentsByCondition": [​
"Alert triggers when all the following conditions are met simultaneously",​
"Error Rate No filter conditions, aggregated by average grouped by [service], greater than ......% in the last 5 minutes"​
],​
"Resources": [​
{​
"AlertGroupId": "69afbf........625ccb7",​
"Region": "cn-beijing",​
"ServiceName": "test1......",​
"ServiceMonitorURL": "",​
"FirstAlertTime": "2026-06-24T21:23:25+08:00",​
"LastAlertTime": "2026-06-24T21:23:25+08:00",​
"Metrics": [​
{​
"Name": "Error Rate",​
"Unit": "%",​
"Threshold": "......",​
"Value": "......",​
"Description": "Error Rate No filter conditions, aggregated by average grouped by [service], greater than ......% in the last 5 minutes",​
"Warn": true,​
"IsTimeCompare": false,​
"InherentUnit": "",​
"LastValue": "",​
"CurrentValue": "",​
"Index": 0,​
"DeltaValue": ""​
}​
],​
"GroupBy": "{service = test1......}",​
"GroupByTags": [​
{​
"Key": "service",​
"Value": "test1......"​
}​
]​
},​
}​
​
变量说明​
说明​
  • 对于非嵌套变量,可以使用 Go Template 标准方式,获取变量的值。例如{{ .Region }}。​
  • 对于嵌套变量,需要通过自定义变量的方式获取所有的资源。例如定义$resource变量,然后通过遍历的方式获取所有的资源{{ range $idx, $resource := .Resources }}。对于内部变量,则需使用$resource.字段名的方式获取变量的值,例如{{ $resource.Id }}。​
通知内容模板中,可以使用的预置变量和说明,如下表所示。​
​
变量名​
类型​
说明​
示例​
用法示例​
Type​
string​
告警类型。​
Metric / MetricRecovered​
{{ translate "Type" "zh" .Type }}​
SiteName​
string​
站点名称。​
火山引擎​
{{ .SiteName }}​
AccountName​
string​
账号名称。​
test_user(12345)​
{{ .AccountName }}​
AccountId​
string​
账号 ID。​
21000*****​
{{ .AccountId }}​
Region​
string​
地域。​
cn-beijing​
{{ translate "Region" "zh" .Region }}​
HappenedAt​
time.Time​
告警发生时间。​
2025-12-01T00:00:00+08:00​
{{ .HappenedAt.Format "2006-01-02 15:04:05" }}​
Level​
string​
告警级别。​
critical​
{{ .Level }}​
ProjectName​
string​
项目名称。​
default​
{{ .ProjectName }}​
TagSet​
[]Tag​
标签集合。​
[{Key:"service",Value:"test1"}]​
{{ range .TagSet }}{{ .Key }}={{ .Value }} {{ end }}​
Domain​
string​
控制台域名。​
console.volcengine.com​
{{ .Domain }}​
MaxCount​
int​
当前渠道最多展示的资源数量。​
5​
{{ .MaxCount }}​
RuleName​
string​
规则名称。​
服务告警测试​
{{ .RuleName }}​
RuleURL​
string​
规则详情链接。​
https://.../server/alarm/detail?...​
[查看规则]({{ .RuleURL }})​
RuleType​
string​
规则类型文案。​
服务报警​
{{ .RuleType }}​
RuleDesc​
string​
规则描述。​
模版:测试模板...​
{{ .RuleDesc }}​
CreateSilenceURL​
string​
创建静默规则链接。​
空字符串或 URL​
[创建静默]({{ .CreateSilenceURL }})​
RelatedServices​
[]string​
受影响服务列表。​
["test1......", "test2-......"]​
{{ range .RelatedServices }}{{ . }} {{ end }}​
Labels​
[]KeyValues​
规则标签列表。​
[]​
{{ formatKeyValues .Labels }}​
ContentsByCondition​
[]string​
按条件生成的触发策略描述。​
以下同时满足时触发报警​
{{ range .ContentsByCondition }}{{ . }}\n{{ end }}​
Resources​
[]APMPlusResource​
告警资源列表。​
2 个 service 资源​
{{ range $resource := .Resources }}{{ $resource.ServiceName }}{{ end }}​
​
Tag​
​
变量名​
类型​
说明​
示例​
用法示例​
Key​
string​
标签 Key。​
service​
{{ $tag.Key }}​
Value​
string​
标签 Value。​
test1......​
{{ $tag.Value }}​
​
KeyValues​
​
变量名​
类型​
说明​
示例​
用法示例​
Key​
string​
标签键。​
env​
{{ $label.Key }}​
Values​
[]string​
同一个键下的多个值。​
["prod", "stg"]​
{{ range $v := $label.Values }}{{ $v }} {{ end }}​
​
APMPlusResource​
​
变量名​
类型​
说明​
示例​
用法示例​
AlertGroupId​
string​
告警组 ID。​
69afbf........625ccb7​
{{ $resource.AlertGroupId }}​
Region​
string​
资源所在地域。​
cn-beijing​
{{ translate "Region" "zh" $resource.Region }}​
ServiceName​
string​
服务名。​
test1......​
{{ $resource.ServiceName }}​
ServiceMonitorURL​
string​
服务监控详情链接。​
https://.../service/...​
[服务监控]({{ $resource.ServiceMonitorURL }})​
FirstAlertTime​
time.Time​
首次告警时间。​
2025-12-01T00:00:00+08:00​
{{ $resource.FirstAlertTime.Format "2006-01-02 15:04:05" }}​
LastAlertTime​
time.Time​
最近一次告警时间。​
2025-12-01T00:00:00+08:00​
{{ $resource.LastAlertTime.Format "2006-01-02 15:04:05" }}​
Metrics​
[]APMPlusMetricValue​
该资源下的指标列表。​
1 条错误率指标​
{{ range $m := $resource.Metrics }}{{ $m.Name }}={{ $m.Value }}{{ end }}​
GroupBy​
string​
资源聚合展示字符串。​
{service = test1......}​
{{ $resource.GroupBy }}​
GroupByTags​
[]Tag​
资源聚合标签集合。​
[{Key:"service",Value:"test1......"}]​
{{ range $tag := $resource.GroupByTags }}{{ $tag.Key }}={{ $tag.Value }} {{ end }}​
​
APMPlusMetricValue​
​
变量名​
类型​
说明​
示例​
用法示例​
Name​
string​
指标名称。​
错误率​
{{ $metric.Name }}​
Unit​
string​
展示单位。​
%​
{{ $metric.Unit }}​
Threshold​
string​
阈值文本。​
......​
{{ $metric.Threshold }}​
Value​
string​
当前值或变化率。​
......​
{{ $metric.Value }}​
Description​
string​
指标描述。​
错误率 无筛选条件 按平均聚合...​
{{ $metric.Description }}​
Warn​
bool​
是否为告警指标。​
true​
{{ $metric.Warn }}​
IsTimeCompare​
bool​
是否为同比 / 环比指标。​
false​
{{ $metric.IsTimeCompare }}​
InherentUnit​
string​
指标固有单位。​
空字符串​
{{ $metric.InherentUnit }}​
LastValue​
string​
上一窗口值。​
空字符串​
{{ $metric.LastValue }}​
CurrentValue​
string​
当前窗口值。​
空字符串​
{{ $metric.CurrentValue }}​
Index​
int​
条件索引。​
0​
{{ $metric.Index }}​
DeltaValue​
string​
变化绝对值。​
空字符串​
{{ $metric.DeltaValue }}​
​
​
最近更新时间:2026.07.01 17:46:30
这个页面对您有帮助吗?
有用
有用
无用
无用