8.ElasticSearch预警服务-Watcher详解-监控Marvel数据
如果ElasticSearch集群部署了Marvel相关的服务,那么就可以安装Watcher来监控异常情况的产生并发送预警。
例如可以在以下情况下配置Watch Action动作.
1.集群监控状态监控
2.高内存使用率
3.高CPU使用率
4.高文件目录空间
5.高FieldData 缓存使用
6.节点加入或者脱离集群
使用Watcher查询Marvel存储的集群信息数据,请注意Marvel数据是否存储正常。
1.监控集群状态配置:
每分钟检测一次,如果集群状态持续Red状态60秒,则触发预警动作。
PUT _watcher/watch/cluster_red_alert { "trigger": { "schedule": { "interval": "1m" } }, "input": { "search": { "request": { "indices": ".marvel-*", "types": "cluster_stats", "body": { "query": { "filtered": { "filter": { "bool": { "must": [ { "range": { "@timestamp": { "gte": "now-2m", "lte": "now" } } } ], "should": [ { "term": { "status.raw": "red" } }, { "term": { "status.raw": "green" } }, { "term": { "status.raw": "yellow" } } ] } } } }, "fields": ["@timestamp","status"], "sort": [ { "@timestamp": { "order": "desc" } } ], "size": 1, "aggs": { "minutes": { "date_histogram": { "field": "@timestamp", "interval": "5s" }, "aggs": { "status": { "terms": { "field": "status.raw", "size": 3 } } } } } } } } }, "throttle_period": "30m", "condition": { "script": { "inline": "if (ctx.payload.hits.total < 1) return false; def rows = ctx.payload.hits.hits; if (rows[0].fields.status[0] != 'red') return false; if (ctx.payload.aggregations.minutes.buckets.size() < 12) return false; def last60Seconds = ctx.payload.aggregations.minutes.buckets[-12..-1]; return last60Seconds.every { it.status.buckets.every { s -> s.key == 'red' } }" } }, "actions": { "send_email": { "email": { "to": "<username>@<domainname>", "subject": "Watcher Notification - Cluster has been RED for the last 60 seconds", "body": "Your cluster has been red for the last 60 seconds." } } } }
2.监控内存使用
每分钟检测一次,如果60秒内集群内存使用大于75%,则发送预警邮件
PUT _watcher/watch/mem_watch { "trigger": { "schedule": { "interval": "1m" } }, "input": { "search": { "request": { "indices": [ ".marvel-*" ], "search_type": "count", "body": { "query": { "filtered": { "filter": { "range": { "@timestamp": { "gte": "now-2m", "lte": "now" } } } } }, "aggs": { "minutes": { "date_histogram": { "field": "@timestamp", "interval": "minute" }, "aggs": { "nodes": { "terms": { "field": "node.name.raw", "size": 10, "order": { "memory": "desc" } }, "aggs": { "memory": { "avg": { "field": "jvm.mem.heap_used_percent" } } } } } } } } } } }, "throttle_period": "30m", "condition": { "script": "if (ctx.payload.aggregations.minutes.buckets.size() == 0) return false; def latest = ctx.payload.aggregations.minutes.buckets[-1]; def node = latest.nodes.buckets[0]; return node && node.memory && node.memory.value >= 75;" }, "actions": { "send_email": { "transform": { "script": "def latest = ctx.payload.aggregations.minutes.buckets[-1]; return latest.nodes.buckets.findAll { return it.memory && it.memory.value >= 75 };" }, "email": { "to": "<username>@<domainname>", "subject": "Watcher Notification - HIGH MEMORY USAGE", "body": "Nodes with HIGH MEMORY Usage (above 75%):\n\n{{#ctx.payload._value}}\"{{key}}\" - Memory Usage is at {{memory.value}}%\n{{/ctx.payload._value}}" } } } }
3.CPU使用率监控
每分钟执行一次,如果60秒CPU使用率大于75%,则发送预警邮件。
PUT _watcher/watch/cpu_usage { "trigger": { "schedule": { "interval": "1m" } }, "input": { "search": { "request": { "indices": [ ".marvel-*" ], "search_type": "count", "body": { "query": { "filtered": { "filter": { "range": { "@timestamp": { "gte": "now-2m", "lte": "now" } } } } }, "aggs": { "minutes": { "date_histogram": { "field": "@timestamp", "interval": "minute" }, "aggs": { "nodes": { "terms": { "field": "node.name.raw", "size": 10, "order": { "cpu": "desc" } }, "aggs": { "cpu": { "avg": { "field": "os.cpu.user" } } } } } } } } } } }, "throttle_period": "30m", "condition": { "script": "if (ctx.payload.aggregations.minutes.buckets.size() == 0) return false; def latest = ctx.payload.aggregations.minutes.buckets[-1]; def node = latest.nodes.buckets[0]; return node && node.cpu && node.cpu.value >= 75;" }, "actions": { "send_email": { "transform": { "script": "def latest = ctx.payload.aggregations.minutes.buckets[-1]; return latest.nodes.buckets.findAll { return it.cpu && it.cpu.value >= 75 };" }, "email": { "to": "user@example.com", "subject": "Watcher Notification - HIGH CPU USAGE", "body": "Nodes with HIGH CPU Usage (above 75%):\n\n{{#ctx.payload._value}}\"{{key}}\" - CPU Usage is at {{cpu.value}}%\n{{/ctx.payload._value}}" } } } }
4.监控文件目录
每分钟检测一次,如果节点目录使用率大于80%,则发送预警邮件
PUT _watcher/watch/open_file_descriptors { "metadata": { "system_fd": 65535, "threshold": 0.8 }, "trigger": { "schedule": { "interval": "1m" } }, "input": { "search": { "request": { "indices": [ ".marvel-*" ], "types": "node_stats", "search_type": "count", "body": { "query": { "filtered": { "filter": { "range": { "@timestamp": { "gte": "now-1m", "lte": "now" } } } } }, "aggs": { "minutes": { "date_histogram": { "field": "@timestamp", "interval": "5s" }, "aggs": { "nodes": { "terms": { "field": "node.name.raw", "size": 10, "order": { "fd": "desc" } }, "aggs": { "fd": { "avg": { "field": "process.open_file_descriptors" } } } } } } } } } } }, "throttle_period": "30m", "condition": { "script": "if (ctx.payload.aggregations.minutes.buckets.size() == 0) return false; def latest = ctx.payload.aggregations.minutes.buckets[-1]; def node = latest.nodes.buckets[0]; return node && node.fd && node.fd.value >= (ctx.metadata.system_fd * ctx.metadata.threshold);" }, "actions": { "send_email": { "transform": { "script": "def latest = ctx.payload.aggregations.minutes.buckets[-1]; return latest.nodes.buckets.findAll({ return it.fd && it.fd.value >= (ctx.metadata.system_fd * ctx.metadata.threshold) }).collect({ it.fd.percent = Math.round((it.fd.value/ctx.metadata.system_fd)*100); it });" }, "email": { "to": "<username>@<domainname>", "subject": "Watcher Notification - NODES WITH 80% FILE DESCRIPTORS USED", "body": "Nodes with 80% FILE DESCRIPTORS USED (above 80%):\n\n{{#ctx.payload._value}}\"{{key}}\" - File Descriptors is at {{fd.value}} ({{fd.percent}}%)\n{{/ctx.payload._value}}" } } } }
5.监控Field 缓存相关
每分钟执行一次,如果使用率大于80%,则发送预警邮件。
PUT _watcher/watch/fielddata_utilization { "metadata": { "fielddata_cache_size": 100000, "threshold": 0.8 }, "trigger": { "schedule": { "interval": "1m" } }, "input": { "search": { "request": { "indices": [ ".marvel-*" ], "types": "node_stats", "search_type": "count", "body": { "query": { "filtered": { "filter": { "range": { "@timestamp": { "gte": "now-1m", "lte": "now" } } } } }, "aggs": { "minutes": { "date_histogram": { "field": "@timestamp", "interval": "5s" }, "aggs": { "nodes": { "terms": { "field": "node.name.raw", "size": 10, "order": { "fielddata": "desc" } }, "aggs": { "fielddata": { "avg": { "field": "indices.fielddata.memory_size_in_bytes" } } } } } } } } } } }, "throttle_period": "30m", "condition": { "script": "if (ctx.payload.aggregations.minutes.buckets.size() == 0) return false; def latest = ctx.payload.aggregations.minutes.buckets[-1]; def node = latest.nodes.buckets[0]; return node && node.fielddata && node.fielddata.value >= (ctx.metadata.fielddata_cache_size * ctx.metadata.threshold);" }, "actions": { "send_email": { "transform": { "script": "def latest = ctx.payload.aggregations.minutes.buckets[-1]; return latest.nodes.buckets.findAll({ return it.fielddata && it.fielddata.value >= (ctx.metadata.fielddata_cache_size * ctx.metadata.threshold) }).collect({ it.fielddata.percent = Math.round((it.fielddata.value/ctx.metadata.fielddata_cache_size)*100); it });" }, "email": { "to": "<username>@<domainname>", "subject": "Watcher Notification - NODES WITH 80% FIELDDATA UTILIZATION", "body": "Nodes with 80% FIELDDATA UTILIZATION (above 80%):\n\n{{#ctx.payload._value}}\"{{key}}\" - Fielddata utilization is at {{fielddata.value}} bytes ({{fielddata.percent}}%)\n{{/ctx.payload._value}}" } } } }
6.监控集群节点
每分钟执行一次,如果有Node加入或者离开集群,则发送预警邮件。
PUT _watcher/watch/node_event { "trigger": { "schedule": { "interval": "60s" } }, "input": { "search": { "request": { "indices": [ ".marvel-*" ], "search_type": "query_then_fetch", "body": { "query": { "filtered": { "query": { "bool": { "should": [ { "match": { "event": "node_left" } }, { "match": { "event": "node_joined" } } ] } }, "filter": { "range": { "@timestamp": { "from": "{{ctx.trigger.scheduled_time}}||-60s", "to": "{{ctx.trigger.triggered_time}}" } } } } }, "fields": [ "event", "message", "cluster_name" ], "sort": [ { "@timestamp": { "order": "desc" } } ] } } } }, "throttle_period": "60s", "condition": { "script": { "inline": "ctx.payload.hits.size() > 0 " } }, "actions": { "send_email": { "email": { "to": "<username>@<domainname>", "subject": "{{ctx.payload.hits.hits.0.fields.event}} the cluster", "body": "{{ctx.payload.hits.hits.0.fields.message}} the cluster {{ctx.payload.hits.hits.0.fields.cluster_name}} " } } } }
相关推荐
用于elasticsearch7.17.3这个版本的ik中文分词器,考虑到官网有时网络不稳定下载不下来,这里特意上传,方便大家使用; 目录结构如下: config -- 文件夹 plugin-security.policy plugin-descriptor.properties ...
《Elasticsearch全文检索插件IK分析器7.17.0详解》 Elasticsearch是一种流行的开源全文搜索引擎,广泛应用于大数据和big data环境中的数据检索与分析。它以其高效、灵活和可扩展性赢得了业界的青睐。在Elastic...
《Elasticsearch分词器:elasticsearch-analysis-ik-7.16.2深度解析》 在信息爆炸的时代,搜索引擎的效能成为了数据检索的关键。Elasticsearch作为一款强大的开源搜索引擎,其灵活性和可扩展性备受青睐。而在中文...
Elasticsearch-Head插件通常用Node.js开发,利用其非阻塞I/O模型和事件驱动特性,可以高效地处理来自Elasticsearch集群的数据流。开发者可以使用Node.js来编写插件的服务器端逻辑,并与Elasticsearch进行通信。 ...
《Elasticsearch Analysis IK插件7.9.3详解》 Elasticsearch作为一个强大的全文搜索引擎,其灵活性和可扩展性深受开发者喜爱。然而,对于中文处理,Elasticsearch原生支持并不理想,这时就需要借助于插件来实现,...
Elasticsearch是一个开源的全文搜索引擎,它基于Lucene构建,被广泛用于数据分析和日志管理。在Linux平台上,Elasticsearch提供了高度可扩展性和实时性能。版本7.13.4是Elasticsearch的一个更新版本,它包含了各种...
Elasticsearch、Kibana和Logstash是 Elastic Stack(前称为 ELK Stack)的重要组成部分,这是一个流行的开源数据处理和分析工具链。这三个组件在大数据、日志管理和实时分析领域广泛应用。 1. **Elasticsearch**:...
《Elasticsearch中文分词器IK插件详解》 Elasticsearch(ES)作为一个强大的全文搜索引擎,其在处理中文文档时,对中文分词的准确性和效率有着至关重要的作用。"elasticsearch-analysis-ik"是ES中最受欢迎的中文...
《Elasticsearch Analysis IK插件详解与7.17.6版本特性》 Elasticsearch是一种流行的开源全文搜索引擎,以其高效、灵活和可扩展性深受开发者喜爱。在处理中文分词方面,Elasticsearch-analysis-ik插件是不可或缺的...
在现代大数据分析和搜索引擎领域,Elasticsearch(ES)因其高效、灵活的全文检索能力而备受青睐。然而,对于中文这样的多字节语言,如何准确地进行分词是关键。这时,我们就需要引入专门的中文分词器。本文将详细...
这个插件的主要目的是优化中文文本的检索效率和精度,通过提供高效的分词算法来提升 Elasticsearch 在处理中文数据时的性能。 在 Elasticsearch 中,分词是全文搜索的关键步骤,它将文本分解成可索引和查询的词汇...
Elasticsearch是一个开源的全文搜索引擎,它以其高效、可扩展和实时的数据检索能力而闻名。在Windows平台上,Elasticsearch的安装和配置过程与在其他操作系统上略有不同。本篇将详细阐述关于"最新版windows elastic...
Elasticsearch(elasticsearch-7.17.0-linux-aarch64.tar.gz适用于Linux x86_64 Arm芯片)是一个高度可扩展的开源全文本搜索和分析引擎。它使您可以快速,近乎实时地存储,搜索和分析大量数据。它通常用作支持具有...
《Elasticsearch IK 分析器插件7.12.0版详解》 Elasticsearch是一种流行的开源全文搜索引擎,以其强大的搜索能力和灵活的数据处理能力深受开发者喜爱。在处理中文文本时,选择合适的分析器至关重要,而`elastic...
Elasticsearch(elasticsearch-7.17.0-linux-x86_64.tar.gz适用于Linux x86_64 )是一个高度可扩展的开源全文本搜索和分析引擎。它使您可以快速,近乎实时地存储,搜索和分析大量数据。它通常用作支持具有复杂搜索...
解压完成后,进入解压后的目录,启动Elasticsearch服务,通常执行`bin/elasticsearch`脚本即可。 **配置** Elasticsearch的配置文件位于`config/elasticsearch.yml`。你可以根据需求调整设置,比如更改默认端口、...
Elasticsearch是一个强大的开源搜索引擎,基于Java开发,其核心功能是全文检索,但同时也提供了数据分析、实时聚合以及数据存储的能力。这个"elasticsearch-7.17.7-windows-x86-64.zip"文件是Elasticsearch的7.17.7...
"elasticsearch-analysis-ik"是针对Elasticsearch的一个中文分词插件,它的主要功能是提供高效、精准的中文分词能力,使得Elasticsearch能够更好地理解和处理中文文本数据。 在Elasticsearch 7.10.0版本中,...
elasticsearch-7.17.4-x86_64.rpm文件 elasticsearch-7.17.4-x86_64.rpm文件 elasticsearch-7.17.4-x86_64.rpm文件 elasticsearch-7.17.4-x86_64.rpm文件 elasticsearch-7.17.4-x86_64.rpm文件 elasticsearch-7.17.4...
此外,Elasticsearch还广泛应用于监控、安全分析、物联网(IoT)数据处理等领域。 总的来说,"windows elasticsearch-7.15.2-windows-x86_64.zip"是一个强大的搜索引擎平台,适用于Windows环境。通过理解和掌握...