cassandra服務監控指令碼
阿新 • • 發佈:2018-12-09
1. 指令碼如下:
#!/bin/bash #/home/zx_wuzhan/monitor/tmp #獲取Cassandra叢集全部資訊 /usr/bin/ssh [email protected] "/home/im/apps/opt/cassandra/bin/nodetool status" > /home/zx_wuzhan/monitor/tmp/cassandra_cluster_state.txt #抽取Cassandra叢集資訊中成員及狀態資訊 /usr/bin/grep -w "[\{1,3\}[:digit:]].[\{1,3\}[:digit:]].[\{1,3\}[:digit:]].[\{1,3\}[:digit:]]" /home/zx_wuzhan/monitor/tmp/cassandra_cluster_state.txt | awk '{print $1" "$2}' > /home/zx_wuzhan/monitor/tmp/cassandra_state_list.txt #判斷每個成員的狀態,狀態正常用0表示,異常用1表示 for ip in `awk '{print $2}' /home/zx_wuzhan/monitor/tmp/cassandra_state_list.txt` do state=`grep $ip /home/zx_wuzhan/monitor/tmp/cassandra_state_list.txt | awk '{print $1}'` if [ $state == "UN" ] then echo cassandra_state,host_ip=$ip request=0 > /home/zx_wuzhan/monitor/tmp/cassandra_state.txt curl -i -XPOST 'http://192.168.188.54:28086/write?db=grafana' --data-binary @/home/zx_wuzhan/monitor/tmp/cassandra_state.txt else echo cassandra_state,host_ip=$ip request=1 > /home/zx_wuzhan/monitor/tmp/cassandra_state.txt curl -i -XPOST 'http://192.168.188.54:28086/write?db=grafana' --data-binary @/home/zx_wuzhan/monitor/tmp/cassandra_state.txt fi done