9.ElasticSearch预警服务-Watcher详解-监控时间线数据
编程技术  /  houtizong 发布于 3年前   100
来看个小例子:固定周期采集数据,并设置数据预警机制
采集数据配置,拉取RSS数据并存储到ElasticSearch中.
1.下载并安装最新的logstash1.5版本
地址:https://www.elastic.co/products/logstash
2.安装rss插件
cd logstash-1.5.0bin/plugin install logstash-input-rss
3.配置数据采集脚本
input { rss { url => "http://stackoverflow.com/feeds/tag/elasticsearch+or+logstash+or+kibana" interval => 3600 }}output { elasticsearch { protocol => "http" host => "localhost" } stdout { }}
4.启动logstash
nohup bin/logstash -f rss.conf > logs/rss.log&
5.验证ElasticSearch数据流是否正常
可以通过API,或者Kopf,Head等插件进行验证。
Watcher预警配置
1.首先定义Script文件,采用Groovy语法,将文件放置到$ES_HOME/config/Scripts目录下。
$ES_HOME/config/scripts/threshold_hits.groovy编辑内容为:return ctx.payload.hits.total > threshold
2.设置Watcher:
PUT _watcher/watch/rss_watch{ "trigger" : { "schedule" : { "daily" : { "at" : "12:00" } #每天12点执行 } }, "input" : { "search" : { "request" : { "indices" : [ "logstash*" ],#指定查询索引 "body" : { "query" : { "filtered" : { "query" : {"match" : {"message": "error problem"}}, #查询条件 "filter" : {"range" : {"@timestamp" : {"gte" : "now-1d"}}} } } } } } }, "condition" : { "script" : { "file" : "threshold_hits",#脚本文件名称 "params" : { "threshold" : 0 #参数 } } }, "actions" : { "send_email" : { #请注意ElasticSearch.yml中的邮件服务器配置信息,可参考之前的文章介绍 "email" : { "to" : "[email protected]", "subject" : "Somebody needs help with ELK", "body" : "The attached Stack Overflow posts were tagged with Elasticsearch, Logstash, or Kibana and mentioned an error or problem.", "attach_data" : true } } }}
3.调试Watcher配,通过以下API可以,立刻执行配置的Watcher
POST _watcher/watch/rss_watch/_execute{ "trigger_event" : { "schedule" : { "triggered_time": "now", "scheduled_time": "now" } }, "ignore_throttle" : true, "simulated_actions" : "_all", "record_execution" : true}
4.验证是否可以收到预警邮件。
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接