2017-05-17 74 views
0

我想設置觀察器發送郵件,如果CPU在最近X分鐘內的使用率超過N%。elasticsearch中的觀察器對於高CPU使用率

第一次elasticsearch在每分鐘通過metricbeat從遠程服務器獲取數據。然後我想通過使用該數據通知管理員遠程服務器的高CPU使用率。

我設置郵件,我完成部分如果內存使用率高,但問題與CPU使用率,是4核處理器。我不寫aggs的功能和條件。我嘗試使用代碼github,但我無法更改功能以使用metricbeat。

回答

0

這爲我工作。每當主機通知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 
    } 
}