這爲我工作。每當主機通知5分鐘(> 95%CPU)時,它會發送郵件:
{
"trigger": {
"schedule": {
"interval": "1m"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"metricbeat-*"
],
"types": [],
"body": {
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-{{ctx.metadata.window_period}}"
}
}
},
{
"range": {
"system.process.cpu.total.pct": {
"gte": "{{ctx.metadata.threshold}}"
}
}
}
]
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gte": 5
}
}
},
"actions": {
"email_me": {
"throttle_period_in_millis": 300000,
"email": {
"profile": "standard",
"attachments": {
"datalles.json": {
"data": {
"format": "json"
}
}
},
"from": "[email protected]",
"to": [
"[email protected]"
],
"subject": " CPU overhead",
"body": {
"html": "The following hosts are running over {{ctx.metadata.threshold}}% CPU: <br><br>{{#ctx.payload.hits.hits}} <b>{{_source.beat.hostname}}</b> ({{_source.system.process.cpu.total.pct}}%) <br> {{/ctx.payload.hits.hits}}"
}
}
}
},
"metadata": {
"window_period": "1m",
"threshold": 0.95
}
}