-
Notifications
You must be signed in to change notification settings - Fork 22
/
cloudshell
executable file
·180 lines (146 loc) · 4.28 KB
/
cloudshell
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# Hardkernel CloudShell Screen update
#
# requires the following packages:
# curl sysstat
#
# Tested on Ubuntu 14.04 Server image
############## Configuration
# console font
# More fonts on: /usr/share/consolefonts
export TERM="linux"
export CONSOLE_FONT="Lat15-Fixed18"
# Output Console (ttyX)
export OUTPUT_CONSOLE="1"
# Network Interface: eth0, wlan0, ....
export NETIF="eth0"
# SATA HDD mount
export SATA="/dev/sda1"
# Screen refresh in seconds
export REFRESH="3"
# CPU Temperature in C or F
export TEMPERATURE_FORMAT="C"
# External IP Refresh counts
# The time to update the ip in counts is acquired by using the following formula
# seconds_to_refresh = EXT_IP_REFRESH * REFRESH
export EXT_IP_REFRESH="10"
get_external_ip() {
export EXTERNAL_IP=`/usr/bin/curl -s http://mdrjr.net/ip.php`
}
get_full_date() {
export DATE=`date +"%Y-%m-%d %H:%M:%S"`
}
get_hostname() {
export HOSTNAME=`hostname`
}
get_internal_ip() {
export INTERNAL_IP=`ifconfig $NETIF | grep 'inet addr:'| cut -d: -f2 | awk '{ print $1}'`
}
get_net_tx_rx_realtime() {
net_txrx=`sar -n DEV 1 1 | grep $NETIF | tail -n 1 | gawk '{print $5" "$6}'`
# in MB/s
_tx=`echo $net_txrx | awk '{printf $1}'`
_rx=`echo $net_txrx | awk '{printf $2}'`
export NET_TX=`echo "scale=1; x=$_tx/1024; if(x<1) print 0; x" | bc`
export NET_RX=`echo "scale=1; x=$_rx/1024; if(x<1) print 0; x" | bc`
}
get_disk_info() {
t=`df -h | grep $SATA`
export DISK_SIZE=`echo $t | awk '{printf $2}'`
export DISK_USED=`echo $t | awk '{printf $3}'`
export DISK_FREE=`echo $t | awk '{printf $4}'`
export DISK_USED_PCT=`echo $t | awk '{printf $5}'`
}
get_memory_info() {
# in Mbytes
export MEM_FREE=$[`cat /proc/meminfo | grep MemFree | awk '{print $2'}` / 1024]
export MEM_TOTAL=$[`cat /proc/meminfo | grep MemTotal | awk '{print $2'}` / 1024]
export MEM_USED=$[$MEM_TOTAL - $MEM_FREE]
}
get_cpu_usage() {
cpufree=`mpstat 1 1 | tail -n 1 | awk '{printf $12}'`
export CPU_USAGE=`echo "scale=1; x=100-$cpufree; if(x<1) print 0; x" | bc`
}
get_cpu_temperature() {
_t=$[`cat /sys/class/thermal/thermal_zone0/temp` / 1000]
if [ "$TEMPERATURE_FORMAT" = "C" ]; then
export CPU_TEMP="$_t"C
else
_t1=$[ $_t * 9 / 5 + 32 ]
export CPU_TEMP="$_t1"F
fi
}
get_samba_connections() {
if [ ! -f /usr/bin/smbstatus ]; then
export SAMBA_CONNECTIONS=0
else
export SAMBA_CONNECTIONS=`smbstatus -b | grep -c ipv`
fi
}
get_nfs_connections() {
export NFS_CONNECTIONS=`netstat -an | grep 2049 | grep -c ESTA`
}
get_process_count() {
export PROCESS_COUNT=`ps xa | wc -l`
}
# local variables
ext_ip_refresh_c=0
COFF=$(tput sgr0)
CGREEN=$(tput setaf 2)
CRED=$(tput setaf 1)
CBLUE=$(tput setaf 6)
oc="/dev/tty$OUTPUT_CONSOLE"
# font setup
setfont $CONSOLE_FONT > $oc
# Turn off the cursor
setterm -cursor off > $oc
# Ensure that we are in the right TTY
chvt $OUTPUT_CONSOLE
# infinite loop
while true; do
# Ensure that we are in the right TTY
chvt $OUTPUT_CONSOLE
# check if EXT_IP_REFRESH
if (( ($ext_ip_refresh_c % $EXT_IP_REFRESH) == 0 )); then
get_external_ip
fi
# increment $ext_ip_refresh_c
ext_ip_refresh_c=$[$ext_ip_refresh_c+1]
# get data
get_internal_ip
get_hostname
get_disk_info
get_full_date
get_net_tx_rx_realtime
get_memory_info
get_cpu_usage
get_cpu_temperature
get_samba_connections
get_nfs_connections
get_process_count
# clear the screen every loop
# we only wipe the screen when we are ready to write data to it
clear > $oc
# format the data on screen
echo "" > $oc
echo -e "$CBLUE $HOSTNAME $COFF: $DATE" > $oc
echo "" > $oc
# line CPU Usage
echo -e "CPU Usage: $CBLUE$CPU_USAGE%$COFF CPU Temp: $CBLUE$CPU_TEMP$COFF" > $oc
# Line Memory
echo -e "Memory Free: $CBLUE$MEM_FREE MB$COFF Used: $CBLUE$MEM_USED MB$COFF" > $oc
# Line IP Addresses
echo -e "IP: $CBLUE$INTERNAL_IP$COFF Rem: $CBLUE$EXTERNAL_IP$COFF" > $oc
# Line network usage
echo -e "TX: $CBLUE$NET_TX MB/s$COFF RX: $CBLUE$NET_RX MB/s$COFF" > $oc
# Line Disk Space
echo -e "Disk Used: $CBLUE$DISK_USED$COFF ($CBLUE$DISK_USED_PCT$COFF) Free: $CBLUE$DISK_FREE$COFF" > $oc
# Line Samba
echo -e "Samba Clients: $CBLUE$SAMBA_CONNECTIONS$COFF" > $oc
# line NFS
echo -e "NFS Connections: $CBLUE$NFS_CONNECTIONS$COFF" > $oc
# line Processes
echo -e "Processes Running: $CBLUE$PROCESS_COUNT$COFF" > $oc
# sleep
sleep $REFRESH
done