Linux 分析操作系统负载

阅读更多
一 CPU负载概念

Linux 分析操作系统负载_第1张图片
 


 
 
二 CPU负载脚本
1 #############################################################
2 # File Name: system_monitor.sh
3 # Author:cakin
5 # Created Time: Sat 12 Aug 2017 10:17:13 AM CST
6 #==============================================
7 #!/bin/bash
8 clear
9 if [[ $# -eq 0 ]]
10 then
11 rest_ternimal=$(tput sgr0)
12
13 #check os type
14 os=$(uname -o)
15 echo -e '\E[32m'"Operating System Type:" $rest_ternimal $os
16 #check os release version and name
17 os_name=$(cat /etc/issue|grep -e "Server")
18 echo -e '\E[32m'"os release version and name:" $rest_ternimal $os_name
19 #check architecture
20 architecture=$(uname -m)
21 echo -e '\E[32m'"architecture:" $rest_ternimal $architecture
22 #check kernel release
23 kernerrelease=$(uname -r)
24 echo -e '\E[32m'"kernel release:" $rest_ternimal $kernerrelease
25 #check hostname $HOSTNAME
26 hostname=$(uname -n)
27 echo -e '\E[32m'"hostname:" $rest_ternimal $hostname
28 #check internal IP
29 internalip=$(hostname -I)
30 echo -e '\E[32m'"internal IP:" $rest_ternimal $internalip
31 #check external IP
32 externalip=$(curl -s http://ipecho.net/plain)
33 echo -e '\E[32m'"external IP:" $rest_ternimal $externalip
34 #check DNS
35 nameservers=$(cat /etc/resolv.conf |grep -E "\
36 echo -e '\E[32m'"DNS:" $rest_ternimal $nameservers
37 #check if connected to Internet or not
38 ping -c 2 imooc.com &>/dev/null && echo "Internet:Connected" || echo "Internet:Disconnected"
39 #check Logged in users
40 who>/tmp/who
41 echo -e '\E[32m' "Logged in users" $rest_ternimal && cat /tmp/who
42 rm -rf /tmp/who
43 ####################################################
44 system_mem_usages=$(awk '/MemTotal/{total=$2}/MemFree/{free=$2}END{print (total-free)/1024}' /proc/meminfo)
45 echo -e '\E[32m'"system memuserages:" $rest_ternimal $system_mem_usages
46 app_mem_usages=$(awk '/MemTotal/{total=$2}/MemFree/{free=$2}/^Cached/{cached=$2}/Buffers/{buffers=$2}END{print (total-free-ca ched-buffers)/1024}' /proc/meminfo)
47 echo -e '\E[32m'"apps memuserage:" $rest_ternimal $app_mem_usages
48 loadaverage=$(top -n 1 -b|grep "load average:"|awk '{print $10 $11 $12}')
49 echo -e '\E[32m'"load averages:" $rest_ternimal $loadaverage
50 fi
 
三 运行结果


Linux 分析操作系统负载_第2张图片
 
  • Linux 分析操作系统负载_第3张图片
  • 大小: 90.2 KB
  • Linux 分析操作系统负载_第4张图片
  • 大小: 63.9 KB
  • Linux 分析操作系统负载_第5张图片
  • 大小: 30.4 KB
  • 查看图片附件

你可能感兴趣的:(Linux,操作系统,负载)