低内存警报和模板

可以使用 Bosun 中的规则编辑器选项卡预览和编辑模板。使用“ 跳转到” 链接选择要编辑的警报,然后可以使用旁边的模板按钮在警报和配置的模板部分之间切换。如果警报具有多个实例,则可以使用“ 模板组” 部分中的 host=xxx,name=xxx 指定要查看所呈现模板的标记集。 ** **

template os.low.memory {
    subject = {{.Last.Status}}: Low Memory: {{.Eval .Alert.Vars.q | printf "%.0f"}}% Free Memory on {{.Group.host}} ({{.Eval .Alert.Vars.free | bytes }} Free of {{.Eval .Alert.Vars.total | bytes }} Total)

    body = `
    <p><a href="{{.Ack}}">Acknowledge</a> | <a href="{{.Rule}}">View Alert in Bosun's Rule Editor</a></p>
    <p><strong>Alert Key: </strong>{{printf "%s%s" .Alert.Name  .Group }}</p>
    <p><strong>Incident: </strong><a href="{{.Incident}}">#{{.Last.IncidentId}}</a></p>
    <p><strong>Notes: </strong>{{html .Alert.Vars.notes}}</p>

    <strong>Graph</strong>
    <div>{{.Graph .Alert.Vars.graph .Alert.Vars.graph_unit}}</div>
    `
}

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

alert os.low.memory {
    template = os.low.memory
    $notes = Alerts when less than 5% free, or less than 500MB (when total > 2GB). In Linux, Buffers and Cache are considered "Free Memory".

    $default_time = "2m"
    $host = wildcard(*)
    $graph = q("avg:300s-avg:os.mem.percent_free{host=$host}", "1d", "")
    $graph_unit = Percent Free Memory (Including Buffers and Cache)
    $q = avg(q("avg:os.mem.percent_free{host=$host}", $default_time, ""))
    $total = last(q("sum:os.mem.total{host=$host}", $default_time, ""))
    $free = last(q("sum:os.mem.free{host=$host}", $default_time, ""))

    #Warn when less than 5% free or total > 2GB and free < 500MB
    warn = $q < 5 || ($total > 2147483648 && $free < 524288000)
    #Crit when less than 0.5% free
    crit = $q <= .5
    critNotification = sample.notification
}

规则编辑器页面上测试警报后,可以使用“ 结果” 选项卡查看计算,使用模板查看呈现的警报通知,使用时间线查看所有警报事件(仅在指定“ 从” 和“ 到” 日期时)。

StackOverflow 文档