表达式

数据类型

  1. Scalar: This is the simplest type, it is a single numeric value with no group associated with it. Keep in mind that an empty group, “{}” is still a group.
  2. NumberSet: A number set is a group of tagged numeric values with one value per unique grouping. As a special case, a scalar may be used in place of a numberSet with a single member with an empty group.
  3. SeriesSet: A series is an array of timestamp-value pairs and an associated group.

运算符

分类

  1. 标准算术运算符:+,-, *, /, %
  2. 关系运算符:<,>, ==, !=, >=, <=
  3. 逻辑运算符:&&,||,!

优先级

从高到低如下:
1. () ,一元运算符 ! 和 -
1. *,/,%
1. +,-
1. ==,!=,>,>=,<,<=
1. &&
1. ||

常用函数

  • q(query string, startDuration string, endDuration string)
    代表的是查询从“endDuration ”开始到“startDuration ”之前的数据,若第三个参数为空,则代表的是当前时刻。该函数是Open TSDB中常用的查询函数。如查询从现在开始到一分钟之前的所有主机被使用的内存,代码如下:
q("avg:os.mem.used{host=*}", "1m", "")

result列显示对应主机内存使用情况,是一个数值集合结果。结果如下:

  • avg(seriesSet): 求平均值,返回的是数值结果。如计算“vs123”主机一分钟内使用内存的平均值,表达式如下:
avg(q("avg:os.mem.used{host=vs123}", "1m", ""))

结果如下:

  • max(seriesSet):求最大值,返回的是数字结果。
max(q("avg:os.mem.used{host=vs123}", "1m", ""))

结果如下:

  • min(seriesSet):求最小值,返回的是数字结果。
  • sum(seriesSet):求和,返回的是数字结果。
q("avg:os.mem.used{host=vs123}", "1m", "")

sum(q("avg:os.mem.used{host=vs123}", "1m", ""))

  • t(numberSet, group string):分组函数。
    如查看以“vs12”开头主机的内存使用,未转换之前:
avg(q("avg:os.mem.used{host=vs12*}", "1m", ""))


使用转换函数之后:

t(avg(q("avg:os.mem.used{host=vs12*}", "1m", "")),"")

  • limit(numberSet, count scalar):限制结果
  • filter(seriesSet, numberSet):过滤结果
    如下:过滤出以“vs”开头的主机中CPU使用最高的前10个主机
filter(q("sum:os.cpu{host=regexp(^vs)}", "1m", ""),limit(sort(avg(q("sum:os.cpu{host=regexp(^vs)}", "1m", "")),"desc"),10))

预警配置

预警配置中分为alert、template、lookup、notification、macro五个部分,每个部分要以“{}”包围,基本的预警需要包括template、alert、notification(邮件配置)三部分。

变量

定义规则:以“”开头,可以使用“”包围变量,如:”开头,可以使用“{}”包围变量,如:{var}、var。全局变量:以“env.”开头,如:tsdbHost=var。 全局变量:以“env.”开头,如:tsdbHost = {env.TSDBHOST}

模板(template)

模板用于以一定的格式发送预警消息,如:使用邮件发送预警通知时,邮件主题以及内容将会匹配特定的模板,以设置好的样式发送预警邮件。

  • 模板的内容包括:

    • body: 消息内容(HTML)
    • subject: 消息主题(plaintext)
  • 预警模板常用的函数:
    • Eval(string)
    • EvalAll(string)
    • Graph(expression, y_label)
    • GraphAll(expression, y_label)
    • Lookup(“table”, “key”)
    • LookupAll(“table”, “key”, “tag=val,tag2=val2”)

简单模板示例:

#模板名称:unknownTemp
template unknownTemp {#模板主题subject = {{.Name}}: {{.Group | len}} unknown alerts #模板内容(与HTML类似)body = `<p>Time: {{.Time}} <p>Name: {{.Name}} <p>Alerts: {{range .Group}}<br>{{.}}{{end}}`
}

预警(alert)

alert部分写预警表达式,触发发送邮件、日志等触发器。
可使用的参数:

  • crit:写临界预警表达式。
  • critNotification:写发生临界预警时,使用的notification。
  • warn:写警告预警表达式(比crit级别低)。
  • warnNotification:写发生警告预警时,使用的notification。
    示例如下:
notification email {#可以添加多个邮件地址,以逗号分隔就好email = email.email1@example.com, email.email2@example.comprint = true
}
alert{……#匹配notificationcritNotification = emailwarnNotification = email
}
  • ignoreUnknown:忽略Unknown预警。
alert{ignoreUnknown = true
}
  • depends:预警依赖的表达式。
  • unknownIsNormal:将unknown转成正常的。
  • runEvery:执行alert频率。
  • template:写模板名称。
  • unjoinedOk:设置后会忽略unjoined表达式错误。
  • unknown
  • log:如果log=true,则形成日志预警。
  • maxLogFrequency:日志预警频率。

预警示例

CPU预警

template cpuTemplate {subject = {{.Last.Status}}: {{.Alert.Name}} on {{.Group.host}}body = `<p>Notes:{{.Alert.Vars.notes }}</p><p>Alert: {{.Alert.Name}} triggered on {{.Group.host}}<hr><p><strong>Computation</strong><table>{{range .Computations}}<tr><td><a href="{{$.Expr .Text}}">{{.Text}}</a></td><td>{{.Value}}</td></tr>{{end}}</table><p><strong>All Hosts CPU Information</strong><p>(Red color means unhealthy,green color means healthy)</p><table>{{range $f := .EvalAll .Alert.Vars.avgcpu}}<tr><td>{{ $f.Group.host}}</td>{{if gt $f.Value 70.0}}<td style="color: red;">{{else}}<td style="color: green;">{{end}}{{ $f.Value | printf "%.0f" }}</td></tr>{{end}}</table><hr>{{ .GraphAll .Alert.Vars.filteResult }}<hr><p><strong>Relevant Tags</strong><table>{{range $k, $v := .Group}}<tr><td>{{$k}}</td><td>:</td><td>{{$v}}</td></tr>{{end}}</table><p>Attention: The time in the graph is <font color="red">UTC</font> time</p><p>The X axis means the time from now to {{.Alert.Vars.queryTime}} ago.</p>`
}
alert cpu.is.too.high {template = cpuTemplate$notes = This alert monitors the percentage of cpu against the cpu limit in haproxy (maxconn) and alerts when we are getting close to that limit and will need to raise that limit. This alert was created due to a socket outage we experienced for that reason$queryTime = 1h$limit = 10$metric = q("sum:rate{counter,,1}:os.cpu{host=regexp(^vs)}", "$queryTime", "")$avgcpu = avg($metric)$orderCPU = limit(sort($avgcpu, "desc"), $limit)$filteResult = filter($metric, $orderCPU)crit = $avgcpu > 80warn = $avgcpu > 70ignoreUnknown = truecritNotification = emailwarnNotification = email
}




磁盘预警

template diskTemplate {subject = {{.Last.Status}}: {{.Alert.Name}} on {{.Group.host}}body = `<p>Notes:{{.Alert.Vars.notes }}</p><p>Alert: {{.Alert.Name}} triggered on {{.Group.host}}<hr><p><strong>Computation</strong><table>{{range .Computations}}<tr><td><a href="{{$.Expr .Text}}">{{.Text}}</a></td><td>{{.Value}}</td></tr>{{end}}</table><p><strong>All Hosts Disk Information</strong><p>(Red color means unhealthy,green color means healthy)</p><table>{{range $f := .EvalAll .Alert.Vars.avgDiskPercent}}<tr><td>{{ $f.Group.host}}</td>{{if lt $f.Value 10.0}}<td style="color: red;">{{else}}<td style="color: green;">{{end}}{{ $f.Value | printf "%.0f" }}</td></tr>{{end}}</table><hr>{{ .GraphAll .Alert.Vars.filteResult }}<hr><p><strong>Relevant Tags</strong><table>{{range $k, $v := .Group}}<tr><td>{{$k}}</td><td>:</td><td>{{$v}}</td></tr>{{end}}</table><p>Attention: The time in the graph is <font color="red">UTC</font> time</p><p>The X axis means the time from now to {{.Alert.Vars.queryTime}} ago.</p>`
}
alert disk.free.space.is.too.small {template = diskTemplate$notes = This alert monitors the percentage of disk free space $queryTime = 1h$limit = 10$diskPercentFree = q("avg:os.disk.fs.percent_free{host=regexp(^vs)}", "$queryTime", "")$avgDiskPercent = avg($diskPercentFree)$orderDisk = limit(sort($avgDiskPercent, "asc"), $limit)$filteResult = filter($diskPercentFree, $orderDisk)ignoreUnknown = truecrit = $avgDiskPercent < 5warn = $avgDiskPercent < 10critNotification = emailwarnNotification = email
}

内存预警

template memroyTemplate {body = `{{if .Alert.Vars.notes}}<p>Notes: {{.Alert.Vars.notes}}{{end}}{{if .Group.host}}{{end}}<hr><p><strong>Alert definition:</strong><table><tr><td>Name:</td><td>{{replace .Alert.Name "." " " -1}}</td></tr><tr><td>Warn:</td><td>{{.Alert.Warn}}</td></tr><tr><td>Crit:</td><td>{{.Alert.Crit}}</td></tr></table><hr><p><strong>All Hosts Memory Information</strong><p>(Red color means unhealthy,green color means healthy)</p><table>{{range $f := .EvalAll .Alert.Vars.avgfree}}<tr><td>{{ $f.Group.host}}</td>{{if lt $f.Value 30.0}}<td style="color: red;">{{else}}<td style="color: green;">{{end}}{{ $f.Value | printf "%.0f" }}</td></tr>{{end}}</table><p><strong>Tags</strong><table>{{range $k, $v := .Group}}{{if eq $k "host"}}<tr><td>{{$k}}</td><td>:</td><td><a href="{{$.HostView $v}}">{{$v}}</a></td></tr>{{else}}<tr><td>{{$k}}</td><td>{{$v}}</td></tr>{{end}}{{end}}</table><p><strong>Computation</strong><table>{{range .Computations}}<tr><td><a href="{{$.Expr .Text}}">{{.Text}}</a></td><td>{{.Value}}</td></tr>{{end}}</table><hr>{{ .GraphAll .Alert.Vars.filteResult }}<hr><p>Attention: The time in the graph is <font color="red">UTC</font> time</p><p>The X axis means the time from now to {{.Alert.Vars.queryTime}} ago.</p>`subject = {{.Last.Status}}: {{replace .Alert.Name "." " " -1}}: {{.Eval .Alert.Vars.avgfree | printf "%.2f"}}{{if .Alert.Vars.unit_string}}{{.Alert.Vars.unit_string}}{{end}} on {{.Group.host}}
}
alert os.low.memory {template = memroyTemplate$notes = In Linux, Buffers and Cache are considered "Free Memory".This alert monitors the percentage of memory free space.$unit_string = % Free Memory$queryTime = 1h$limit = 10$memory = q("avg:os.mem.percent_free{host=regexp(^vs)}", "$queryTime", "")$avgfree = avg($memory)$orderMemory = limit(sort($avgfree, "asc"), $limit) $filteResult = filter($memory, $orderMemory)
ignoreUnknown = truecrit = $avgfree < 20warn = $avgfree < 30critNotification = emailwarnNotification = email
}

忽略Unknown

template unknownTemp {subject = {{.Name}}: {{.Group | len}} unknown alerts body = `<p>Time: {{.Time}} <p>Name: {{.Name}} <p>Alerts: {{range .Group}}<br>{{.}}{{end}}`
}
unknownTemplate = unknownTemp

邮件配置

smtpHost = mail.example.com:25
emailFrom = username@163.com
smtpUsername= username@163.com
smtpPassword= password
notification email {email = example1@example1.com, example2@example2.comprint = true
}

参考文件

  • Bosun表达式
  • Bosun配置文件
  • 预警示例

Bosun 预警配置相关推荐

  1. 详解:CDH预警配置 QQ邮箱 与 企业实操

    CDH预警配置 QQ邮箱 一:在qq邮箱中开启SMTP服务 为什么要用qq邮箱 也可以用公司的,不过就是要下载app占用内存,没有qq邮箱方便,你也可以用手机短信提醒的 qq邮箱 --设置--账户 1 ...

  2. CDH预警配置QQ邮箱

    一. 在QQ邮箱中开启POP   二 .关闭主机的sendmail,开启postfix (本机若没有两个服务,就需要先安装)本地安装sendmail和postfix [root@Slave1 ~] ...

  3. WINDOWS服务器性能监控器的监视以及邮件预警配置

    http://www.zihao123.com/1245.html 导语:Windows性能监视器是Windows自带的性能监视软件,提供用于分析系统性能的实时数据.仅从一个单独的控制台,即可实时监视 ...

  4. WINDOWS性能监控器的监视以及邮件预警配置

    原文:https://www.skyarch.cn/blog/windows/monitor-perfmon-tool/ Windows性能监视器是Windows自带的性能监视软件,提供用于分析系统性 ...

  5. 关于网管软件中的预警功能的发展

        我们知道,根据国际标准化组织的定义,网管软件有五大功能,分别是故障管理,计费管理,配置管理,性能管理和安全管理.当然市场上的产品对这些模块可能是选择性的实现,但是一般来说,故障管理和性能管理是 ...

  6. 如何自动化识别异常数据?达到智能预警?

    今天和大家聊聊常见的场景:异常数据的识别,以及预警相关功能的产品化设计. 01 - 场景概述 我们在做数据分析的时候,有一个重要的环节,就是发现目前运行数据的异常,然后基于异常寻找原因.提出意见和建议 ...

  7. iNeuOS工业互联平台,设备容器(物联网)改版,并且实现设备数据点的实时计算和预警。发布3.2版本

    目       录 1.      概述... 2 2.      平台演示... 2 3.      设备容器新版本介绍... 2 4.      全局数据计算及预警平台... 3 5.      ...

  8. TOP互联网公司都在用,为什么SRE比传统运维更抢手?

    阿里妹导读:双11的完美收官,2684亿的销售奇迹及顺滑极致的客户体验让双11背后的技术再次被推到风头浪尖.而双11技术热点话题,不得不提集团核心系统100%上云这一技术创举. 作为集团上云的底座产品 ...

  9. zabbix邮件内容乱码与邮件内容为附件解决办法

    在zabbix的实际使用过程中,在收到邮件预警的时候,我们会发现邮件内容是乱码的,在手机端收到的是附件,而且附件下载后的文件类型是打不开的.这样我们不知道我们是哪个服务器的哪项服务出了问题,接下来我们 ...

最新文章

  1. 【PCL】的五大依赖库及作用
  2. matlab 报错 javax,[求助]安装报错,求大佬帮忙
  3. dock怎么自定义_如何自定义和调整Mac的Dock
  4. 二叉树遍历(代码,分析,汇编)
  5. bodhi linux 安装 ubuntu软件,Bodhi Linux 5.1.0 发布,基于Ubuntu的轻量级发行版
  6. RTSP播放器开发过程中需要考虑哪些关键因素
  7. dubbo学习之源码创建属于自己的dubbo-demo
  8. shell脚本和linux命令,Linux shell脚本全面学习(一)
  9. mysql查询临时表是否存在_[转]SQL判断临时表是否存在
  10. 小微金融的常规策略架构与流程是什么?
  11. 正则表达式 - 中文、英文姓名匹配
  12. p5.js 入门教程
  13. 4k颜色测试软件,BMPC 4K 使用达芬奇LUT 调色测试
  14. JavaScript判断数组是否包含某元素
  15. iOS从零开始,使用Swift:下一步去哪里
  16. 帝国霸业服务器无限加载,帝国霸业银河生存1.0正式版开局生存流程指南
  17. 如何让技术大佬失去理智
  18. Centos启动默认打开网络
  19. c语言课程设计作业五子棋,c语言课程设计案例-五子棋.ppt
  20. 如何快速开发实用的应用软件?

热门文章

  1. 计算机经验量表,大学生计算机自我效能感量表的开发与应用
  2. mac 卸载 安装mysql_Mac 卸载与安装mysql
  3. PID算法详细解析——基于单片机
  4. 远程桌面管理工具RDO下载地址
  5. ubuntu安装指纹识别驱动
  6. 全息与沙盘的融合,全息沙盘带来全新体验
  7. UML教程1:模型图的构成和功能说明
  8. Typescript从入门到精通(上)
  9. Python网络编程——面向连接(TCP)和无连接(UDP)时间戳网络小程序
  10. python爬虫企业数据_python爬取企业名录并入库