check_resin.py

  1. #!/bin/env python
  2. #comment: used to check resin log for zabbix
  3. #date: 2014-12-09
  4. #author: duanchao@lightinthebox.com
  5. # -*- coding: utf-8 -*-
  6. import time,sys,re
  7. clickstream_log_df=open('/opt/resin/log/access.log')
  8. time_ymd=time.strftime('%Y-%m-%d',time.localtime(time.time()))
  9. becur=time.time() - 300
  10. clickstream_log_list=clickstream_log_df.readlines()
  11. clickstream_log_df.close()
  12. clickstream_log_list.reverse()
  13. def get_request_account():
  14. request_account=0
  15. for i in clickstream_log_list:
  16. i_string=i.split('[',1)[1].strip().replace(':',' ')
  17. timestr=time_ymd + ' ' + i_string.split()[1] + ':' + i_string.split()[2] + ':' + i_string.split()[3]
  18. timestamp=time.mktime(time.strptime(timestr, "%Y-%m-%d %H:%M:%S"))
  19. if int(timestamp) >= int(becur):
  20. request_account += 1
  21. else:
  22. break
  23. return request_account
  24. def get_avg_response_time():
  25. request_time=0
  26. n=0
  27. p=re.compile("^(\d+)")
  28. for i in clickstream_log_list:
  29. i_string=i.split('[',1)[1].strip().replace(':',' ')
  30. timestr=time_ymd + ' ' + i_string.split()[1] + ':' + i_string.split()[2] + ':' + i_string.split()[3]
  31. timestamp=time.mktime(time.strptime(timestr, "%Y-%m-%d %H:%M:%S"))
  32. if int(timestamp) >= int(becur):
  33. if "w00tw00t" not in i and 'HTTP/1.0" 400' not in i:
  34. n += 1
  35. s=p.search(i_string.split()[-1])
  36. if s:
  37. request_time = request_time + float(i_string.split()[-1])
  38. else:
  39. break
  40. return ("%.3f" % (request_time / n / 1000000))
  41. if __name__ == '__main__':
  42. status_data_array={
  43. 'avg_response_time' : 'get_avg_response_time()',
  44. 'request_account' : 'get_request_account()',
  45. }
  46. print eval(status_data_array[sys.argv[1]])

monitor_solr

  1. #!/bin/bash
  2. solr_response_time=$(/etc/zabbix/script/check_resin.py avg_response_time)
  3. time=$(echo "$solr_response_time * 1000" | bc | awk -F"." '{print $1}')
  4. if [ "$time" -gt 500 ];then
  5. killall java
  6. sleep 5
  7. /opt/resin/bin/resin.sh start
  8. echo "$(date) solr have been restarted" >> /tmp/monitor_solr.log
  9. else
  10. echo "$(date) ok" >> /tmp/monitor_solr.log
  11. f