一、 控制节点监测脚本
#! /bin/bash
#分界线函数
b (){
echo -e "\033[31m-------------------------------------\033[0m"
}
read -p "请输入需要检测的网卡名:" ma
while :
do
clear
ip=`ifconfig $ma | awk '/inet /{print $2}'`
echo "本地IP地址是:"$ip && b
cpu=`uptime | awk '{print $NF}'`
#awk中NF为当前行的列数,$NF是最后一列
echo "本机CPU最近15分钟的负载是:$cpu%" && b
net_in=`ifconfig $ma | awk '/RX p/{print $5}'`
echo "入站网卡流量为:"$net_in && b
net_out=`ifconfig $ma | awk '/TX p/{print $5}'`
echo "出站网卡流量为:"$net_out && b
mem=`free -h| awk '/Mem/{print $4}'`
echo "内存剩余容量为:"$mem && b
disk=`df -h| awk '/\/$/{print $4}'`
echo "根分区剩余容量为:"$disk && b
user=`cat /etc/passwd |wc -l`
echo "本地账户数量为:$user 个" && b
login=`who | wc -l`
echo "当前登陆计算机的账户数量为:$login 个" && b
process=`ps aux | wc -l`
echo "当前计算机启动的进程数量为:$process 个" && b
#soft=`rpm -qa | wc -l`
#echo "当前计算机已安装的软件数量为:$soft 个" && b
sleep 2
done
二、 计算节点监测脚本
#! /bin/bash
#分界线函数
b (){
echo -e "\033[31m-------------------------------------\033[0m"
sleep 1
}
#检查服务状态
echo "即将开始检查服务状态..."
sleep 3
for n in {chronyd,rabbitmq-server,libvirtd,openstack-nova-compute,neutron-linuxbridge-agent}
do
systemctl status $n &> /dev/null
if [ $? -eq 0 ];then
echo "$n is ok!" && b
else
echo "正在帮您重启$n服务..."
systemctl restart $n && echo "$n已被正常启动,正在检查下一项服务..." && b && continue || echo "$n服务不能正常启动,请排除故障后再次尝试!" && exit
fi
done
while :
do
clear
b="echo ---------------------------------------------------"
cpu=`uptime | awk '{print $NF}'`
$b
#awk中NF为当前行的列数,$NF是最后一列
echo "本机CPU最近15分钟的负载是:$cpu%"
$b
net_in=`ifconfig ens38 | awk '/RX p/{print $5}'`
echo "入站网卡流量为:$net_in KB"
$b
net_out=`ifconfig ens38 | awk '/TX p/{print $5}'`
echo "出站网卡流量为:$net_out KB"
$b
mem=`free -h| awk '/Mem/{print $4}'`
echo "内存剩余容量为:"$mem
$b
disk=`df -h| awk '/\/$/{print $4}'`
echo "根分区剩余容量为:"$disk
$b
echo "正在运行的实例有:"
virsh list |awk '{print $2}'
$b
sleep 1.5
done
三、 存储节点监测脚本
#! /bin/bash
#分界线函数
b (){
echo -e "\033[31m-------------------------------------\033[0m"
sleep 1
}
#检查服务状态
echo "即将开始检查服务状态..."
sleep 3
for n in {chronyd,rabbitmq-server,lvm2-lvmetad,openstack-cinder-volume}
do
systemctl status $n &> /dev/null
if [ $? -eq 0 ];then
echo "$n is ok!" && b
else
echo "正在帮您重启$n服务..."
systemctl restart $n && echo "$n已被正常启动,正在检查下一项服务..." && b && continue || echo "$n服务不能正常启动,请排除故障后再次尝试!" && exit
fi
done
while :
do
clear
b="echo ---------------------------------------------------"
cpu=`uptime | awk '{print $NF}'`
$b
#awk中NF为当前行的列数,$NF是最后一列
echo "本机CPU最近15分钟的负载是:$cpu%"
$b
net_in=`ifconfig ens37 | awk '/RX p/{print $5}'`
echo "入站网卡流量为:$net_in KB"
$b
net_out=`ifconfig ens37 | awk '/TX p/{print $5}'`
echo "出站网卡流量为:$net_out KB"
$b
mem=`free -h| awk '/Mem/{print $4}'`
echo "内存剩余容量为:"$mem
$b
total=$(co=`lsblk |awk '/sdb/{print $4}'` && echo ${co/G/})
all_cinder=0
for n in $(lsblk |awk '/cinder--volumes-volume/{si[$4]++}END{for(i in si){print i}}') #筛选出已使用磁盘列表
do
m=`echo ${n%G}` #m=`echo ${n/G/}`
let all_cinder+=$m
done
echo "已使用云磁盘:$all_cinder G"
disk=`expr $total - $all_cinder`
echo "云磁盘剩余容量为:$disk G"
$b
sleep 2
done