zoukankan      html  css  js  c++  java
  • 查询elasticsearch索引日志条数

    只是用来记录一些简单的报警脚本

    看看就行

    ]# cat es_index_count.sh 
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    #dhger的2台服务器
    for i in {2008,2008-2};
    do
    curl -u elastic:elk_123 -X GET http://127.0.0.1:9200/dhger-*/_count -H 'Content-Type: application/json' -d '
    {
      "query": {
        "bool": {
          "must": [],
          "filter": [
            { "match_phrase": 
            {"agent.hostname.keyword": {"query": "'$i'" }
            }
            },
            {"range": {
                "@timestamp": {"from": "now-15m"}
            }
            }
          ]
        }
      }
    }' > /soft/ecc-${i}.txt
    y=`awk -F '[:,]' '{print $2}' /soft/ecc-${i}.txt`
    if [ $y -eq 0 ];then
    #/bin/bash /soft/alert.sh "dhgner-$i" "$y"
    /usr/bin/python /soft/python3 "`date +%H:%M` dhger服务 $i" "$y"
    sleep 10
    echo $y
    fi
    done
    #dher的2台服务器
    for i in {dh-2008,ct-2008-2};
    do
    curl -u elastic:elk_123 -X GET http://127.0.0.1:9200/dher-*/_count -H 'Content-Type: application/json' -d '
    {
      "query": {
        "bool": {
          "must": [],
          "filter": [
            { "match_phrase": 
            {"agent.hostname.keyword": {"query": "'$i'" }
            }
            },
            {"range": {
                "@timestamp": {"from": "now-15m"}
            }
            }
          ]
        }
      }
    }' > /soft/signer-${i}.txt
    y=`awk -F '[:,]' '{print $2}' /soft/dher-${i}.txt`
    if [ $y -eq 0 ];then
    #/bin/bash /soft/alert.sh "dher-$i" "$y"
    /usr/bin/python /soft/python3 "`date +%H:%M` siger服务 $i" "$y"
    sleep 10
    echo $y
    fi
    done
    You have mail in /var/spool/mail/root
    

    配置定时任务

    */5 8-19 * * * /bin/bash  /soft/es_index_count.sh &>/var/es_count.log
    
  • 相关阅读:
    YbtOJ20030 连珠风暴
    YbtOJ20029 最大权值
    P6859 蝴蝶与花
    P4115 Qtree4
    P2486 [SDOI2011]染色
    P2487 [SDOI2011]拦截导弹
    P5163 WD与地图
    P3733 [HAOI2017]八纵八横
    CF1100F Ivan and Burgers
    P1712 [NOI2016]区间
  • 原文地址:https://www.cnblogs.com/dinghc/p/13176749.html
Copyright © 2011-2022 走看看