Compare commits

...

2 Commits

Author SHA1 Message Date
mischa
5795cb8879 add a CPU load tracker 2024-05-14 18:20:00 +02:00
mischa
4e9862efc2 make notify flexible with vm name it gets presented 2024-05-14 18:19:35 +02:00
2 changed files with 76 additions and 4 deletions

72
cpu.sh Executable file
View File

@ -0,0 +1,72 @@
#!/bin/sh
#
# Copyright (c) 2024 Mischa Peters <mischa @ openbsd.amsterdam>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
THRESHOLD=90
TTL=10
GRACE=6
#ps -uU _vmd | awk -v var="${THRESHOLD}" '$12 !~ /\// && $3 > var {print $12,$3}'
#
HOSTNAME=$(hostname)
TIMESTAMP=$(date +%s)
SEEN=$(ls -1 /tmp/vm* | awk -F'/' '{print $3}')
OUT=$(ps -uU _vmd | awk -v var="${THRESHOLD}" '$12 !~ /\// && $3 > var {print $12}')
if [ -z "$OUT" ]; then
echo "No VM over the threshold overload"
rm -rf /tmp/vm*
fi
for VM in ${OUT}; do
echo -n "${VM}"
if [ ! -f /home/mischa/vms/${VM}.exclude ]; then
if [ -f /tmp/${VM} ]; then
FIRSTSEEN=$(awk 'NR==1' /tmp/${VM})
LASTSEEN=$(awk 'NR==2' /tmp/${VM})
echo -n " - ${FIRSTSEEN}"
echo -n ", $((${TIMESTAMP} - ${FIRSTSEEN}))"
echo -n ", ${LASTSEEN}"
echo -n ", $((${TIMESTAMP} - ${LASTSEEN}))"
if [[ $(( ${TIMESTAMP} - ${LASTSEEN} )) -gt $(( 60 * ${TTL} )) ]]; then
echo -n ", TTL"
echo ${FIRSTSEEN} > /tmp/${VM}
echo ${TIMESTAMP} >> /tmp/${VM}
fi
if [[ $(( ${TIMESTAMP} - ${FIRSTSEEN} )) -gt $(( 60 * 60 * ${GRACE} )) ]]; then
if [[ $(( ${TIMESTAMP} - ${LASTSEEN} )) -gt $(( 60 * ${TTL} )) ]]; then
echo -n ", GRACE DONE"
echo
echo "notify!"
/home/mischa/bin/notify.pl cpu ${VM}
echo "${VM} over ${THRESHOLD}% CPU load for ${GRACE} hours" | mail -s "${HOSTNAME} - ${VM} over ${THRESHOLD}% CPU load for ${GRACE} hours" -r mischa@high5.nl mischa@high5.nl
rm -rf /tmp/${VM}
fi
fi
echo
else
echo " - firstseen"
echo ${TIMESTAMP} > /tmp/${VM}
echo ${TIMESTAMP} >> /tmp/${VM}
fi
fi
done
for s in ${SEEN[@]}; do
if [[ "${OUT[*]}" != *"${s}"* ]]; then
echo "${s} - remove from tracking list"
rm -rf /tmp/${s}
fi
done

View File

@ -142,10 +142,10 @@ sub mailout {
$paypal_url = "SPONSORED";
}
if ($_donated !~ m/renewal/) {
print "renewal not set\n";
next;
}
#if ($_donated !~ m/renewal/) {
#print "renewal not set\n";
#next;
#}
my $stripe = $stripe_urls{$_payment} || '';
my $ideal = $ideal_url || "https://bunq.me/openbsdams/${_payment}/${_instance}%20$conf{'conf'}{'SERVER'}";