dot

packages and services management
Log | Files | Refs | README

commit 24f0c1e45971dba6031371b636c3bd65c2da5fa5
parent cf49f02b9638b5b16fd22f746ba56b11f056aabd
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Fri, 28 Jul 2017 19:54:54 +0200

monitor: moved from bin and added a start script

Diffstat:
MSERVICE | 2+-
Dbin/monitor | 92-------------------------------------------------------------------------------
Amonitor/bin/monitor | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amonitor/start | 1+
4 files changed, 94 insertions(+), 93 deletions(-)

diff --git a/SERVICE b/SERVICE @@ -38,7 +38,7 @@ do if [ "$cmd" = stop ] || [ "$cmd" = restart ] then - kill -s QUIT "$pid" && + kill "$pid" && printf '%-15s [stopped] %s\n' "$srv" "$cmdline" else run=1 diff --git a/bin/monitor b/bin/monitor @@ -1,92 +0,0 @@ -# ressources monitoring script - -# It will produce one line with the following values, separated with a space: -# -# 1. hostname 5. load average (1 minute) -# 2. unix time 6. disk I/O -# 3. free memory 7. total free storage -# 4. cpu usage - -VAR="${VAR:-$HOME/var}" - - -# --- record ------------------------------------------------------------------- - -mkdir -p "$VAR/stat" - -case "$(uname)" in -(Linux ) mem=free cpu=id bi=bi bo=bo b='' ;; -(*BSD ) mem=fre cpu=id bi='' bo='' b="$disks" ;; -(Solaris) mem=free cpu=id bi='' bo='' b="$disks" ;; -esac - -[ $# = 2 ] && [ "$1" = -d ] && while : -do vmstat "$2" 2 | -awk -v mem="$mem" -v cpu="$cpu" -v bi="$bi" -v bo="$bo" ' - -BEGIN { - "date +%s" | getline date - "hostname" | getline host - "uptime" | getline load - - sub(/.* /, "", load) - - while ("df" | getline) - if ($1 ~ "^/dev/" || $1 == "zroot") stor += $4 -} - -NR == 2 { - split($0, keys) - - for (key in keys) - if (keys[key] ~ /0$/) disks[i++] = keys[key] -} - -NR >= 4 { - for (i = 1 + split($0, values); i > 0; i--) - table[keys[i]] = values[i] - - mem = table[mem] - cpu = 100 - table[cpu] - load = load - diskio = table[bi] + table[bo] - - for (disk in disks) - diskio += table[disks[disk]] - - print host " " date " " mem " " cpu " " load " " diskio " " stor -}' >> "$VAR/stat/now" -done - - -# --- results ------------------------------------------------------------------ - -[ $# = 1 ] && [ "$1" = -p ] || exit 0 - -while read -r host date mem cpu load diskio stor -do - memv="$memv $mem" - cpuv="$cpuv $cpu" - loadv="$loadv $load" - diskiov="$diskiov $diskio" - storv="$storv $stor" -done <<EOF -$(tail -n 80 "$VAR/stat/now") -EOF - -o() { printf '\n\n[ %s ]\n\n' "$*"; } - -o memory - printf %s "$memv" | plot -h 30 - -o cpu - printf %s "$cpuv" | plot -h 30 - -o load - printf %s "$loadv" | plot -h 30 - -o diskio - printf %s "$diskiov" | plot -h 30 - -o stor - printf %s "$storv" | plot -h 30 diff --git a/monitor/bin/monitor b/monitor/bin/monitor @@ -0,0 +1,92 @@ +# ressources monitoring script + +# It will produce one line with the following values, separated with a space: +# +# 1. hostname 5. load average (1 minute) +# 2. unix time 6. disk I/O +# 3. free memory 7. total free storage +# 4. cpu usage + +VAR="${VAR:-$HOME/var}" + + +# --- record ------------------------------------------------------------------- + +mkdir -p "$VAR/stat" + +case "$(uname)" in +(Linux ) mem=free cpu=id bi=bi bo=bo b='' ;; +(*BSD ) mem=fre cpu=id bi='' bo='' b="$disks" ;; +(Solaris) mem=free cpu=id bi='' bo='' b="$disks" ;; +esac + +vmstat "$1" 2 | +awk -v mem="$mem" -v cpu="$cpu" -v bi="$bi" -v bo="$bo" ' + +BEGIN { + "date +%s" | getline date + "hostname" | getline host + "uptime" | getline load + + sub(/.* /, "", load) + + while ("df" | getline) + if ($1 ~ "^/dev/" || $1 == "zroot") stor += $4 +} + +NR == 2 { + split($0, keys) + + for (key in keys) + if (keys[key] ~ /0$/) disks[i++] = keys[key] +} + +NR >= 4 { + for (i = 1 + split($0, values); i > 0; i--) + table[keys[i]] = values[i] + + mem = table[mem] + cpu = 100 - table[cpu] + load = load + diskio = table[bi] + table[bo] + + for (disk in disks) + diskio += table[disks[disk]] + + print host " " date " " mem " " cpu " " load " " diskio " " stor +}' >> "$VAR/stat/now" + + +# --- plot the results --------------------------------------------------------- + +while read -r host date mem cpu load diskio stor +do + memv="$memv $mem" + cpuv="$cpuv $cpu" + loadv="$loadv $load" + diskiov="$diskiov $diskio" + storv="$storv $stor" +done <<EOF +$(tail -n 80 "$VAR/stat/now") +EOF + +o() { printf '\n\n[ %s ]\n\n' "$*"; } +{ + o free memory + printf %s "$memv" | plot -h 30 + + o cpu usage + printf %s "$cpuv" | plot -h 30 + + o 15mn load average + printf %s "$loadv" | plot -h 30 + + o disk i/o + printf %s "$diskiov" | plot -h 30 + + o storage + printf %s "$storv" | plot -h 30 + +} > "$VAR/stat/graph" + +exec "$0" diff --git a/monitor/start b/monitor/start @@ -0,0 +1 @@ +exec monitor -d $((60 * 15)) & PID=$!