飞书集成平台 x Grafana:打造监控告警系统全攻略

飞书集成平台 x Grafana:打造监控告警系统全攻略
Photo by Sigmund / Unsplash

Grafana告警内容设置

告警内容分为:告警标题告警说明告警详情。告警标题和告警说明用来描述告警的规则。告警详情,描述告警的规则和具体的值。

告警详情 Description 设置

  1. 打印所有的标签
{{ $labels }}

alertname=High CPU usage, grafana_folder=CPU alerts, instance=server1
  1. 自定义格式化打印所有的标签
{{ range $k, $v := $labels -}}
{{ $k }}={{ $v }}
{{ end }}

alertname=High CPU usage
grafana_folder=CPU alerts
instance=server1
  1. 打印单个标签
The host {{ index $labels "instance" }} has exceeded 80% CPU usage for the last 5 minutes

The host server1 has exceeded 80% CPU usage for the last 5 minutes
  1. 打印具体的值
{{ index $values "A"· }}

81.2345
  1. if - else 的使用
{{ if (gt $values.A.Value 80.0) -}}
high
{{ else if (gt $values.A.Value 50.0) -}}
medium
{{ else -}}
low
{{- end }}
  1. 其他格式化函数
函数
函数名
示例
输出
args

{{define "x"}}{{.arg0}} {{.arg1}}{{end}}{{template "x" (args 1 "2")}}
1 2
externalURL

{{ externalURL }}
https://example.com/grafana
graphLink

{{ graphLink "{\"expr\": \"up\", \"datasource\": \"gdev-prometheus\"}" }}
/explore?left=["now-1h","now","gdev-prometheus",{"datasource":"gdev-prometheus","expr":"up","instant":false,"range":true}]
humanize
易读
{{ humanize 1000.0 }}
1k
humanize1024
易读 1024
{{ humanize1024 1024.0 }}
1ki
humanizeDuration
易读 时长
{{ humanizeDuration 60.0 }}
1m 0s
humanizePercentage
易读 百分比
{{ humanizePercentage 0.2 }}
20%
humanizeTimestamp
易读 1024
{{ humanizeTimestamp 1577836800.0 }}
2020-01-01 00:00:00 +0000 UTC
match

{{ match "a.*" "abc" }}
true
pathPrefix

{{ pathPrefix }}
/grafana
tableLink

{{ tableLink "{\"expr\": \"up\", \"datasource\": \"gdev-prometheus\"}" }}
/explore?left=["now-1h","now","gdev-prometheus",{"datasource":"gdev-prometheus","expr":"up","instant":true,"range":false}]
title

{{ title "hello, world!" }}
Hello, World!
toLower

{{ toLower "Hello, world!" }}
hello, world!
toUpper

{{ toUpper "Hello, world!" }}
HELLO, WORLD!
reReplaceAll

{{ reReplaceAll "localhost:(.*)" "example.com:$1" "localhost:8080" }}
example.com:8080

详见文档:

https://grafana.com/docs/grafana/latest/alerting/fundamentals/annotation-label/variables-label-annotation/#functions

飞书集成平台

可以认为是一套开发可用的“低代码平台”,在本案例中,做了以下几个步骤:

  1. 触发器接受 grafana 的告警
  2. 从“值班”多维表格中获取今天值班人员信息
  3. 使用 javascript 预处理告警信息,包括:标题、内容、runbook、值班人员等
  4. 根据告警类型信息选择不同的飞书消息卡片模板
  5. 结合模板和数据,发送到告警群(可在集成平台中配置)

飞书集成平台的触发器提供一个回调地址,将地址填写到 grafana 联络点,选择 webhook 完成设置。

参考链接

Read more

Git hook 开发和实践,提升自动化效率

Git hook 开发和实践,提升自动化效率

我们使用 git 进行版本控制,期间会触发很多事件,这些利用好这些事件做好自动化,能帮我提升效率。git hook 就是一个这样的工具,在特定的事件中执行特定的钩子。 ╰─➤ ls .git/hooks applypatch-msg.sample post-update.sample pre-merge-commit.sample pre-receive.sample update.sample commit-msg.sample pre-applypatch.sample pre-push.sample prepare-commit-msg.sample fsmonitor-watchman.sample pre-commit.sample pre-rebase.sample push-to-checkout.sample 设置钩子路径 git 仓库的钩子存放路径由 core.hooksPath 控制,默认是在项目的 .git/hooks。它不能使用版本控制

By brian

MacOS 安装了最新版 Docker,命令行找不到了?

它藏在 /Applications/Docker.app 中,可以使用 find 命令查看: $cd /Applications/Docker.app $find . -name "docker" ./Contents/Resources/bin/docker 将 bin 目录拼接到 PATH 环境变量即可,一般可以追加到 ~/.bashrc ~/.zshrc 中。 export PATH=/Applications/Docker.app/Contents/Resources/bin:$PATH source ~/.zshrc 使环境变量生效,执行 docker 检查版本 $ source ~/.zshrc $ docker --version Docker

By brian
沪ICP备2022013452号-1