CPU 內(nèi)存檢查小腳本
#!/bin/bash
function echo_red () {
local what=$*
echo -e "\e[1;31m${what}\e[0m"
}
function echo_green () {
local what=$*
echo -e "\e[1;32m${what}\e[0m"
}
cpu_used=`vmstat | awk 'NR==3{print (100-$(NF-2))}'`
cpu_average=`uptime | awk '{print $(NF-2),$(NF-1),$NF}'`
mem_used=`free -h |awk 'NR==2{print int(100-($NF/$2*100))}'`
echo "CPU利用率: $cpu_used%"
echo "CPU負(fù)載: $cpu_average"
echo "內(nèi)存利用率: $mem_used%"
echo "==========檢查結(jié)果=========="
if [ $cpu_used -ge 60 ]
then
echo_red "cpu利用率過大于60%,請(qǐng)檢查."
elif [ $mem_used -ge 80 ]
then
echo_red "內(nèi)存利用率過大于80%,請(qǐng)檢查."
else
echo_green "CPU和內(nèi)存使用率正常."
fi
#!/bin/bash
#!/usr/bin/env bash
# This script reproduces what the kubelet does
# to calculate memory.available relative to root cgroup.
# current memory usage
memory_capacity_in_kb=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}')
memory_capacity_in_bytes=$((memory_capacity_in_kb * 1024))
memory_usage_in_bytes=$(cat /sys/fs/cgroup/memory/memory.usage_in_bytes)
memory_total_inactive_file=$(cat /sys/fs/cgroup/memory/memory.stat | grep total_inactive_file | awk '{print $2}')
memory_working_set=${memory_usage_in_bytes}
if [ "$memory_working_set" -lt "$memory_total_inactive_file" ];
then
memory_working_set=0
else
memory_working_set=$((memory_usage_in_bytes - memory_total_inactive_file))
fi
memory_available_in_bytes=$((memory_capacity_in_bytes - memory_working_set))
memory_available_in_kb=$((memory_available_in_bytes / 1024))
memory_available_in_mb=$((memory_available_in_kb / 1024))
echo "memory.capacity_in_bytes $memory_capacity_in_bytes"
echo "memory.usage_in_bytes $memory_usage_in_bytes"
echo "memory.total_inactive_file $memory_total_inactive_file"
echo "memory.working_set $memory_working_set"
echo "memory.available_in_bytes $memory_available_in_bytes"
echo "memory.available_in_kb $memory_available_in_kb"
echo "memory.available_in_mb $memory_available_in_mb"
patch
#!/bin/bash
# 使用 kubectl 獲取所有命名空間中的暴露的服務(wù)及其命名空間
kubectl get expose -A | while read NAMESPACE NAME AGE; do
# 忽略標(biāo)題行
if [[ $NAMESPACE == "NAMESPACE" ]]; then continue; fi
# 打印當(dāng)前處理的服務(wù)信息
#echo "Patching service $NAME in namespace $NAMESPACE"
# 使用 kubectl patch 為服務(wù)添加 finalizers
kubectl patch expose $NAME -n $NAMESPACE -p '{"metadata":{"finalizers":["finalizers.jdos.io/expose"]}}' --type="merge"
done
打印主機(jī)信息
#!/usr/bin/env bash
#!/bin/bash
ip=`ifconfig eth0 | awk '/inet /{print $2}'`
echo "本地IP地址是:"$ip
cpu=`uptime | awk '{print $NF}'`
#awk中NF為當(dāng)前行的列數(shù),$NF是最后一列
echo "本機(jī)CPU最近15分鐘的負(fù)載是:"$cpu
net_in=`ifconfig eth0 | awk '/RX p/{print $5}'`
echo "入站網(wǎng)卡流量為:"$net_in
net_out=`ifconfig eth0 | awk '/TX p/{print $5}'`
echo "出站網(wǎng)卡流量為:"$net_out
mem=`free | awk '/Mem/{print $4}'`
echo "內(nèi)存剩余容量為:"$mem
disk=`df | awk '/\/$/{print $4}'`
echo "根分區(qū)剩余容量為:"$disk
user=`cat /etc/passwd |wc -l`
echo "本地賬戶數(shù)量為:"$user
login=`who | wc -l`
echo "當(dāng)前登陸計(jì)算機(jī)的賬戶數(shù)量為:"$login
process=`ps aux | wc -l`
echo "當(dāng)前計(jì)算機(jī)啟動(dòng)的進(jìn)程數(shù)量為:"$process
soft=`rpm -qa | wc -l`
echo "當(dāng)前計(jì)算機(jī)已安裝的軟件數(shù)量為:"$soft
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者