我正在尝试在 helm chart 中设置 grafana 警报。
为此,使用来自另一个 grafana 实例的现有手动创建的警报,我们希望使用 helm chart 默认将其保留在新的 grafana 设置中。
由于找不到任何导出/导入选项,尝试手动编辑。在此示例中:helm-charts/values.yaml at main · grafana/helm-charts (github.com)
在值文件中找到警报选项关联/ 但无法设置以下属性
但是,无法在值文件中找到要设置的以下选项。
请帮忙。还有,在哪里可以获取 datasourceUid 和 orgId 值来设置在警报中?
图表中的示例规则:
alerting:
rules.yaml:
apiVersion: 1
groups:
- orgId: 1
folder: "Performance Metrics"
name: qtm
interval: 60s
rules:
- uid: my_id_1
condition: B
title: qtm
data:
- refId: A
queryType: ""
relativeTimeRange:
from: 600
to: 0
datasourceUid: "-100"
model:
editorMode: code
expr: '100 * (sum(rate(n_bolt_api_usage{app="data-cruncher-read-replica", err="internal"}[60m])) or vector(0)) / (vector(1) or (sum(rate(n_bolt_api_usage{app="data-cruncher-read-replica"}[60m]))))'
hide: false
intervalMs: 1000
legendFormat: __auto
maxDataPoints: 43200
range: true
refId: A
- refId: B
queryType: ""
relativeTimeRange:
from: 0
to: 0
datasourceUid: "-100"
model:
conditions:
- evaluator:
params:
- 10
type: gt
operator:
type: and
query:
params:
- A
reducer:
params: []
type: last
type: query
datasource:
type: __expr__
uid: "-100"
expression: A
hide: false
intervalMs: 1000
maxDataPoints: 43200
refId: B
type: classic_conditions
updated: "2022-09-22T18:27:51Z"
noDataState: NoData
execErrState: Alerting
for: 1h
annotations:
summary: P1 QTM High Internal Errors in API Usage
收到错误如下:
logger=ngalert uid=my_id_1 org=1 version=4 attempt=0 now=2022-09-23T15:52:00Z t=2022-09-23T15:52:00.001235843Z level=error msg="无法评估警报规则" results="[{Instance: State:Error Error:无法执行条件:'A'中的表达式命令类型无效 EvaluatedAt:2022-09-23 15:52:00 +0000 UTC EvaluationDuration:1.232689ms EvaluationString: Values:map[]}]" duration=92.684µs
答案1
这是最新版本(9.1.x iirc)中的一个新功能
并在这里的文档中讨论https://grafana.com/docs/grafana/latest/administration/provisioning/#alerting
可以将其包含在 gafana 值文件中,如下所示:
例如
alerting:
rules.yaml: |
apiVersion: 1
groups:
....
contactpoints.yaml: |
apiVersion: 1
contactPoints:
....
查看 PRhttps://github.com/grafana/helm-charts/pull/1720了解详情。
和orgId
您datasourceUid
应该已经拥有了,因为您在之前已在values.yaml
(https://grafana.com/docs/grafana/latest/administration/provisioning/#data-sources)
至于如何获取警报查询部分,我认为这意味着您必须在 Web UI 中手动构建它,然后通过 API 提取它(https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#route-get-alert-rule)
condition: A
# <list, required> list of query objects that should be executed on each
# evaluation - should be obtained trough the API
data:
...