低記憶體警報和模板
可以使用 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
}
在規則編輯器頁面上測試警報後,可以使用“ 結果” 選項卡檢視計算,使用模板檢視呈現的警報通知,使用時間線檢視所有警報事件(僅在指定“ 從” 和“ 到” 日期時)。