运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(二)
- #!/bin/bash
- #ip
- web_ip=$(/sbin/ifconfig eth0|grep "inet addr"|cut -d : -f 2|awk '{print $1}')
- ##eth0网卡的ip
- #name
- web_name=$(hostname)
- ##web主机名
- monitor_name=web
- ##监控的服务器是什么类型
- here='gansu'
- ##监控的省份
- #mysql info
- mysql_ip='1.1.1.1'
- ##数据库的ip
- mysql_username='root'
- ##数据库的用户
- mysql_passwd='****'
- #数据库的密码
- mysql_database='monitor'
- ##选择的数据库
- memory_table=''$here'_memory'
- load_table=''$here'_load'
- io_table=''$here'_io'
- hardware_table=''$here'_hardware'
- message_table=''$here'_message'
- user_table=''$here'_user'
- disk_table=''$here'_disk'
- cpu_table=''$here'_cpu'
- service_table=''$here'_service'
- ##想数据库里写入的表
- #date and log
- day="$(date +%Y%m%d)"
- worklog='/usr/local/monitor/logs/all_work_log'
- downlog='/usr/local/monitor/logs/all_down_log'
- ##日志与实际
- now="$(date +%Y-%m-%d-%T)"
- #web service
- tomcat="$(netstat -antl|grep 8080|wc -l)"
- web_http="$(ps -ef|grep httpd|grep -v grep|wc -l)"
- yz_tomcat="$(netstat -antl|grep 8081|wc -l)"
- ##通过端口与服务在后头的运行情况监控其运行状态
- #cpu service
- alert_cpu='80'
- ##cpu的报警阀值
- web_cpu_idle="$(top -b -n 1 | grep Cpu | awk '{print $5}' | cut -f 1 -d .)"
- web_cpu="$(echo 100 - $web_cpu_idle|/usr/bin/bc)"
- ##监控cpu的使用率
- #memory service
- alert_mem='100'
- ##内存的报警阀值
- web_mem="$(/usr/bin/free -m|grep Mem|awk '{print $4}')"
- web_swap="$(/usr/bin/free -m|grep Swap|awk '{print $3}')"
- ##memory与swap的使用率
- alert_swap='0'
- ##swap的报警阀值
- #memory log
- memory_worklog='/usr/local/monitor/logs/mem_work_log'
- memory_downlog='/usr/local/monitor/logs/mem_down_log'
- #load service
- cpu_count="$(grep -c 'model name' /proc/cpuinfo)"
- alert_load="$(echo $cpu_count/2|/usr/bin/bc)"
- web_load="$(uptime|awk '{print $NF}'|cut -f 1 -d .)"
- web_load_15="$(uptime|awk '{print $NF}')"
- #监控负载的使用率
- #load log
- load_worklog='/usr/local/monitor/logs/load_work_log'
- load_downlog='/usr/local/monitor/logs/load_down_log'
- #io service
- alert_io='80'
- web_io_idle_back="$(/usr/bin/iostat|awk 'NR==4{print $NF}'|cut -f 1 -d .)"
- web_io_idle="$(echo 100 - $web_io_idle_back|/usr/bin/bc)"
- ##io的使用值
- #io log
- io_worklog='/usr/local/monitor/logs/io_work_log'
- io_downlog='/usr/local/monitor/logs/io_down_log'
- #hardware service
- web_hardware_error="$(dmesg|grep -i error|wc -l)"
- web_info_error="$(dmesg|grep -i error)"
- ##开机启动的错误信息
- #hardware error log
- hard_worklog='/usr/local/monitor/logs/hard_work_log'
- hard_downlog='/usr/local/monitor/logs/hard_down_log'
- #message service
- web_message_error_count="$(awk '/"$(date +%Y%m%d)"/' /var/log/messages|grep -i error|wc -l)"
- web_message_error="$(awk '/"$(date +%Y%m%d)"/' /var/log/messages|grep -i error)"
- ##日志的错误信息
- #message error log
- message_worklog='/usr/local/monitor/logs/message_work_log'
- message_downlog='/usr/local/monitor/logs/message_down_log'
- #user service
- web_user_count="$(/usr/bin/who|wc -l)"
- web_user_info="$(/usr/bin/who)"
- ##当前登录的用户值
- #user log
- user_worklog='/usr/local/monitor/logs/user_work_log'
- user_downlog='/usr/local/monitor/logs/user_down_log'
- #disk service
- alert_disk='80'
- web_disk="$(/bin/df -H|sort -k5nr|grep -vE 'Filesystem|tmpfs|cdrom'|awk '{print $5 " " $1}')"
- web_disk_use=$(echo $web_disk|awk '{print $1}'|cut -d '%' -f1)
- web_disk_partition=$(echo $web_disk|awk '{print $2}')
- #硬盘使用率
- #disk log
- disk_worklog='/usr/local/monitor/logs/disk_work_log'
- disk_downlog='/usr/local/monitor/logs/disk_down_log'
- #cpu log
- cpu_worklog='/usr/local/monitor/logs/cpu_work_log'
- cpu_downlog='/usr/local/monitor/logs/cpu_down_log'
- #notification mail
- email='denglei@ctfo.com'
- ##报警的接收人
- #monitor
- if [ ! -d "$loghere" ];then
- mkdir $loghere
- fi
- #check web service
- if [ $web_http -ge 1 ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: http Monitor_Server: $monitor_name is working" >> $worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','web_http','working',now())";
- else
- /etc/init.d/httpd start
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: http Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: http was a problem" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: http Monitor_Server: $montior_name is down" >> $downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','web_http','downing',now())";
- fi
- if [ $tomcat -ge 1 ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: tomcat Monitor_Server: $monitor_name is working" >> $worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','tomcat','working',now())";
- else
- /usr/local/monitor/shell/web_tomcat.sh
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: tomcat Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: tomcat was a problem" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: tomcat Monitor_Server: $montior_name is down" >> $downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','tomcat','downing',now())";
- fi
- if [ $yz_tomcat -ge 1 ];then
- echo "$now ShengFen: $here Server: $web_name Service: Ip: $web_ip yz_tomcat Monitor_Server: $monitor_name is working" >> $worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','yz_tomcat','working',now())";
- else
- /usr/local/monitor/shell/web_yz_tomcat.sh
- echo "$now ShengFen: $here Server: $web_name Service: Ip: $web_ip yz_tomcat Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: yz_tomcat was a problem" $email
- echo "$now ShengFen: $here Server: $web_name Service: Ip: $web_ip yz_tomcat Monitor_Server: $montior_name is down" >> $downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$web_name','$web_ip','$monitor_name','yz_tomcat','downing',now())";
- fi
- #check cpu_idle
- if [ $web_cpu -ge $alert_cpu ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $web_cpu"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: cpu_use was Exceed Threshold value: 80%" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $web_cpu" >> $cpu_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $cpu_table values ('','$here','$web_name','$web_ip','$monitor_name','cpu_use','$alert_cpu','$web_cpu','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $web_cpu" >> $cpu_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $cpu_table values ('','$here','$web_name','$web_ip','$monitor_name','cpu_use','$alert_cpu','$web_cpu','normal',now())";
- fi
- #check memory
- if [ $web_mem -le $alert_mem ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: memory Monitor_Server: $monitor_name Free_mem: $web_mem"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: memory was Exceed Threshold value" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: memory Monitor_Server: $monitor_name Free_mem: $web_mem" >> $memory_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$web_name','$web_ip','$monitor_name','memory','$alert_mem','$web_mem','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: memory Monitor_Server: $monitor_name Free_mem: $web_mem" >> $memory_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$web_name','$web_ip','$monitor_name','memory','$alert_mem','$web_mem','normal',now())";
- fi
- #check swap
- if [ $web_swap -gt $alert_swap ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: swap Monitor_Server: $monitor_name Swap_web: $web_swap"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: swap Ip: $web_ip was Exceed Threshold value" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: swap Monitor_Server: $monitor_name Swap_web: $web_swap" >> $memory_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$web_name','$web_ip','$monitor_name','swap','$alert_swap','$web_swap','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: swap Monitor_Server: $monitor_name Swap_web: $web_swap" >> $memory_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$web_name','$web_ip','$monitor_name','swap','$alert_swap','$web_swap','normal',now())";
- fi
- #check load_15
- if [ $web_load -ge $alert_load ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: load_15 Monitor_Server: $monitor_name Load_use: $web_load_15"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: load_15 Ip: $web_ip was Exceed Threshold value" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: load_15 Monitor_Server: $monitor_name Load_use: $web_load_15" >> $load_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $load_table values ('','$here','$web_name','$web_ip','$monitor_name','load_15','$alert_load','$web_load_15','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $server Ip: $ip Service: load Monitor_Server: $monitor_name Load_use: $web_load_15" >> $load_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $load_table values ('','$here','$web_name','$web_ip','$monitor_name','load_15','$alert_load','$web_load_15','normal',now())";
- fi
- #check io_idle
- if [ $web_io_idle -ge $alert_io ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $web_io_idle"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: io_use was Exceed Threshold value: 80%" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $web_io_idle" >> $io_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $io_table values ('','$here','$web_name','$web_ip','$monitor_name','io_use','$alert_io','$web_io_idle','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $web_io_idle" >> $io_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $io_table values ('','$here','$web_name','$web_ip','$monitor_name','io_use','$alert_io','$web_io_idle','normal',now())";
- fi
- #check hareware error info
- if [ $web_hardware_error -gt 0 ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: hardware_error Monitor_Server: $monitor_name Error: $web_info_error"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: hardware_error were some hardware imformation error" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: hardware_error Monitor_Server: $monitor_name Error: $web_info_error" >> $hard_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $hardware_table values ('','$here','$web_name','$web_ip','$monitor_name','hardware_error','0','$web_hardware_error','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: hardware_error Monitor_Server: $monitor_name Error: Nothing" >> $hard_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $hardware_table values ('','$here','$web_name','$web_ip','$monitor_name','hardware_error','0','$web_hardware_error','normal',now())";
- fi
- #check message error
- if [ $web_message_error_count -ge 1 ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: message_error Monitor_Server: $monitor_name Message_error: $web_message_error"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: message_error were some message imformation error" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: message_error Monitor_Server: $monitor_name Message_error: $web_message_error" >> $message_downlog-$day
- /usr/bin/mysql-h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $message_table values ('','$here','$web_name','$web_ip','$monitor_name','message_error','1','$web_message_error_count','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: message_error Monitor_Server: $monitor_name Message_error: Nothing" >> $message_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $message_table values ('','$here','$web_name','$web_ip','$monitor_name','message_error','1','$web_message_error_count','normal',now())";
- fi
- #check user
- if [ $web_user_count -ge 3 ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: user Monitor_Server: $monitor_name User: $web_user_info"|/bin/mail -s "Notification ShengFen: $here Server: $web_name Service: user was Exceed Threshold value: 3" $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: user Monitor_Server: $monitor_name User: $web_user_info" >> $user_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $user_table values ('','$here','$web_name','$web_ip','$monitor_name','user','3','$web_user_count','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: user Monitor_Server: $monitor_name User: normal" >> $user_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $user_table values ('','$here','$web_name','$web_ip','$monitor_name','user','3','$web_user_count','normal',now())";
- fi
- #check disk
- if [ $web_disk_use -ge $alert_disk ];then
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $web_disk_partition ($web_disk_use%)"|/bin/mail -s "Warning!!! $here Server: $web_name Service: disk_use was Exceed Threshold value : $alert_disk% " $email
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $web_disk_partion ($web_disk_use%)" >> $disk_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $disk_table values ('','$here','$web_name','$web_ip','$monitor_name','disk_use','$alert_disk','$web_disk_partition','$web_disk_use','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $web_name Ip: $web_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $web_disk_partition ($web_disk_use%)" >> $disk_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $disk_table values ('','$here','$web_name','$web_ip','$monitor_name','disk_use','$alert_disk','$web_disk_partition','$web_disk_use','normal',now())";
- fi
- #!/bin/bash
- #ip
- jh_ip=$(/sbin/ifconfig eth0|grep "inet addr"|cut -d : -f 2|awk '{print $1}')
- #name
- jh_name=$(hostname)
- monitor_name=jiaohuan
- here='gansu'
- #mysql info
- mysql_ip='1.1.1.1'
- mysql_username='root'
- mysql_passwd='****'
- mysql_database='monitor'
- memory_table=''$here'_memory'
- load_table=''$here'_load'
- io_table=''$here'_io'
- hardware_table=''$here'_hardware'
- message_table=''$here'_message'
- user_table=''$here'_user'
- disk_table=''$here'_disk'
- cpu_table=''$here'_cpu'
- service_table=''$here'_service'
- #date and log
- day="$(date +%Y%m%d)"
- worklog='/usr/local/monitor/logs/all_work_log'
- downlog='/usr/local/monitor/logs/all_down_log'
- now="$(date +%Y-%m-%d-%T)"
- loghere='/usr/local/monitor/logs'
- #jiaohuan service
- pas="$(ps -ef|grep pas|grep -v grep|grep -v ppas|wc -l)"
- ppas="$(ps -ef|grep ppas|grep -v grep|wc -l)"
- cas="$(ps -ef|grep cas|grep -v grep|wc -l)"
- mas="$(ps -ef|grep mas|grep -v grep|grep -v mmas|wc -l)"
- mmas="$(ps -ef|grep mmas|grep -v grep|wc -l)"
- #cpu service
- alert_cpu='80'
- jh_cpu_idle="$(top -b -n 1 | grep Cpu | awk '{print $5}' | cut -f 1 -d .)"
- jh_cpu="$(echo 100 - $jh_cpu_idle|/usr/bin/bc)"
- #memory service
- alert_mem='100'
- jh_mem="$(/usr/bin/free -m|grep Mem|awk '{print $4}')"
- jh_swap="$(/usr/bin/free -m|grep Swap|awk '{print $3}')"
- alert_swap='0'
- #memory log
- memory_worklog='/usr/local/monitor/logs/mem_work_log'
- memory_downlog='/usr/local/monitor/logs/mem_down_log'
- #load service
- cpu_count="$(grep -c 'model name' /proc/cpuinfo)"
- alert_load="$(echo $cpu_count/2|/usr/bin/bc)"
- jh_load="$(uptime|awk '{print $NF}'|cut -f 1 -d .)"
- jh_load_15="$(uptime|awk '{print $NF}')"
- #load log
- load_worklog='/usr/local/monitor/logs/load_work_log'
- load_downlog='/usr/local/monitor/logs/load_down_log'
- #io service
- alert_io='80'
- jh_io_idle_back="$(/usr/bin/iostat|awk 'NR==4{print $NF}'|cut -f 1 -d .)"
- jh_io_idle="$(echo 100 - $jh_io_idle_back|/usr/bin/bc)"
- #io log
- io_worklog='/usr/local/monitor/logs/io_work_log'
- io_downlog='/usr/local/monitor/logs/io_down_log'
- #hardware service
- jh_hardware_error="$(dmesg|grep -i error|wc -l)"
- jh_info_error="$(dmesg|grep -i error)"
- #hardware error log
- hard_worklog='/usr/local/monitor/logs/hard_work_log'
- hard_downlog='/usr/local/monitor/logs/hard_down_log'
- #message service
- jh_message_error_count="$(awk '/"$(date +%Y%m%d)"/' /var/log/messages|grep -i error|wc -l)"
- jh_message_error="$(awk '/"$(date +%Y%m%d)"/' /var/log/messages|grep -i error)"
- #message error log
- message_worklog='/usr/local/monitor/logs/message_work_log'
- message_downlog='/usr/local/monitor/logs/message_down_log'
- #user service
- jh_user_count="$(/usr/bin/who|wc -l)"
- jh_user_info="$(/usr/bin/who)"
- #user log
- user_worklog='/usr/local/monitor/logs/user_work_log'
- user_downlog='/usr/local/monitor/logs/user_down_log'
- #disk service
- alert_disk='80'
- jh_disk="$(/bin/df -H|sort -k5nr|grep -vE 'Filesystem|tmpfs|cdrom'|awk '{print $5 " " $1}')"
- jh_disk_use=$(echo $jh_disk|awk '{print $1}'|cut -d '%' -f1)
- jh_disk_partition=$(echo $jh_disk|awk '{print $2}')
- #disk log
- disk_worklog='/usr/local/monitor/logs/disk_work_log'
- disk_downlog='/usr/local/monitor/logs/disk_down_log'
- #cpu log
- cpu_worklog='/usr/local/monitor/logs/cpu_work_log'
- cpu_downlog='/usr/local/monitor/logs/cpu_down_log'
- #notification mail
- email='denglei@ctfo.com'
- #monitor
- if [ ! -d "$loghere" ];then
- mkdir $loghere
- fi
- #monitor
- #jiaohuan check
- if [ $pas -ge 1 ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: pas Monitor_Server: $monitor_name is working" >> $worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','pas','working',now())";
- else
- /usr/local/lbs/bin4.0.7.7/pas -daemon
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: pas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: pas was a problem" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: pas Monitor_Server: $montior_name is down" >> $downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','pas','downing',now())";
- fi
- if [ $ppas -ge 1 ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: ppas Monitor_Server: $monitor_name is working" >> $worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','ppas','working',now())";
- else
- /usr/local/lbs/bin4.0.7.7/ppas -daemon
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: ppas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: ppas was a problem" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: ppas Monitor_Server: $montior_name is down" >> $downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','ppas','downing',now())";
- fi
- if [ $mas -ge 1 ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mas Monitor_Server: $monitor_name is working" >> $worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','mas','working',now())";
- else
- /usr/local/lbs/bin4.0.7.7/mas -daemon
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: mas was a problem" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mas Monitor_Server: $montior_name is down" >> $downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','mas','downing',now())";
- fi
- if [ $mmas -ge 1 ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mmas Monitor_Server: $monitor_name is working" >> $worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','mmas','working',now())";
- else
- /usr/local/lbs/bin4.0.7.7/mmas -daemon
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mmas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: mmas was a problem" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: mmas Monitor_Server: $montior_name is down" >> $downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','mmas','downing',now())";
- fi
- if [ $cas -ge 1 ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cas Monitor_Server: $monitor_name is working" >> $worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','cas','working',now())";
- else
- /usr/local/lbs/bin4.0.7.7/cas -daemon
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cas Monitor_Server: $monitor_name is down"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: cas was a problem" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cas Monitor_Server: $montior_name is down" >> $downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $service_table values ('','$here','$jh_name','$jh_ip','$monitor_name','cas','downing',now())";
- fi
- #check cpu_idle
- if [ $jh_cpu -ge $alert_cpu ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $jh_cpu"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: cpu_use was Exceed Threshold value: 80%" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $jh_cpu" >> $cpu_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $cpu_table values ('','$here','$jh_name','$jh_ip','$monitor_name','cpu_use','$alert_cpu','$jh_cpu','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: cpu_idle Monitor_Server: $monitor_name Cpu_use: $jh_cpu" >> $cpu_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $cpu_table values ('','$here','$jh_name','$jh_ip','$monitor_name','cpu_use','$alert_cpu','$jh_cpu','normal',now())";
- fi
- #check memory
- if [ $jh_mem -le $alert_mem ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: memory Monitor_Server: $monitor_name Free_mem: $jh_mem"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: memory was Exceed Threshold value" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: memory Monitor_Server: $monitor_name Free_mem: $jh_mem" >> $memory_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$jh_name','$jh_ip','$monitor_name','memory','$alert_mem','$jh_mem','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: memory Monitor_Server: $monitor_name Free_mem: $jh_mem" >> $memory_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$jh_name','$jh_ip','$monitor_name','memory','$alert_mem','$jh_mem','normal',now())";
- fi
- #check swap
- if [ $jh_swap -gt $alert_swap ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: swap Monitor_Server: $monitor_name Swap_jh: $jh_swap"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: swap Ip: $jh_ip was Exceed Threshold value" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: swap Monitor_Server: $monitor_name Swap_jh: $jh_swap" >> $memory_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$jh_name','$jh_ip','$monitor_name','swap','$alert_swap','$jh_swap','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: swap Monitor_Server: $monitor_name Swap_jh: $jh_swap" >> $memory_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $memory_table values ('','$here','$jh_name','$jh_ip','$monitor_name','swap','$alert_swap','$jh_swap','normal',now())";
- fi
- #check load_15
- if [ $jh_load -ge $alert_load ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: load_15 Monitor_Server: $monitor_name Load_use: $jh_load_15"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: load_15 Ip: $jh_ip was Exceed Threshold value" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: load_15 Monitor_Server: $monitor_name Load_use: $jh_load_15" >> $load_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $load_table values ('','$here','$jh_name','$jh_ip','$monitor_name','load_15','$alert_load','$jh_load_15','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $server Ip: $ip Service: load Monitor_Server: $monitor_name Load_use: $jh_load_15" >> $load_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $load_table values ('','$here','$jh_name','$jh_ip','$monitor_name','load_15','$alert_load','$jh_load_15','normal',now())";
- fi
- #check io_idle
- if [ $jh_io_idle -ge $alert_io ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $jh_io_idle"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: io_use was Exceed Threshold value: 80%" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $jh_io_idle" >> $io_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $io_table values ('','$here','$jh_name','$jh_ip','$monitor_name','io_use','$alert_io','$jh_io_idle','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: io_idle Monitor_Server: $monitor_name Io_use: $jh_io_idle" >> $io_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $io_table values ('','$here','$jh_name','$jh_ip','$monitor_name','io_use','$alert_io','$jh_io_idle','normal',now())";
- fi
- #check hareware error info
- if [ $jh_hardware_error -gt 0 ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: hardware_error Monitor_Server: $monitor_name Error: $jh_info_error"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: hardware_error were some hardware imformation error" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: hardware_error Monitor_Server: $monitor_name Error: $jh_info_error" >> $hard_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $hardware_table values ('','$here','$jh_name','$jh_ip','$monitor_name','hardware_error','0','$jh_hardware_error','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: hardware_error Monitor_Server: $monitor_name Error: Nothing" >> $hard_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $hardware_table values ('','$here','$jh_name','$jh_ip','$monitor_name','hardware_error','0','$jh_hardware_error','normal',now())";
- fi
- #check message error
- if [ $jh_message_error_count -ge 1 ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: message_error Monitor_Server: $monitor_name Message_error: $jh_message_error"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: message_error were some message imformation error" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: message_error Monitor_Server: $monitor_name Message_error: $jh_message_error" >> $message_downlog-$day
- /usr/bin/mysql-h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $message_table values ('','$here','$jh_name','$jh_ip','$monitor_name','message_error','1','$jh_message_error_count','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: message_error Monitor_Server: $monitor_name Message_error: Nothing" >> $message_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $message_table values ('','$here','$jh_name','$jh_ip','$monitor_name','message_error','1','$jh_message_error_count','normal',now())";
- fi
- #check user
- if [ $jh_user_count -ge 3 ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: user Monitor_Server: $monitor_name User: $jh_user_info"|/bin/mail -s "Notification ShengFen: $here Server: $jh_name Service: user was Exceed Threshold value: 3" $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: user Monitor_Server: $monitor_name User: $jh_user_info" >> $user_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $user_table values ('','$here','$jh_name','$jh_ip','$monitor_name','user','3','$jh_user_count','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: user Monitor_Server: $monitor_name User: normal" >> $user_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $user_table values ('','$here','$jh_name','$jh_ip','$monitor_name','user','3','$jh_user_count','normal',now())";
- fi
- #check disk
- if [ $jh_disk_use -ge $alert_disk ];then
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $jh_disk_partition ($jh_disk_use%)"|/bin/mail -s "Warning!!! $here Server: $jh_name Service: disk_use was Exceed Threshold value : $alert_disk% " $email
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $jh_disk_partion ($jh_disk_use%)" >> $disk_downlog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $disk_table values ('','$here','$jh_name','$jh_ip','$monitor_name','disk_use','$alert_disk','$jh_disk_partition','$jh_disk_use','abnormal',now())";
- else
- echo "$now ShengFen: $here Server: $jh_name Ip: $jh_ip Service: disk_use Monitor_Server: $monitor_name Disk_use: $jh_disk_partition ($jh_disk_use%)" >> $disk_worklog-$day
- /usr/bin/mysql -h $mysql_ip -u$mysql_username -p$mysql_passwd $mysql_database -e "insert into $disk_table values ('','$here','$jh_name','$jh_ip','$monitor_name','disk_use','$alert_disk','$jh_disk_partition','$jh_disk_use','normal',now())";
- fi
下一篇文章地址:
运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(三)
http://dl528888.blog.51cto.com/2382721/1035142
本文出自 “吟—技术交流” 博客,请务必保留此出处http://dl528888.blog.51cto.com/2382721/1035131
转载于:https://blog.51cto.com/solothisworld/1047948
运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(二)相关推荐
- 运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(一)
前言 记得刚来这家公司的时候,我部门就我一个运维工程师,然后就是经理,刚开始公司平台什么监控都没有,在我与经理的努力下,先搭建nagios+cacti监控平台,后来随着公司业务的增加,平台的功能与服务 ...
- 运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(五)
4.监控视图 主要是通过shell脚本进行收集mysql的数据,然后同gnuplot软件进行数据视图化,然后php加载这些图片到web里显示,用到的php文件为view.php day.php.mon ...
- 运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(四)
(5)数据库服务器(以甘肃数据库为例,脚本解释参照甘肃web) #!/bin/bash #ip db_ip=$(/sbin/ifconfig eth0|grep "inet addr&quo ...
- 运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统
转载来自:http://dl528888.blog.51cto.com/2382721/1034992 前言 记得刚来这家公司的时候,我部门就我一个运维工程师,然后就是经理,刚开始公司平台什么监控都没 ...
- 运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(七)
X.create_province.sh脚本内容 #!binbash LANG="zh_CN.UTF-8" LANG=C #mysql info mysql_ip='1.1.1.1 ...
- php自动运维,运维自动化之使用PHP+MYSQL+SHELL打造私有监控系统(五)
include("conn.php"); include("head.php"); include("province.php"); ?&g ...
- linux运维自动化脚本,linux运维自动化shell脚本小工具
linux运维shell 脚本小工具,如要分享此文章,请注明文章出处,以下脚本仅供参考,若放置在服务器上出错,后果请自负 1.检测cpu剩余百分比 #!/bin/bash #Inspect CPU # ...
- Servicehot和你说说运维自动化的那些事儿
2019独角兽企业重金招聘Python工程师标准>>> 运维管理兜兜转转十几余载,大家的运维管理再也不是小米加步枪.人工费力拉线扛服务器的传统时代,如你所知,这些年大家张口闭口谈的都 ...
- 舍本求末的运维自动化技术热潮
运维自动化是2010年开始炒得很热的一个概念,也让很多工程师.用人单位瞎激动了很久,我也跟风学过puppet和python,求职双方也经常在面试时花大量时间谈运维自动化. 但冷静下来想想,所谓自动化, ...
最新文章
- debian,ubuntu下安装MariaDB,并设置密码,修改端口,允许外网访问
- 三菱fx5u编程手册_实用分享 | 三菱FX 5U特点是什么?
- 详解linux的initrd
- 移动端怎么让底部固定_移动端排名应该怎么做?两种匹配移动端实战排名干货分享...
- 不联网redhat5.5安装oracle11g,redhat5.5_64位上安装oracle11gR2_步骤+问题解决
- Excel文件批量删除指定行或列
- Joplin 的思维导图 Mindmap(脑图)插件
- 树莓派使用USB摄像头和motion实现监控
- 关于一些Excel的快捷键总结
- linux下利用yum安装svn
- AD21覆铜,包地,补泪滴,有图
- Java的Scanner对象
- 安科瑞电气火灾监控系统对分散在建筑内的探测器进行遥测、遥调、遥控、遥信,方便实现监控与管理。
- Bt(宝塔面板)phpmyadmin打不开的解决办法
- 【电机】使用Simulink建立BLDC反电动势测量的简单模型
- 日更100天(5)每天进步一点点
- win10 移动文件夹和移动文件
- 闭环系统的零极点图判定稳定性_《自动控制原理》课后习题答案.doc
- 什么是SAFe? SAFe管理工具
- 毕业论文问卷数据怎样分析才正确?
热门文章
- vertica MySQL_Vertica数据库操作
- windows server 2012 远程连不上_CVE20201350 | Windows DNS Server远程代码执行漏洞通告
- 节前福利 | 三位大佬带你从客户成功、销售、市场端打造 To B 运作体系 !
- PPT 下载 | 神策数据朱静芸:消费者全渠道精细化运营方案
- 干货下载 | 评估产品增长,勿陷入“土著思维”
- 国际青年日,神策数据召唤优(有)质(志)青年
- android tv如何适配不同的平台
- Android动画 详解(一 补间动画)
- 当clear line vty 命令不起作用时
- 艾伟:ASP.NET MVC,深入浅出IModelBinder,在Post方式下慎用HtmlHelper