-
Notifications
You must be signed in to change notification settings - Fork 4
/
system.bash
executable file
·58 lines (52 loc) · 2.02 KB
/
system.bash
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
#!/bin/bash
# script to retrieve relevant system performance details not available in the conky api
# data is placed in files for conky to read
. ~/conky/monochrome/logging.bash
function renameTempFile {
for f in "$@"
do [[ -f ${f}.$$ ]] && mv ${f}.$$ ${f}
done
}
OUTDIR=/tmp/conky
TMPFILE=${OUTDIR}/system.$$
SWAPREADFILE=${OUTDIR}/system.swap.read
SWAPWRITEFILE=${OUTDIR}/system.swap.write
CPUUSFILE=${OUTDIR}/system.cpu.us
CPUSYFILE=${OUTDIR}/system.cpu.sy
CPUIDFILE=${OUTDIR}/system.cpu.id
CPUWAFILE=${OUTDIR}/system.cpu.wa
trap 'log "received shutdown signal, deleting output files"; rm ${OUTDIR}/system.*; exit 0' EXIT
log 'compiling system performance metrics'
echo 'n/a' > ${SWAPREADFILE}
echo 'n/a' > ${SWAPWRITEFILE}
type -p vmstat > /dev/null || { logError "'vmstat' utility is not installed, swap metrics will be unavailable"; exit 1; }
while true; do
# ::::::::::: swap i/o
# $ vmstat --no-first
# procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
# r b swpd free buff cache si so bi bo in cs us sy id wa st
# 1 0 3314100 363380 30040 607636 4 0 132 48 2013 3409 3 1 96 0 0
vmstat --no-first --unit K | tail -1 > ${TMPFILE}
awk '{
if ($7 < 1000)
{VALUE = $7; UNIT = "KiB"; FORMAT = "%d%s"}
else
{VALUE = $7/1024; UNIT = "MiB"; FORMAT = "%3.1f%s"}
}
END {printf FORMAT, VALUE, UNIT}' ${TMPFILE} > ${SWAPREADFILE}.$$
awk '{
if ($8 < 1000)
{VALUE = $8; UNIT = "KiB"; FORMAT = "%d%s"}
else
{VALUE = $8/1024; UNIT = "MiB"; FORMAT = "%3.1f%s"}
}
END {printf FORMAT, VALUE, UNIT}' ${TMPFILE} > ${SWAPWRITEFILE}.$$
# ::::::::::: cpu
awk '{print $13}' ${TMPFILE} > ${CPUUSFILE}.$$
awk '{print $14}' ${TMPFILE} > ${CPUSYFILE}.$$
awk '{print $15}' ${TMPFILE} > ${CPUIDFILE}.$$
awk '{print $16}' ${TMPFILE} > ${CPUWAFILE}.$$
renameTempFile ${SWAPREADFILE} ${SWAPWRITEFILE} ${CPUUSFILE} ${CPUSYFILE} ${CPUIDFILE} ${CPUWAFILE}
sleep 1 &
wait
done