示例警报

Bosun 警报使用自定义 DSL 在配置文件中定义 。它们使用函数来评估时间序列数据,并在 warn 或 crit 表达式非零时生成警报。警报使用模板在通知中包含其他信息,通常是电子邮件和/或 HTTP POST 请求。

template sample.alert {
    body = `<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>
    <hr>
    {{ .Graph .Alert.Vars.metric }}`

    subject = {{.Last.Status}}: {{.Alert.Name}} cpu idle at {{.Alert.Vars.q | .E}}% on {{.Group.host}}
}

notification sample.notification {
    email = alerts@example.com
}

alert sample.alert {
    template = sample.template
    $q = avg(q("sum:rate:linux.cpu{host=*,type=idle}", "1m"))
    crit = $q < 40
    notification = sample.notification
}

对于任何闲置 CPU 使用率在过去 1 分钟内平均低于 40%的主机,警报将发送一封主题为 Critical: sample.alert cpu idle at 25% on hostname 的电子邮件。此示例是主机范围警报,但 Bosun 还支持群集,数据中心或全局范围警报( 有关详细信息,请参阅基础视频系列 )。