TOP查看有个单cpu占满,影响到了snmp采集,排查原因

写个脚本记录占用cpu、memory高的进程
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
DIR="/tmp/test"
[ -d $DIR ] || mkdir -p $DIR
LOG="$DIR/`date +%Y%m%d%H%M%S`.txt"
top -b -d 1 -n 1 > $LOG
pstree >> $LOG
dstat -t --proc-count --top-cpu --top-mem -cdlmnsyr --disk-util --output $DIR/dstat.csv 5 100
根据输出内容,查看systemd /进程占用较多,怀疑是systemctl的bug
bug:Bug 1308780 - systemd Using 4GB RAM after 18 Days of Uptime
https://bugzilla.redhat.com/show_bug.cgi?id=1308780
解决方案:http://www.51niux.com/?id=223
更新system试试:
yum install systemd
yum install dbus
yum install polkit
更新脚本:
#!/bin/bash
dversion=`dbus-daemon --version |head -1 | awk '{print $NF}'`;
s3=`rpm -qa |fgrep systemd-sysv`;
flag1=0;
flag2=0;
if [ "$dversion"X = "1.10.24"X ]; then
flag1=1;
fi
if [ "$s3"X = "systemd-sysv-219-78.el7_9.3.x86_64"X ] || [ "$s3"X = "systemd-sysv-302-78.el7_9.3.x86_64"X ]; then
flag2=1;
fi
yum install systemd -y >> /dev/null
if [ "$?" = "0" ]; then
echo "ok: yum install systemd";
else
echo "error: yum install systemd";
exit 1;
fi
yum install dbus -y >> /dev/null
if [ "$?" = "0" ]; then
echo "ok: yum install dbus";
else
echo "error: yum install dbus";
exit 1;
fi
yum install polkit -y >> /dev/null
if [ "$?" = "0" ]; then
echo "ok: yum install polkit";
else
echo "error: yum install polkit";
exit 1;
fi
if [ "$flag1" = "0" ]; then
service dbus restart
if [ "$?" = "0" ]; then
echo "ok: dbus restart";
else
echo "error: dbus restart";
exit 1;
fi
fi
if [ "$flag2" = "0" ]; then
service systemd-logind restart
if [ "$?" = "0" ]; then
echo "ok: systemd restart";
else
echo "error: systemd restart";
exit 1;
fi
fi
echo "====="
m=`ps aux |fgrep '/usr/lib/systemd/systemd ' |fgrep -v grep| awk '{printf("%.2f", $6/1024.0/1024.0)}'`;
centos=`cat /etc/redhat-release | awk '{print $4}'`; sversion=`uname -a | awk '{print $3}'`; dversion=`dbus-daemon --version |head -1 | awk '{print $NF}'`; s3=`rpm -qa |fgrep systemd-sysv`;
echo -e "$m\t$centos\t$sversion\t$dversion\t$s3";
echo "====="
0