cpu&mem监控脚本

2021-05-18 10:06:13 浏览数 (1)

#!/bin/bash

time=`date "%Y-%m-%d %H:%M:%S"`

d=`date %Y%m%d`

N=`ps -ef | grep httpd | grep -v grep | wc -l`

Q=`ps -ef | grep java | grep -v grep | wc -l`

[ -d /root/check_log/ ] || mkdir /root/check_log

IP=`/sbin/ifconfig eth0 | sed -n '2'p | awk '{print $2}' | awk -F':' '{print $2}'`

M=`uptime | awk '{print $8,$9,$10,$11,$12}'`

O=`/sbin/ifconfig eth0 | sed -n '8'p | awk '{print $3,$4}'`

P=`/sbin/ifconfig eth0 | sed -n '8'p | awk '{print $7,$8}'`

R=`/sbin/ifconfig eth1 | sed -n '8'p | awk '{print $3,$4}'`

S=`/sbin/ifconfig eth1 | sed -n '8'p | awk '{print $7,$8}'`

A=`top -bn1 | sed -n '2'p | awk '{print $2}'`

B=`top -bn1 | sed -n '2'p | awk '{print $10}'`

echo --------------------------分割线 -------------------------- >> /root/check_log/$d.log

echo --------------------------分割线 -------------------------- >> /root/check_log/$d.log

echo ****************************$IP**************************** >> /root/check_log/$d.log

echo "系统当前时间:" >> /root/check_log/$d.log

echo $time >> /root/check_log/$d.log

echo "---------------------check system load------------------" >> /root/check_log/$d.log

echo "系统当前负载:" >> /root/check_log/$d.log

echo $M >> /root/check_log/$d.log

echo "---------------------check 总进程数---------------------" >> /root/check_log/$d.log

echo "系统当前总进程数:" >> /root/check_log/$d.log

echo $A >> /root/check_log/$d.log

echo "系统当前僵死进程数:" >> /root/check_log/$d.log

echo $B >> /root/check_log/$d.log

echo "---------------------check 应用进程数--------------------" >> /root/check_log/$d.log

echo "当前apache进程数:" >> /root/check_log/$d.log

echo $N >> /root/check_log/$d.log

echo "当前java进程数" >> /root/check_log/$d.log

echo $Q >> /root/check_log/$d.log

echo "---------------------check Tcp连接状态-------------------" >> /root/check_log/$d.log

netstat -n | awk '/^tcp/ { S[$NF]} END {for(a in S) print a,S[a]}' >> /root/check_log/$d.log

echo "---------------------check 网卡流量-----------------------" >> /root/check_log/$d.log

echo "当前eth0网卡流量:" >> /root/check_log/$d.log

echo "接收总流量:$O" >> /root/check_log/$d.log

echo "发送总流量:$P" >> /root/check_log/$d.log

echo "当前eth1网卡流量:" >> /root/check_log/$d.log

echo "接收总流量:$R" >> /root/check_log/$d.log

echo "发送总流量:$S" >> /root/check_log/$d.log

echo "---------------------check 网卡使用率-----------------------" >> /root/check_log/$d.log

echo sar -n DEV 1 10|grep Average >> /root/check_log/$d.log

echo "-----------------------------check cpu load------------------------------" >> /root/check_log/$d.log

echo "系统当前cpu负载:" >> /root/check_log/$d.log

sar -u 1 10 | grep -v Linux | grep -v ^$ >> /root/check_log/$d.log

#cat /proc/stat >>/root/check_log/$d.log

echo "-----------------------------check mem load------------------------------" >> /root/check_log/$d.log

echo "系统当前内存信息:" >> /root/check_log/$d.log

cat /proc/meminfo >> /root/check_log/$d.log

echo "-----------------------------check 磁盘空间------------------------------" >> /root/check_log/$d.log

echo "系统当前磁盘容量:" >> /root/check_log/$d.log

df -h >> /root/check_log/$d.log

echo "-----------------------------check io load-------------------------------" >> /root/check_log/$d.log

echo "系统当前io磁盘负载:" >> /root/check_log/$d.log

iostat 1 10 | grep -v ^$ | grep -v Linux | grep -v dm | grep -v hdc >> /root/check_log/$d.log

#find /root/check_log/ -mtime 6 |xargs rm -f

0 人点赞