cassandra.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #!/bin/bash
  2. scripts_dir=/etc/zabbix/scripts/cassandra
  3. cassandra_script=$scripts_dir/cassandra.pl
  4. cassandra_nodes_script=$scripts_dir/check_cassandra_nodes.pl
  5. cassandra_tpstats_script=$scripts_dir/check_cassandra_tpstats.pl
  6. usage() {
  7. echo "Usage:"
  8. echo "${0##*/} --round"
  9. echo "${0##*/} --status_main"
  10. echo "${0##*/} --status_main_text"
  11. echo "${0##*/} --status_heap_mem"
  12. echo "${0##*/} --info_id"
  13. echo "${0##*/} --info_gossip"
  14. echo "${0##*/} --info_thrift"
  15. echo "${0##*/} --info_exceptions"
  16. echo "${0##*/} --info_native_transport"
  17. echo "${0##*/} --info_uptime"
  18. echo "${0##*/} --status_nodes_up"
  19. echo "${0##*/} --status_nodes_down"
  20. echo "${0##*/} --status_nodes_text"
  21. echo "${0##*/} --status_nodes_globalstatus"
  22. echo "${0##*/} --tpstats_globalstatus"
  23. echo "${0##*/} --tpstats_readstage_active"
  24. echo "${0##*/} --tpstats_readstage_pending"
  25. echo "${0##*/} --tpstats_readstage_completed"
  26. echo "${0##*/} --tpstats_readstage_blocked"
  27. echo "${0##*/} --tpstats_readstage_all_time_blocked"
  28. exit
  29. }
  30. #UserParameter=cassandra.status.main
  31. function status_main {
  32. out=`$cassandra_script 2>&1`
  33. if [[ $out =~ ^CASSANDRA[[:space:]]OK.*||WARNING[[:space:]]-[[:space:]]WARNING:[[:space:]]\d+%[[:space:]]heap[[:space:]]used.* ]]; then
  34. echo "1"
  35. else
  36. echo "0"
  37. fi
  38. }
  39. #UserParameter=cassandra.status.main.text
  40. function status_main_text {
  41. $cassandra_script 2>&1
  42. }
  43. #UserParameter=cassandra.status.heap_mem
  44. function status_heap_mem {
  45. out=`$cassandra_script 2>&1 |awk -F 'heap_mem=' '{print $2}'`
  46. check=`bc <<< "$out > 0"`
  47. if [ $check -eq 1 ]; then
  48. echo $out
  49. else
  50. echo "0"
  51. fi
  52. }
  53. #UserParameter=cassandra.info.id
  54. function info_id {
  55. nodetool info |egrep "^ID" |awk -F ' : ' '{print $2}'
  56. }
  57. #UserParameter=cassandra.info.gossip
  58. function info_gossip {
  59. out=`nodetool info |egrep "^Gossip"|awk -F ' : ' '{print $2}'`
  60. if [[ $out =~ ^true$ ]]; then
  61. echo "0"
  62. else
  63. echo "1"
  64. fi
  65. }
  66. #UserParameter=cassandra.info.thrift
  67. function info_thrift {
  68. out=`nodetool info |egrep "^Thrift"|awk -F ' : ' '{print $2}'`
  69. if [[ $out =~ ^true$ ]]; then
  70. echo "0"
  71. else
  72. echo "1"
  73. fi
  74. }
  75. #UserParameter=cassandra.info.exceptions
  76. function info_exceptions {
  77. out=`nodetool info |egrep "^Exceptions"|awk -F ' : ' '{print $2}'`
  78. if [ "$out" -ge "0" ]; then
  79. echo $out
  80. else
  81. echo "ZBX_NOTSUPPORTED"
  82. fi
  83. }
  84. #UserParameter=cassandra.info.native_transport
  85. function info_native_transport {
  86. out=`nodetool info |egrep "^Native Transport"|awk -F 'active: ' '{print $2}'`
  87. if [[ $out =~ ^true$ ]]; then
  88. echo "0"
  89. else
  90. echo "1"
  91. fi
  92. }
  93. #UserParameter=cassandra.info.uptime
  94. function info_uptime {
  95. out=`nodetool info |egrep "^Uptime"|awk -F ' : ' '{print $2}'`
  96. if [ "$out" -ge "0" ]; then
  97. echo $out
  98. else
  99. echo "ZBX_NOTSUPPORTED"
  100. fi
  101. }
  102. #UserParameter=cassandra.status.nodes_up
  103. function status_nodes_up {
  104. out=`$cassandra_nodes_script 2>&1 |sed 's/.*nodes_up=\([0-9]\+\).*/\1/g'| tr -d '\n'`
  105. if [[ $out =~ ^[0-9]+$ ]]; then
  106. echo $out
  107. else
  108. echo "0"
  109. fi
  110. }
  111. #UserParameter=cassandra.status.nodes_down
  112. function status_nodes_down {
  113. out=`$cassandra_nodes_script 2>&1 |sed 's/.*nodes_down=\([0-9]\+\).*/\1/g'| tr -d '\n'`
  114. if [[ $out =~ ^[0-9]+$ ]]; then
  115. echo $out
  116. else
  117. echo "0"
  118. fi
  119. }
  120. #UserParameter=cassandra.status.nodes.text
  121. function status_nodes_text {
  122. $cassandra_nodes_script 2>&1
  123. }
  124. #UserParameter=cassandra.status.nodes.globalstatus
  125. function status_nodes_globalstatus {
  126. $cassandra_nodes_script 2>&1 |egrep "^OK: [0-9]+ nodes up" -c
  127. }
  128. #UserParameter=cassandra.tpstats.globalstatus
  129. function tpstats_globalstatus {
  130. $cassandra_tpstats_script 2>&1 |egrep "^OK:" -c
  131. }
  132. #UserParameter=cassandra.tpstats.readstage.active
  133. function tpstats_readstage_active {
  134. out=`$cassandra_tpstats_script 2>&1 |sed 's/.*ReadStage_Active=\([0-9]\+\).*/\1/g'| tr -d '\n'`
  135. if [[ $out =~ ^[0-9]+$ ]]; then
  136. echo $out
  137. else
  138. echo "ZBX_NOTSUPPORTED"
  139. fi
  140. }
  141. #UserParameter=cassandra.tpstats.readstage.pending
  142. function tpstats_readstage_pending {
  143. out=`$cassandra_tpstats_script 2>&1 |sed 's/.*ReadStage_Pending=\([0-9]\+\).*/\1/g'| tr -d '\n'`
  144. if [[ $out =~ ^[0-9]+$ ]]; then
  145. echo $out
  146. else
  147. echo "ZBX_NOTSUPPORTED"
  148. fi
  149. }
  150. #UserParameter=cassandra.tpstats.readstage.completed
  151. function tpstats_readstage_completed {
  152. out=`$cassandra_tpstats_script 2>&1 |sed 's/.*ReadStage_Completed=\([0-9]\+\).*/\1/g'| tr -d '\n'`
  153. if [[ $out =~ ^[0-9]+$ ]]; then
  154. echo $out
  155. else
  156. echo "ZBX_NOTSUPPORTED"
  157. fi
  158. }
  159. #UserParameter=cassandra.tpstats.readstage.blocked
  160. function tpstats_readstage_blocked {
  161. out=`$cassandra_tpstats_script 2>&1 |sed 's/.*ReadStage_Blocked=\([0-9]\+\).*/\1/g'| tr -d '\n'`
  162. if [[ $out =~ ^[0-9]+$ ]]; then
  163. echo $out
  164. else
  165. echo "ZBX_NOTSUPPORTED"
  166. fi
  167. }
  168. #UserParameter=cassandra.tpstats.readstage.all_time_blocked
  169. function tpstats_readstage_all_time_blocked {
  170. out=`$cassandra_tpstats_script 2>&1 |sed 's/.*ReadStage_All_time_blocked=\([0-9]\+\).*/\1/g'| tr -d '\n'`
  171. if [[ $out =~ ^[0-9]+$ ]]; then
  172. echo $out
  173. else
  174. echo "ZBX_NOTSUPPORTED"
  175. fi
  176. }
  177. test x"$1" == x"" && usage
  178. test x"$1" == x"--status_main" && status_main
  179. test x"$1" == x"--status_main_text" && status_main_text
  180. test x"$1" == x"--status_heap_mem" && status_heap_mem
  181. test x"$1" == x"--info_id" && info_id
  182. test x"$1" == x"--info_gossip" && info_gossip
  183. test x"$1" == x"--info_thrift" && info_thrift
  184. test x"$1" == x"--info_exceptions" && info_exceptions
  185. test x"$1" == x"--info_native_transport" && info_native_transport
  186. test x"$1" == x"--info_uptime" && info_uptime
  187. test x"$1" == x"--status_nodes_up" && status_nodes_up
  188. test x"$1" == x"--status_nodes_down" && status_nodes_down
  189. test x"$1" == x"--status_nodes_text" && status_nodes_text
  190. test x"$1" == x"--status_nodes_globalstatus" && status_nodes_globalstatus
  191. test x"$1" == x"--tpstats_globalstatus" && tpstats_globalstatus
  192. test x"$1" == x"--tpstats_readstage_active" && tpstats_readstage_active
  193. test x"$1" == x"--tpstats_readstage_pending" && tpstats_readstage_pending
  194. test x"$1" == x"--tpstats_readstage_completed" && tpstats_readstage_completed
  195. test x"$1" == x"--tpstats_readstage_blocked" && tpstats_readstage_blocked
  196. test x"$1" == x"--tpstats_readstage_all_time_blocked" && tpstats_readstage_all_time_blocked