Browse Source

new: [vps,0km] add ``disk`` resource to ``vps stats`` and ``0km vps-stats``

pull/8/head
Valentin Lab 7 months ago
parent
commit
b87b36303d
  1. 61
      bin/0km
  2. 24
      bin/vps

61
bin/0km

@ -1421,7 +1421,7 @@ cmdline.spec::cmd:vps-stats:run() {
opts_rrdfetch+=(-e "$end")
fi
fi
local resources=(c.memory c.network load_avg)
local resources=(c.memory c.network load_avg disk)
if [ -n "${opt_resource}" ]; then
resources=(${opt_resource//,/ })
fi
@ -1768,6 +1768,65 @@ graph:def:load_avg() {
echo
}
graph:def:disk() {
local vps="$1" i="$2"
shift 2
local opts_rrdfetch=("$@")
rrd_vps_path="$VAR_DIR/rrd/$vps"
[ -f "$rrd_vps_path/$resource.rrd" ] || {
warn "No containers data yet for vps '$vps'... Ignoring"
return 0
}
gnuplot_line_config=(
"set term qt $i title \"$vps $resource\" replotonresize noraise"
"set title '$vps'"
"set xdata time"
"set timefmt '%s'"
"set ylabel '${resource//_/\\_} Usage'"
"set format y '%s'"
"set ytics format '%g GiB'"
"set mouse mouseformat 6"
"set yrange [0:*] "
"set border behind"
)
printf "%s\n" "${gnuplot_line_config[@]}"
first=1
for value in used:2 size:3; do
label="${value%:*}"
col_num="${value#*:}"
rrdfetch_cmd="'< rrdtool fetch \"$rrd_vps_path/$resource.rrd\""
rrdfetch_cmd+=" AVERAGE ${opts_rrdfetch[*]} | \\"$'\n'
rrdfetch_cmd+=" tail -n +2 | \\"$'\n'
rrdfetch_cmd+=" egrep -v \"^$\" | sed -r \"s/ -?nan/ -/g;s/^([0-9]+): /\\1 /g\"'"
rrdfetch_cmd_bash=$(eval echo "${rrdfetch_cmd}")
rrdfetch_cmd_bash=${rrdfetch_cmd_bash#< }
first_ts=
first_ts=$(eval "$rrdfetch_cmd_bash" | head -n 1 | cut -f 1 -d " ")
if [ -z "$first_ts" ]; then
warn "No data for $resource on vps $vps, skipping..."
continue
fi
last_ts=$(eval "$rrdfetch_cmd_bash" | tail -n 1 | cut -f 1 -d " ")
if [[ -z "$data_start_ts" ]] || [[ "$data_start_ts" > "$first_ts" ]]; then
data_start_ts="$first_ts"
fi
if [[ -z "$data_stop_ts" ]] || [[ "$data_stop_ts" < "$last_ts" ]]; then
data_stop_ts="$last_ts"
fi
if [ -n "$first" ]; then
first=
echo "plot \\"
else
echo ", \\"
fi
container="${container//\'/}"
container="${container//@/\\@}"
echo -n " ${rrdfetch_cmd} u 1:(\$${col_num}/(1024*1024)) w lines title '${label}'"
done
echo
}

24
bin/vps

@ -2205,7 +2205,7 @@ cmdline.spec::cmd:stats:run() {
return 1
esac
local resources=(c.{memory,network} load_avg)
local resources=(c.{memory,network} load_avg disk)
if [ -n "${opt_resource}" ]; then
resources=(${opt_resource//,/ })
fi
@ -2355,6 +2355,28 @@ stats:load_avg() {
esac
}
stats:disk() {
local format="$1"
local out
disk_used_size=$(df --output=used,size / | tail -n 1) || return 1
out=$(printf "%s " "" "$(date +%s)" "${disk_used_size// / }")
printf "%s\n" "$out" | rrd:update "" "disk|2:used:GAUGE:U:U,3:size:GAUGE:U:U" || {
return 1
}
case "${format:-p}" in
raw|r)
printf "%s\n" "$out" | cut -f 2-4 -d " "
;;
pretty|p)
{
echo "__used" "__size"
printf "%s\n" "$out" | cut -f 3-5 -d " " |
numfmt --field 1-2 --from-unit=1024 --to=iec-i --format=%8.1fB
} | col:normalize:size ++ | header:make
;;
esac
}
host:sys:load_avg() {
local uptime

Loading…
Cancel
Save