moved hdd stuff to hdd.sh, added top info

This commit is contained in:
mrbesen 2019-07-07 11:00:39 +02:00
parent d5657eb1f8
commit 04688e5b8a
6 changed files with 21 additions and 10 deletions

10
bot.sh
View File

@ -10,10 +10,12 @@ pwd
. func.sh . func.sh
#hdd usage #hdd usage
used=$(df --output=pcent $hdd | tail -1 | grep -Po "(\\d+)" --color=never) . hdd.sh
used=$(hddUsage)
if [ "$used" -gt "$hddlimit" ]; then if [ "$used" -gt "$hddlimit" ]; then
echo "warn!" echo "warn!"
send "warnung%20server%20used%20$used%25%20of%20the%20storage!" hddTop=$(hddTop)
send "warnung server used $used% of the storage $hddTop"
fi fi
#services #services
@ -29,7 +31,7 @@ fi
cpu=$(cpuUsage) cpu=$(cpuUsage)
if [ "$cpu" -gt "$cpulimit" ]; then if [ "$cpu" -gt "$cpulimit" ]; then
echo "cpu limit!" echo "cpu limit!"
proc=$(cpuHighest) proc=$(cpuTop)
send "warnung%20CPU%20Usage%20is%20high%20$cpu%25%0A$proc" send "warnung%20CPU%20Usage%20is%20high%20$cpu%25%0A$proc"
fi fi
@ -38,7 +40,7 @@ fi
mem=$(memUsage) mem=$(memUsage)
if [ "$mem" -gt "$memlimit" ]; then if [ "$mem" -gt "$memlimit" ]; then
echo "mem limit!" echo "mem limit!"
proc=$(memHighest) proc=$(memTop)
send "warnung%20Memory%20Usage%20is%20high%20$mem%25%0A$proc" send "warnung%20Memory%20Usage%20is%20high%20$mem%25%0A$proc"
fi fi

View File

@ -2,8 +2,9 @@
function checkCert { function checkCert {
valid=$(openssl x509 -enddate -noout -in "$1" | cut -b 10-) valid=$(openssl x509 -enddate -noout -in "$1" | cut -b 10-)
valids=$(date -d "${valid}" +%s) valids=$(date -d "${valid}" +%s)
limit=$(date -d "-${certlimit}" +%s) limit=$(date -d "+${certlimit}" +%s)
#echo "valid $valid, valids: ${valids}, limit: $limit, certlimit: $certlimit"
if [ "${valids}" -lt "${limit}" ]; then if [ "${valids}" -lt "${limit}" ]; then
return 1 return 1
fi fi

4
cpu.sh
View File

@ -4,6 +4,6 @@ function cpuUsage {
ps -A -o pcpu | tail -n+2 | paste -sd+ | bc | awk '{print int($1)}' ps -A -o pcpu | tail -n+2 | paste -sd+ | bc | awk '{print int($1)}'
} }
function cpuHighest { function cpuTop {
ps -eo pid,cmd,%cpu --sort=-%cpu | head -2 | tail -n 1 ps -eo pid,cmd,%cpu --sort=-%cpu | head -2 | tail -n 1 | sed 's: :%20:g; s:/:%2F:g'
} }

View File

@ -2,5 +2,5 @@
#1. arg = text #1. arg = text
send() { send() {
echo "Sending $1 to ${userid}" echo "Sending $1 to ${userid}"
curl -s "https://api.telegram.org/bot${token}/sendMessage?chat_id=${userid}&text=$1" > /dev/null curl --data "chat_id=${userid}&text=$1" -s "https://api.telegram.org/bot${token}/sendMessage" > /dev/null
} }

8
hdd.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
function hddUsage {
df --output=pcent $hdd | tail -1 | grep -Po "(\\d+)" --color=never
}
function hddTop {
du -hd 3 / --exclude="/proc" | sort -hr | grep -E "/.*/.*/" | head -n 3 | sed -e 's/\t/%20/g; s:/:%2F:g; a%0A' | sed -e '1i \%0A' | tr -d '\n'
}

4
mem.sh
View File

@ -3,6 +3,6 @@ function memUsage {
top -bn1 | sed -n 4p | awk '{ print int( $6 / $4 * 100) }' top -bn1 | sed -n 4p | awk '{ print int( $6 / $4 * 100) }'
} }
function memHighest { function memTop {
ps -eo pid,cmd,%mem --sort=-%mem | head -2 | tail -n 1 ps -eo pid,cmd,%mem --sort=-%mem | head -2 | tail -n 1 | sed 's: :%20:g; s:/:%2F:g'
} }