dot

packages and services management
Log | Files | Refs | README

commit 75b2309f5d475292135673e90004048c1bbc6d78
parent db5bc456f0a79e89c9c84525e1a8700af5fcd0d4
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Wed, 26 Jul 2017 09:46:22 +0200

bin/monitor: succesfully plotted the values

Diffstat:
Mbin/monitor | 41++++++++++++++++++++++++++++++++++++++---
Mbin/plot | 7++++---
2 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/bin/monitor b/bin/monitor @@ -3,12 +3,15 @@ # It will produce one line with the following values, separated with a space: # # 1. hostname 5. load average (1 minute) -# 2. date-time 6. disk I/O +# 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 @@ -17,7 +20,8 @@ case "$(uname)" in (Solaris) mem=free cpu=id bi='' bo='' b="$disks" ;; esac -vmstat 2 2 | awk -v mem="$mem" -v cpu="$cpu" -v bi="$bi" -v bo="$bo" ' +[ $# = 0 ] && +vmstat 1 2 | awk -v mem="$mem" -v cpu="$cpu" -v bi="$bi" -v bo="$bo" ' BEGIN { "date +%s" | getline date @@ -44,7 +48,7 @@ NR >= 4 { mem = table[mem] cpu = 100 - table[cpu] - load = load * 100 + load = load diskio = table[bi] + table[bo] for (disk in disks) @@ -52,3 +56,34 @@ NR >= 4 { print host " " date " " mem " " cpu " " load " " diskio " " stor }' >> "$VAR/stat/now" + + +# --- 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 < "$VAR/stat/now" + +p() { printf '\n\n[ %s ]\n\n' "$*"; } + +p 'memory' +printf %s "$memv" | plot -y $((1 << 17)) + +p 'cpu' +printf %s "$cpuv" | plot -y 5 + +p 'load' +printf %s "$loadv" | plot -y 0.1 + +p 'diskio' +printf %s "$diskiov" | plot -y 256 + +p 'stor' +printf %s "$storv" | plot -y 30000 diff --git a/bin/plot b/bin/plot @@ -27,11 +27,12 @@ BEGIN { } # draw the grid + margin = length(max) > 10 ? length(max) : 10 for (y = maxy + maxy % 2; y >= 1; y -= 2) { if (y % 4) - printf "%" length(max) "s |", "" + printf "%" margin "s |", "" else - printf "%" length(max) "d -|", (y - 1) * stepy + printf "%" margin "d -|", (y - 1) * stepy for (x = 1; x <= maxx; x++) printf "%s", (dots[x] >= y ? ":" : \ @@ -41,7 +42,7 @@ BEGIN { } # draw 'x' axis - printf "%" length(max) "s0 +", "" + printf "%" margin "s0 +", "" for (x = 1; x <= maxx; x++) printf "-" print "+ " maxx * stepx