russ fix
This commit is contained in:
@@ -2,17 +2,17 @@
|
|||||||
#This script monitors server load and memory usage for every 10 seconds and sends notification to telegram in case of high usage.
|
#This script monitors server load and memory usage for every 10 seconds and sends notification to telegram in case of high usage.
|
||||||
|
|
||||||
#Include telegram chat id and bot token ID here
|
#Include telegram chat id and bot token ID here
|
||||||
chat_id=""
|
chat_id="-4224655517"
|
||||||
token=""
|
token="6978729637:AAHTyZ6W4I7DxRVmf5K_Wc4nvIWfarZ7x_Y"
|
||||||
host=$HOSTNAME
|
host=$HOSTNAME
|
||||||
ip=($(hostname -I))
|
ip=($(hostname -I))
|
||||||
#Temporary files to store data
|
#Временные файлы для хранения данных
|
||||||
resource_usage_info=/tmp/resource_usage_${host}.txt
|
resource_usage_info=/tmp/resource_usage_${host}.txt
|
||||||
msg_caption=/tmp/telegram_msg_caption.txt
|
msg_caption=/tmp/telegram_msg_caption.txt
|
||||||
|
|
||||||
#Set threshold levels for memory usage and load here. If the usage exceeds these values, the notification will be sent.
|
#Установите пороговые значения для использования памяти и загрузки здесь. Если использование превысит эти значения, будет отправлено уведомление.
|
||||||
mem_threshold=80 #Should be interger. This is in percentage
|
mem_threshold=80 #Должно быть целым числом. Это в процентах
|
||||||
load_threshold=$(nproc) #Should be integer. Usually total number of cores.
|
load_threshold=1(nproc) #Должно быть целым числом. Обычно это общее количество ядер.
|
||||||
|
|
||||||
#Telegram API to send notificaiton.
|
#Telegram API to send notificaiton.
|
||||||
function telegram_send
|
function telegram_send
|
||||||
@@ -26,7 +26,7 @@ do
|
|||||||
min_load=$(cat /proc/loadavg | cut -d . -f1)
|
min_load=$(cat /proc/loadavg | cut -d . -f1)
|
||||||
if [ $min_load -ge $load_threshold ]
|
if [ $min_load -ge $load_threshold ]
|
||||||
then
|
then
|
||||||
echo -e "⚠️High CPU usage detected⚠️\n🖥$(hostname)\n🌎$ip\n⏱$(uptime)\n#CPU" > $msg_caption
|
echo -e "⚠️Обнаружена высокая загрузка процессора⚠️\n🖥$(hostname)\n🌎$ip\n⏱$(uptime)\n#CPU" > $msg_caption
|
||||||
echo -e "CPU usage report from $(hostname)\nServer Time : $(date +"%d%b%Y %T")\n\n\$uptime\n$(uptime)\n\n%CPU %MEM USER\tCMD" > $resource_usage_info
|
echo -e "CPU usage report from $(hostname)\nServer Time : $(date +"%d%b%Y %T")\n\n\$uptime\n$(uptime)\n\n%CPU %MEM USER\tCMD" > $resource_usage_info
|
||||||
ps -eo pcpu,pmem,user,cmd | sed '1d' | sort -nr >> $resource_usage_info
|
ps -eo pcpu,pmem,user,cmd | sed '1d' | sort -nr >> $resource_usage_info
|
||||||
caption=$(<$msg_caption)
|
caption=$(<$msg_caption)
|
||||||
@@ -42,7 +42,7 @@ do
|
|||||||
mem_usage=$(echo "$mem" | awk 'NR==2{printf "%i\n", ($3*100/$2)}')
|
mem_usage=$(echo "$mem" | awk 'NR==2{printf "%i\n", ($3*100/$2)}')
|
||||||
if [ $mem_usage -gt $mem_threshold ]
|
if [ $mem_usage -gt $mem_threshold ]
|
||||||
then
|
then
|
||||||
echo -e "⚠️High Memory usage detected⚠️\n🖥$(hostname)\n🌎$ip\n🔸$(echo $mem_usage% memory usage)\n#RAM" > $msg_caption
|
echo -e "⚠️Обнаружен высокий уровень использования памяти⚠️\n🖥$(hostname)\n🌎$ip\n🔸$(echo $mem_usage% memory usage)\n#RAM" > $msg_caption
|
||||||
echo -e "Memory consumption Report from $(hostname)\nServer Time : $(date +"%d%b%Y %T")\n\n\$free -m output\n$mem\n\n%MEM %CPU USER\tCMD" > $resource_usage_info
|
echo -e "Memory consumption Report from $(hostname)\nServer Time : $(date +"%d%b%Y %T")\n\n\$free -m output\n$mem\n\n%MEM %CPU USER\tCMD" > $resource_usage_info
|
||||||
ps -eo pmem,pcpu,user,cmd | sed '1d' | sort -nr >> $resource_usage_info
|
ps -eo pmem,pcpu,user,cmd | sed '1d' | sort -nr >> $resource_usage_info
|
||||||
caption=$(<$msg_caption)
|
caption=$(<$msg_caption)
|
||||||
|
|||||||
Reference in New Issue
Block a user