-
Notifications
You must be signed in to change notification settings - Fork 10
/
vdstat-en
86 lines (65 loc) · 3.71 KB
/
vdstat-en
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
if [ ! -f /bin/netstat ]; then
yum -y install net-tools >/dev/null 2>&1
sudo apt-get update >/dev/null 2>&1
sudo apt-get -y install net-tools >/dev/null 2>&1
fi
if [ ! -f /usr/bin/sar ]; then
yum -y install sysstat >/dev/null 2>&1
sudo apt-get update >/dev/null 2>&1
sudo apt-get -y install sysstat >/dev/null 2>&1
fi
if [ ! -f /usr/bin/bc ]; then
yum -y install bc >/dev/null 2>&1
sudo apt-get update >/dev/null 2>&1
sudo apt-get -y install bc >/dev/null 2>&1
fi
if [ ! -d /tmp ]; then
mkdir -p /tmp
fi
a=a
while [ $a = 'a' ]
do
CPUdangdung=`sar -u 1 1 | grep Average: | awk '{print $3}'`
block=`fdisk -l| grep I/O| awk '{print $7}'| head -1`
IOsar=`sar -b 1 1 | grep Average:`
bread_s=`echo "$IOsar" | awk '{print $5}'| tr . ' ' | awk '{print $1}'`; IOdangdung_doc=$((bread_s*block/1024/1024))
bwrtn_s=`echo "$IOsar" | awk '{print $6}'| tr . ' ' | awk '{print $1}'`; IOdangdung_ghi=$((bwrtn_s*block/1024/1024))
RAMsar=`sar -r 1 1 | grep Average:`
used=`echo "$RAMsar" | awk '{print $3}'| tr . ' ' | awk '{print $1}'`
buffer=`echo "$RAMsar" | awk '{print $5}'| tr . ' ' | awk '{print $1}'`
cached=`echo "$RAMsar" | awk '{print $6}'| tr . ' ' | awk '{print $1}'`
RAMdangdung=$(((used-buffer-cached)/1024))
BWsar="`sar -n DEV 1 1`"
bwnhanvao=$(echo "scale=3;(`echo "$BWsar"|grep Average:| grep -v "IFACE"| awk {'print $5'} |tr "\n" "+"`0)"| bc -q| awk '{printf "%.0f\n", $0}')
bwtruyendi=$(echo "scale=3;(`echo "$BWsar"|grep Average:| grep -v "IFACE"| awk {'print $6'} |tr "\n" "+"`0)"| bc -q| awk '{printf "%.0f\n", $0}')
netstat_an_grep_80=`netstat -an|grep :80`
netstat_an_grep_443=`netstat -an|grep :443`
netstat_an_grep_ESTA=`netstat -an | grep ESTA`
netstatport80="`echo "$netstat_an_grep_80" |awk '!/:8080/'|awk '!/:8081/' |awk '{print $5}'|cut -d":" -f1|sort|uniq -c|sort -rn | grep '\.'| grep -v "0.0.0.0"`"
netstatport443="`echo "$netstat_an_grep_443" |awk '{print $5}'|cut -d":" -f1|sort|uniq -c|sort -rn | grep '\.'| grep -v "0.0.0.0"|tr -s " "`"
port80truyvan=`netstat -n | grep :80 |awk '!/:8080/'|awk '!/:8081/'|wc -l`
port443truyvan=`netstat -n | grep :443 |wc -l`
port80numberip=`echo "$netstatport80"| wc -l`
port443numberip=`echo "$netstatport443"| wc -l`
port80thietlap=`echo "$netstat_an_grep_80"|awk '!/:8080/'|awk '!/:8081/'| grep ESTA| wc -l`
port443thietlap=`echo "$netstat_an_grep_443" | grep ESTA | wc -l`
#port80listip="`echo "$netstatport80" | head -24 |tr -s " "`"
#port443listip="`echo "$netstatport443" | head -24 |tr -s " "`"
#thietlaplistip="`echo "$netstat_an_grep_ESTA" |awk '{print $5}'|cut -d":" -f1|sort|uniq -c|sort -rn| grep '\.' | grep -v "0.0.0.0"|head -24|tr -s " "`"
listiphostname=`netstat -tn | awk '{print $5}' | sed -e 's/:.*//' | grep '\.'|xargs -i sh -c 'echo {} $(getent hosts {})' | awk '$1 == $2 {print $2, $3; next}; {print}' | sort | uniq -c | sort -nr | head -24`
column=`pr -mT --width=145 --page-width=145 <(echo "IP Address request much:"; echo "$listiphostname")`
date=`TZ=America/New_York date +"TIME:%HH%M-DATE:%d-%m-%Y"`
clear
echo '########### The server statistics table for SYSTEM ADMIN LINUX SERVER VO DUY DOT COM: ########### '$date' ###########
CPU usage: ~'$CPUdangdung'% RAM usage: ~'$RAMdangdung'MB IO usage: ~'$IOdangdung_doc'MB/s READ
~'$IOdangdung_ghi'MB/s WRITE
The total number of QUERIES to port 80 is: '$port80truyvan' (By '$port80numberip' IP Address request)
The total number of QUERIES to port 443 is: '$port443truyvan' (By '$port443numberip' IP Address request)
Total number of ESTABLISHED connections is: | Network Bandwidth:
Port 80: '$port80thietlap' connections | Incoming: '$bwnhanvao'KB/s
Port 443: '$port443thietlap' connections | Outgoing: '$bwtruyendi'KB/s
'"$column"'
Thank you for using!'
a=a;
done