forked from mdrjr/cloudshell_lcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudshell
executable file
·186 lines (152 loc) · 4.63 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
181
182
183
184
185
186
#!/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 CONSOLE_FONT="lat9-16 -m 8859-2"
export LANG="en_US.UTF-8"
# Output Console
export OUTPUT_CONSOLE="tty1"
# Network Interface: eth0, wlan0, ....
export NETIF="eth0"
export TERM=linux
# SATA HDD mount
export SATA="/dev/sda1"
export SATA2="/dev/sdb1"
# Screen refresh in seconds
export REFRESH="1"
# 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="100"
get_external_ip() {
export EXTERNAL_IP=`curl http://ipecho.net/plain`; echo
}
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'| cut -d: -f2 | awk '{ print $2}'`
}
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=2; $_tx/1024" | bc | awk '{printf "%.2f", $0}'`
export NET_RX=`echo "scale=2; $_rx/1024" | bc | awk '{printf "%.2f", $0}' `
}
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}'`
t=`df -h | grep $SATA2`
export DISK_SIZE2=`echo $t | awk '{printf $2}'`
export DISK_USED2=`echo $t | awk '{printf $3}'`
export DISK_FREE2=`echo $t | awk '{printf $4}'`
export DISK_USED_PCT2=`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=2 ;100-$cpufree" | bc | awk '{printf "%.2f", $0}'`
}
get_cpu_speed() {
export CPU_SPEED=$[`cat /sys/devices/system/cpu/cpu4/cpufreq/scaling_cur_freq`/1000]
}
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() {
export SAMBA_CONNECTIONS=`smbstatus -b | grep -c ipv`
}
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/$OUTPUT_CONSOLE"
# font setup
setfont $CONSOLE_FONT
#disable kernel messages
dmesg -n 1
# disable console blanking
setterm -blank 0 -powersave off > $oc
# infinite loop
while true; do
# 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_speed
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
echo -e "CPU Speed: $CBLUE$CPU_SPEED Mhz$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 Disk1 Space
echo -e "HD1: $CBLUE$DISK_USED$COFF ($CBLUE$DISK_USED_PCT$COFF) Free: $CBLUE$DISK_FREE$COFF" > $oc
# Line Disk2 Space
echo -e "HD2: $CBLUE$DISK_USED2$COFF ($CBLUE$DISK_USED_PCT2$COFF) Free: $CBLUE$DISK_FREE2$COFF" > $oc
# Line Samba
echo -e "Samba Clients: $CBLUE$SAMBA_CONNECTIONS$COFF" > $oc
# line Processes
echo -e "Processes Running: $CBLUE$PROCESS_COUNT$COFF" > $oc
# sleep
sleep $REFRESH
done