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

View File

@ -2,8 +2,9 @@
function checkCert {
valid=$(openssl x509 -enddate -noout -in "$1" | cut -b 10-)
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
return 1
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)}'
}
function cpuHighest {
ps -eo pid,cmd,%cpu --sort=-%cpu | head -2 | tail -n 1
function cpuTop {
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
send() {
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) }'
}
function memHighest {
ps -eo pid,cmd,%mem --sort=-%mem | head -2 | tail -n 1
function memTop {
ps -eo pid,cmd,%mem --sort=-%mem | head -2 | tail -n 1 | sed 's: :%20:g; s:/:%2F:g'
}