elasticsearch v6.3.0 monitor

0. Overview
1. 監(jiān)控
   - 自定義監(jiān)控
   - x-pack監(jiān)控
   - 瞬時(shí)狀態(tài)監(jiān)控
2. x-pack monitor
   - 監(jiān)控組織圖
   - 安裝
   - 啟動(dòng)
   - 配置
   - CMD
3. Others
4. 自定義監(jiān)控grafana實(shí)例
5. Reference

Overview

上周四(0614)es推出了v6.3.0,期待已久的SQL和Rollups已經(jīng)可以被使用,x-pack功能更加完善。想在此基礎(chǔ)上,看看630的監(jiān)控是怎么樣。


監(jiān)控

es最重要的目標(biāo)是線上的穩(wěn)定高性能,而穩(wěn)定的定義就離不開監(jiān)控。監(jiān)控方式有多種,

  • 通過curl命令定時(shí)抽取es的各項(xiàng)重點(diǎn)stats,然后輸出到grafana


    es_curl-InfluxDB-Grafana
  • 結(jié)合kibana,通過es官方提供的x-pack monitor/Marvel


    x-pack monitor
  • 瞬時(shí)狀態(tài)監(jiān)控Cerebro

    cerebor

x-pack monitor

監(jiān)控組織圖

x-pack monitor arch.
x-pack collectors

流程大概是:

  1. 安裝帶x-pack plugin的es和kibana
  2. 配置product-es-cluster的x-pack data collector(采集哪些指標(biāo)),exporter(將采集指標(biāo)寫到哪里),duration(默認(rèn)7d),采集頻率xpack.monitoring.collection.interval(也可以在kibana設(shè)置,默認(rèn)10s,越頻繁,monitoring index越大)
  3. product-es-cluster每隔interval將collector數(shù)據(jù)寫入到exporter(即monitoring-es-cluster
  4. kibana每隔interval(這個(gè)interval與exporter的interval無關(guān))從monitoring-es-cluster讀取collector數(shù)據(jù),然后展示在UI上
  5. kibana會(huì)返回一條確認(rèn)信息到collector(當(dāng)連上master的時(shí)候)

安裝

在6.3之前,es和kibana都需要額外安裝x-pack plugin;而6.3已經(jīng)集成了x-pack,直接配置一下即可使用。

安裝es v630

elasticsearch.yml

安裝kibana vv630

kibana.yml

啟動(dòng)

起來之后,看看2個(gè)node時(shí)候連上,再看看kibana是否連上。


es master log
kibana log

配置

直接使用x-pack提供的monitor,在kibana上查看監(jiān)控?cái)?shù)據(jù)的趨勢?;蛘呤褂脛?dòng)態(tài)setting來更新配置。

CMD

HOST=127.0.0.1:9200

curl -s -X GET "$HOST/_cluster/health?pretty"
curl -s -XGET "$HOST/_cat/indices?v"
curl -s -XGET "$HOST/_cat/nodes?v"

# setting check
curl -s -X GET "$HOST/_cluster/settings?pretty"

# dynamic setting
curl -s -X PUT "$HOST/_cluster/settings" -H 'Content-Type: application/json' -d'
{
  "persistent" : {
    "xpack.monitoring.collection.enabled" : "true",
    "xpack.monitoring.collection.interval" : "30s"
  }
}'

curl -s -X PUT "$HOST/_cluster/settings" -H 'Content-Type: application/json' -d'
{
  "transient" : {
    "xpack.monitoring.collection.interval" : null
  }
}'

# create mapping
curl -s -X PUT "$HOST/person" -H 'Content-Type: application/json' -d'
{
    "settings" : {
        "number_of_shards" : 2,
        "number_of_replicas" : 0,
        "refresh_interval": "10s",

        "translog": {
            "flush_threshold_size": "10mb",
            "sync_interval": "10s",
            "durability": "async"
        },

        "merge": {
            "policy": {
                "segments_per_tier": "25",
                "floor_segment": "100mb"
            }
        }
    },
    "mappings" : {
        "_doc" : {
            "properties" : {
                "id" : { "type" : "integer" },
                "name" : { "type" : "text" },
                "address" : { "type" : "text" }
            }
        }
    }
}
'

# generate docs
for i in {1..500000}
do
    curl -s -X POST "$HOST/person/_doc?pretty" -H 'Content-Type: application/json' -d'{  "id": "4", "name": "chenfh5", "address": "Beijing Chaoyang"}' > /dev/null
done

# check docs
curl -s -X GET "$HOST/.monitoring-es-6-2018.06.19/_search?pretty&size=1000" -H 'Content-Type: application/json' -d'
{
    "sort" : [
        { "timestamp" : {"order" : "desc"}}
    ]
}' | grep 'timestamp' | head -n 100

Others

Cerebro現(xiàn)在也從以前的kopf plugin形式脫離出來,做成直接通過http的形式來crul es stat以便渲染UI。所以直接配置es master的http端口,即可使用Cerebro來展示es集群的瞬時(shí)狀態(tài)。

自定義監(jiān)控grafana實(shí)例

  1. 安裝grafana
grafana version
  1. 為grafana添加(時(shí)序)數(shù)據(jù)庫,用以保存歷史數(shù)據(jù)作對比
添加data source
  1. 編寫定時(shí)腳本收集相關(guān)監(jiān)控指標(biāo)數(shù)據(jù),并上報(bào)到grafana在步驟2所添加的db里
    elasticsearch2elastic這個(gè)腳本,里面的,
# 希望監(jiān)控的es集群
# ElasticSearch Cluster to Monitor
elasticServer = os.environ.get('ES_METRICS_CLUSTER_URL', 'http://srcServer:9200')

# 上報(bào)監(jiān)控?cái)?shù)據(jù)的目的地,即grafana的data source
# ElasticSearch Cluster to Send Metrics
elasticMonitoringCluster = os.environ.get('ES_METRICS_MONITORING_CLUSTER_URL', 'http://destServer:9200')
  1. 查看grafana的data source是否有上報(bào)數(shù)據(jù)
check if the monitor data have been uoloaded?
  1. 配置dashboard
    根據(jù)上報(bào)的數(shù)據(jù),配置自己喜歡的監(jiān)控儀表盤(New dashboard)。也可以使用社區(qū)已經(jīng)建好的dashboard。
    這里采用了在社區(qū)版基礎(chǔ)上修改為自己喜歡的。
    先import社區(qū)版的到grafana里。Home -> Import dashboard

    因?yàn)榫W(wǎng)絡(luò)問題,沒有采用id/url的方式,而采用了離線json安裝方式,具體采用了哪些指標(biāo),指標(biāo)應(yīng)用了哪些函數(shù),都可以在json文件上看到,當(dāng)然也可以在導(dǎo)入之后直接在grafana里面修改

  2. 展示

snapshot
  1. 自定義
    通過定時(shí)腳本上傳自定義數(shù)據(jù),然后在metric里面應(yīng)用各類函數(shù)得到最后想要的監(jiān)控指標(biāo),然后選擇合適圖表來展示。如,每個(gè)RT的總數(shù)據(jù)量,每個(gè)RT的每日數(shù)據(jù)量。
  1. 告警
    利用grafana的alert功能

  1. grafana設(shè)置多集群


    在setting里面設(shè)置分集群
具體在tab里面引用重命名

另外,由于cluster_name這個(gè)在默認(rèn)寫的時(shí)候是text,導(dǎo)致了使用query_string查的時(shí)候這個(gè)cluster_name形同虛設(shè),那么就會(huì)導(dǎo)致每個(gè)集群查到的數(shù)據(jù)都是一樣的,取max之后也就都一樣了。

540
630
cluster_name的mapping

正確的打開方式,根據(jù)grafana的查詢語句,來改造自己的mapping,即把cluster_name改為keyword。

540_correct
630_correct
cluster_name的mapping_correct
  1. grafana es template variables
    今天再來說說上面遇到的variable配置了query之后沒有結(jié)果的問題。

先說結(jié)果,

# not work
{"find": "terms", "fields": "cluster_name"}

# work
{"find": "terms", "field": "cluster_name", "query": ""}
error {"type":"illegal_state_exception","reason":"value source config is invalid; must have either a field context or a script or marked as unwrapped"}
have resp

從上面可以看到如果只使用field,而沒有query的話,grafana翻譯出來的esDsl是錯(cuò)誤的,即不帶cluster_name這個(gè)field。而如果帶上query就會(huì)有,而在帶上query之后,再回退到不帶query的方式,有時(shí)候可以,有時(shí)候不可以。而根據(jù)grafana提供的文檔,如果對field沒有特殊query需求,是可以不帶query的。

grafana doc
  1. es date type


    UTC vs local time zone

snapshot

整體一覽所有集群


grafana custom es each cluster monitor checklist for each cluster



細(xì)看某個(gè)集群的具體信息

grafana custom es each cluster monitor whole snapshot


Reference

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容