added config, added cpu load warning

This commit is contained in:
mrbesen 2019-05-10 02:23:32 +02:00
parent 358017389e
commit 84dc50a90e
4 changed files with 33 additions and 6 deletions

14
bot.sh
View File

@ -1,19 +1,27 @@
#!/bin/bash
# the main bot script
. config.sh
. func.sh
#hdd usage
used=$(df --output=pcent /dev/sda3 | tail -1 | grep -Po "(\\d+)" --color=never)
if [ "$used" -gt 50 ]; then
used=$(df --output=pcent $hdd | tail -1 | grep -Po "(\\d+)" --color=never)
if [ "$used" -gt "$hddlimit" ]; then
echo "warn!"
send "warnung%20server%20used%20$used%25%20of%20the%20storage!"
fi
#services
. services.sh
notrunning=$(checkServices "nginx,mysql")
notrunning=$(checkServices "$services")
if [ "$notrunning" != "" ]; then
echo "Serive warn!"
send "warnung%20the%20following%20services%20are%20not%20running%20$notrunning"
fi
. cpu.sh
cpu=$(cpuUsage)
if [ "$cpu" -gt "$cpulimit" ]; then
echo "cpu limit!"
send "warnung%20CPU%20Usage%20is%20high%20$cpu"
fi

17
config.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
#services that should be running
services="nginx,mysql"
#cpu usage limit (not divided by core count)
cpulimit="150"
#telegram api-token
token="123456:ABCDEFGH"
#telegram user to notify
userid="123456"
#harddrive usage percentage
hddlimit="50"
#harddrive
hdd="/dev/sda1"

5
cpu.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
function cpuUsage {
ps -A -o pcpu | tail -n+2 | paste -sd+ | bc | awk '{print int($1)}'
}

View File

@ -1,7 +1,4 @@
#!/bin/bash
token="APItoken"
userid="usernameorid"
#1. arg = text
send() {
echo "Sending $1 to ${userid}"