dot

packages and services management
Log | Files | Refs | README

commit b337b72dfa293dc9c40a67ed2559e719d2bc496f
parent 85bd44eb240f03448d28cdc617a23b55e1d0df33
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Sun,  6 Aug 2017 00:30:12 +0200

monitor/bin/*: split monitor in 2 half and handle skipped data

Diffstat:
Mmonitor/bin/monitor | 97++++++-------------------------------------------------------------------------
Amonitor/bin/monitor-plot | 44++++++++++++++++++++++++++++++++++++++++++++
Amonitor/bin/monitor-send | 0
Amonitor/bin/monitor-step | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mmonitor/start | 2+-
5 files changed, 102 insertions(+), 91 deletions(-)

diff --git a/monitor/bin/monitor b/monitor/bin/monitor @@ -1,94 +1,11 @@ -# 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 ------------------------------------------------------------------- +VAR=${VAR:-$HOME/var} +STEP="${1:-900}" 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:-$((60 * 15))}" 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/data" - - -# --- plot the results --------------------------------------------------------- - -while read -r host date mem cpu load diskio stor +while true do - memv="$memv $mem" - cpuv="$cpuv $cpu" - loadv="$loadv $load" - diskiov="$diskiov $diskio" - storv="$storv $stor" -done <<EOF -$(tail -n 80 "$VAR/stat/data") -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 - - printf '\n\n\t' - date -} > "$VAR/stat/graph" - -exec "$0" "$@" + monitor-step "$STEP" >> "$VAR/stat/data" + tail -n 100 "$VAR/stat/data" | + monitor-plot "$STEP" > "$VAR/stat/graph" +done diff --git a/monitor/bin/monitor-plot b/monitor/bin/monitor-plot @@ -0,0 +1,44 @@ +# read the data from "$VAR/stat/data" and fills missing entries with "?" + +awk -v STEP="${1:?Usage: ${0##*/} step}" ' + +BEGIN { + fields[2] = "time" + fields[3] = "mem" + fields[4] = "cpu" + fields[5] = "load" + fields[6] = "diskio" + fields[7] = "storage" +} + +{ + nfields = split($0, line, " ") + + for (i = 1; i <= nfields; i++) + data[i"]["NR] = line[i] +} + +END { + for (i = 1; i <= NR; i++) + start += data[2"]["i] % STEP + start = start / NR + int(data[2"]["1] / STEP) * STEP + + for (i = 3; i <= nfields; i++) { + offset = start + printf "%s", fields[i] + for (j = 1; j <= NR; j++) { + while (data[2"]["j] > offset) { + printf " ?" + offset += STEP + } + offset += STEP + printf " %s", data[i"]["j] + } + print "" + } +}' | while read field line +do + printf '\n[ %s ] \n\n' "$field" + printf %s "$line" | plot -h 30 + printf '\n' +done diff --git a/monitor/bin/monitor-send b/monitor/bin/monitor-send diff --git a/monitor/bin/monitor-step b/monitor/bin/monitor-step @@ -0,0 +1,50 @@ +# 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 + +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:-15}" 2 | +awk -v mem="$mem" -v cpu="$cpu" -v bi="$bi" -v bo="$bo" ' + +BEGIN { + "date +%s" | getline time + "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 " " time " " mem " " cpu " " load " " diskio " " stor +}' diff --git a/monitor/start b/monitor/start @@ -1 +1 @@ -exec monitor $((60 * 15)) & PID=$! +monitor "$1" & PID=$!