-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathsysmon
65 lines (43 loc) · 1.87 KB
/
sysmon
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
#!/bin/bash
#settings:
netspeed=true
ram=true
cpu=true
#-------------------------------------------------------
#---------------- initialize ---------------------------
rm /tmp/.sysmon > /dev/null 2>&1
dstat --net --mem --cpu --output=/tmp/.sysmon 1 1 > /dev/null 2>&1
#----------- up/down speed -----------------------------
if [ $netspeed = true ]; then
upspeed=$(echo $(cat /tmp/.sysmon | tail -1 | cut -d ',' -f2)/1024*8 | bc)
upkbmb=$(if [ $upspeed -gt 1024 ]; then
up1=$(echo $(cat /tmp/.sysmon | tail -1 | cut -d ',' -f2)/1024/1024 | bc -l)
echo $up1 | head -c 4
else
echo $upspeed | head -c 3
fi)
downspeed=$(echo $(cat /tmp/.sysmon | tail -1 | cut -d ',' -f1)/1024*8 | bc)
downkbmb=$(if [ $downspeed -gt 1024 ]; then
down1=$(echo $(cat /tmp/.sysmon | tail -1 | cut -d ',' -f1)/1024/1024*8 | bc -l)
echo $down1 | head -c 4
else
echo $downspeed | head -c 3
fi)
#---------------- up/down speed unit --------------------
upunit=$(if [ $upspeed -gt 1024 ]; then echo "Mb/s"; else echo "Kb/s"; fi)
downunit=$(if [ $downspeed -gt 1024 ]; then echo "Mb/s"; else echo "Kb/s"; fi)
fi
#------------------- CPU % used -------------------------
if [ $cpu = true ]; then
cpufree=$(cat /tmp/.sysmon | tail -1 | cut -d ',' -f9)
cpuused=$(echo 100-$cpufree | bc | sed -e 's/\..*//')
fi
#------------------- RAM % used --------------------------
if [ $ram = true ]; then
memused=$(free -m | grep buffers/cache | tr -s ' ' | cut -d' ' -f 3)
memfree=$(free -m | grep buffers/cache | tr -s ' ' | cut -d' ' -f 4)
memtotal=$(echo $memused+$memfree | bc -l)
memusedpercent=$(echo 100-100*$memfree/$memtotal | bc)
fi
#------------------ The Indicator Sysmonitor actual output -
echo $(if [ $ram = true ]; then echo Mem: $memusedpercent% \|; fi) $(if [ $cpu = true ]; then echo CPU: $cpuused% \|; fi) $(if [ $netspeed = true ]; then echo ↑ $upkbmb $upunit ↓ $downkbmb $downunit; fi)