-
Notifications
You must be signed in to change notification settings - Fork 1
/
dwmstatusbar
executable file
·68 lines (53 loc) · 1.84 KB
/
dwmstatusbar
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
#!/bin/bash
INTERVAL=1 # refresh interval [s]
NETWORK_INTERFACES="enp0s31f6" # separated by spaces
DL=" | " # delimiter
print_memfree() {
memfree=$(($(grep -m1 'MemAvailable:' /proc/meminfo | awk '{print $2}') / 1024))"M"
echo -e "MEM $memfree"
}
print_date() {
date "+%a %m-%d %T"
}
print_mem_killer() {
cpu_killer=$(basename $(ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -1|awk '{print $5}'))
echo -e $cpu_killer
}
print_cpu_killer() {
cpu_killer=$(basename $(ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 2 -nr | head -1|awk '{print $5}'))
echo -e $cpu_killer
}
print_volume() {
VOL=$(amixer get Master | tail -1 | sed 's/.*\[\([0-9]*%\)\].*/\1/')
echo $VOL
}
print_main_fs_usage() {
FS_USAGE=$(df |grep /$ | awk '{print $5}')
echo -e "/ $FS_USAGE"
}
print_data_fs_usage() {
FS_USAGE=$(df |grep /data$ | awk '{print $5}')
echo -e "/data $FS_USAGE"
}
tx_old=0
rx_old=0
# setopt shwordsplit
for NETWORK_INTERFACE in ${NETWORK_INTERFACES}; do
tx_old=$(cat /sys/class/net/${NETWORK_INTERFACE}/statistics/tx_bytes)
rx_old=$(cat /sys/class/net/${NETWORK_INTERFACE}/statistics/rx_bytes)
done
# unsetopt shwordsplit
while true; do
rx_now=0
tx_now=0
for NETWORK_INTERFACE in ${NETWORK_INTERFACES}; do
tx_now=$(($rx_now + $(cat /sys/class/net/${NETWORK_INTERFACE}/statistics/tx_bytes)))
rx_now=$(($rx_now + $(cat /sys/class/net/${NETWORK_INTERFACE}/statistics/rx_bytes)))
done
let rx_rate=($rx_now-$rx_old)/1024/$INTERVAL
let tx_rate=($tx_now-$tx_old)/1024/$INTERVAL
xsetroot -name "MEM† $(print_mem_killer)${DL}CPU† $(print_cpu_killer)${DL}V $(print_volume)${DL}RX $rx_rate kb/s${DL}TX $tx_rate kb/s${DL}$(print_memfree)${DL}$(print_main_fs_usage)${DL}$(print_data_fs_usage)${DL}$(print_date)"
sleep $INTERVAL
tx_old=$tx_now
rx_old=$rx_now
done