网站开发与系统开发,a站是啥,网络营销是什么课,网站开发如何让图片加载的更快功能#xff1a; 对Linux主机的物理资源消耗进行监测和统计#xff0c;对运行在本机上的服务进程进行监测和统计#xff0c;列出本机上的账户有效期 使用场景#xff1a; 在没有 Promethes、zabbix、夜莺等监控工具的条件下#xff0c;通过 crontab 排程应用本程序完成对主…功能 对Linux主机的物理资源消耗进行监测和统计对运行在本机上的服务进程进行监测和统计列出本机上的账户有效期 使用场景 在没有 Promethes、zabbix、夜莺等监控工具的条件下通过 crontab 排程应用本程序完成对主机上的关键信息的采集和输出一遍分析当前主机的物理资源与业务程序的运行状态。 ************************************************************************************************************** #!/bin/bash echo ################################################### README INFO ############################################################## echo ### Purpose: Carrying Out A Routine Inspection Monitoring the Program Running-Status and the Consumed Hardware Resource ### echo ### Made By: PomanTeng ### echo ### E-mail: denggongmengbogmail.com ### echo ### WeChat: 1807479153 ### echo ### Version Identification Number:V2.1.0 ### echo ### Procedure Identification Number:20230916 ### echo ##############################################################################################################################
# Check the current OS user
[[ $(id -u) -gt 0 ]] echo 请用root用户执行此脚本 exit 1
source /etc/profile
source ~/.bash_profile
echo echo -e 现在时刻 :\n \n $(date) echo
echo echo 当前OS及其依托的基础设备类型 : echo cat /etc/*release* | awk /release/ | uniq echo hostnamectl | awk /Chassis|Virtualization/ echo
# Defining the Manufacturer-Variables
manufacturer$(dmidecode -s system-manufacturer)
productName$(dmidecode -s system-product-name)
productSN$(dmidecode -s system-serial-number)
biosVendor$(dmidecode -s bios-vendor)
biosVersion$(dmidecode -s bios-version)
cpuSpecification$(dmidecode -s processor-version | uniq)
# Defining Variable sysversion sysversion$(cat /etc/*release* | grep release | uniq)
# Defining the Metric-Variables
cpuTop50$(ps -aux | head -n 1 | awk -F -v OFS {print $2,$3,$11} ; ps -aux | sort -k3nr | head -n 50 | awk -F -v OFS {print $2,$3,$11})
memTop50$(ps -aux | head -n 1 | awk -F -v OFS {print $2,$4,$11} ; ps -aux | sort -k4nr | head -n 50 | awk -F -v OFS {print $2,$4,$11})
cpuConsumedTotalps -aux | head -n 1 | awk -F {print $3} ; ps -aux | awk {sum$3}END{print sum}
rootUsed$(df | awk $NF/ {var$3}END{print var/1024/1024 GB})
rootRemain$(df | awk $NF/ {var$4}END{print var/1024/1024 GB})
rootPercent$(df | awk $NF/ {print $5})
dataUsed$(df | awk $NF/app {var$3}END{print var/1024/1024 GB})
dataRemain$(df | awk $NF/app {var$4}END{print var/1024/1024 GB})
dataPercent$(df | awk $NF/app {print $5})
bondRX$(ifconfig | grep -A 8 bond1 | grep RX packets)
bondTX$(ifconfig | grep -A 8 bond1 | grep TX packets)
sysLoad$(top | head -n 5)
vmstatLoad$(vmstat -wt)
memUsed$(free -h | awk -F {print $3} | awk -F NR2)
memRemain$(free -h | awk -F {print $7} | awk -F NR2)
swapUsed$(free -h | awk -F {print $3} | awk -F NR3)
swapRemain$(free -h | awk -F {print $4} | awk -F NR3)
localIP$(ip addr | awk /^[0-9]: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, \\1, g, $2)} | awk NR1) listeningPortProgram$(netstat -tlunp | awk -F NR 1 {next} {print $0})
portList$(netstat -tlunp -e | awk -F NR1 {next} {print $0} | awk -F {print $4} | awk -F : {print $NF}) netstat -tlunp -e | awk -F NR1 {next} {print $0} | awk -F {print $4} | awk -F : {print $NF} | awk -F NR1 {next} {print $0} ./portList.txt
# Defining the Function get_Port-Program to get the port and the corresponding program
get_Port_Program(){ cat ./portList.txt | while read lines do for var in $lines do echo Separator BEGIN echo -e Current Port is : $var echo -e PID and Program is : pwdx $(lsof -i:$var | awk /LISTEN?/ | awk -F {print $2} | uniq) echo Separator END done done
}
####################################################################################################################################################################################################
# Defining the Function excute_Main to get the Routine Inspection-Result
excute_Main(){ cat EOF
设备制造商: ${manufacturer}
设备供货型号: ${productName}
设备供货序列号: ${productSN}
BIOS制造商: ${biosVendor}
BIOS版本号: ${biosVersion}
板载CPU规格: ${cpuSpecification}
操作系统版本: ${sysversion}
当前主机的 Local IP: ${localIP}
CPU消耗总计: ${cpuConsumedTotal}
CPU消耗前50的程序: ${cpuTop50}
内存消耗前50的程序: ${memTop50}
内存消耗使用量: ${memUsed}
内存消耗剩余量: ${memRemain}
交换空间消耗使用量: ${swapUsed}
交换空间消耗剩余量: ${swapRemain}
根分区的使用量: ${rootUsed}
根分区的剩余量: ${rootRemain}
根分区的使用百分比: ${rootPercent}
数据分区的使用量: ${dataUsed}
数据分区的剩余量: ${dataRemain}
数据分区的使用百分比: ${dataPercent}
Bond接收的数据量: ${bondRX}
Bond发送的数据量: ${bondTX}
操作系统负载: ${sysLoad} Separator ${vmstatLoad}
正在监听的服务: ${listeningPortProgram}
EOF
}
#########################################################################################################################################
# Execute Functions
excute_Main rm -rf ./portList.txt
############################################################################################################################################
echo ***** 本机运行的业务程序 ***** echo echo -e ps -ef | grep tiance | grep -v grep | awk { for(i1; i7; i){ $i }; print NR $0 } echo
echo ***** 本机业务程序的端口状态 ***** echo echo -e $(ss -tlunp | grep tiance | grep -v grep | awk -F {print NR $5,$7}) echo ####################################################################################################################################################
echo ***** 系统用户失效日期 *****
echo
cat /etc/passwd | awk -F : {print $1} | while read line; do echo $line chage -l $line | grep Password expires --coloralways ;done
echo
exit