check_resin.py
#!/bin/env python#comment: used to check resin log for zabbix#date: 2014-12-09#author: duanchao@lightinthebox.com# -*- coding: utf-8 -*-import time,sys,reclickstream_log_df=open('/opt/resin/log/access.log')time_ymd=time.strftime('%Y-%m-%d',time.localtime(time.time()))becur=time.time() - 300clickstream_log_list=clickstream_log_df.readlines()clickstream_log_df.close()clickstream_log_list.reverse()def get_request_account(): request_account=0 for i in clickstream_log_list: i_string=i.split('[',1)[1].strip().replace(':',' ') timestr=time_ymd + ' ' + i_string.split()[1] + ':' + i_string.split()[2] + ':' + i_string.split()[3] timestamp=time.mktime(time.strptime(timestr, "%Y-%m-%d %H:%M:%S")) if int(timestamp) >= int(becur): request_account += 1 else: break return request_accountdef get_avg_response_time(): request_time=0 n=0 p=re.compile("^(\d+)") for i in clickstream_log_list: i_string=i.split('[',1)[1].strip().replace(':',' ') timestr=time_ymd + ' ' + i_string.split()[1] + ':' + i_string.split()[2] + ':' + i_string.split()[3] timestamp=time.mktime(time.strptime(timestr, "%Y-%m-%d %H:%M:%S")) if int(timestamp) >= int(becur): if "w00tw00t" not in i and 'HTTP/1.0" 400' not in i: n += 1 s=p.search(i_string.split()[-1]) if s: request_time = request_time + float(i_string.split()[-1]) else: break return ("%.3f" % (request_time / n / 1000000))if __name__ == '__main__': status_data_array={ 'avg_response_time' : 'get_avg_response_time()', 'request_account' : 'get_request_account()', } print eval(status_data_array[sys.argv[1]])
monitor_solr
#!/bin/bashsolr_response_time=$(/etc/zabbix/script/check_resin.py avg_response_time)time=$(echo "$solr_response_time * 1000" | bc | awk -F"." '{print $1}')if [ "$time" -gt 500 ];then killall java sleep 5 /opt/resin/bin/resin.sh start echo "$(date) solr have been restarted" >> /tmp/monitor_solr.logelse echo "$(date) ok" >> /tmp/monitor_solr.logf