hiddify / Hiddify-Manager

Multi-user anti-filtering panel, with an effortless installation and supporting more than 20 protocols to circumvent filtering plus the telegram proxy.
https://hiddify.com
GNU General Public License v3.0
6.15k stars 721 forks source link

اسکریپت اجرای راه انداری مجدد سرویس ها بصورت خودکار #3371

Closed amin2plus closed 8 months ago

amin2plus commented 11 months ago

در ادامه این مشکل

یک اسکریپت پایتونی نوشتم که رم سرور از 85 درصد به بالا رفت به یک چت پیام بده، و زمانی که به 90درصد رم رسید اول به یک چت دیگه(این چت صدا نوتیفیکیشنش بازه) اول پیام بده بعد اسکریپت restat.sh رو اجرا کنه، و بعد توی crontab زدم که هر 5 دقیقه اجرا بشه مشکلم کامل برطرف شده ولی روزی حداقل یک بار پیام ری-استارت سرویس ها میاد و حدس زدم بقیه هم ممکنه این مشکل رو داشته باشند

پیش نیاز:

pip install python-telegram-bot

ram_monitor.py

import psutil
import subprocess
import asyncio
from telegram import Bot

bot_token = "YOUR_BOT_TOKEN" # Replace with your Telegram bot token
alarm_chat_id = 1111111111  # replace with Alarm Chat ID without notification
reboot_chat_id = 22222222  # replace with Reboot Chat ID with notification

async def send_telegram_alert(chat_id, message):
    bot = Bot(token=bot_token)
    await bot.send_message(chat_id=chat_id, text=message)

async def main():

    # Check RAM usage
    ram_percent = psutil.virtual_memory().percent

    if ram_percent > 90:

        message = f"Your VPS RAM usage is {ram_percent}%. Restarting Hiddify services..."
        await send_telegram_alert(alarm_chat_id, message)

        # Restart the service
        subprocess.call(["/opt/hiddify-config/restart.sh"])

    elif ram_percent > 85:

        message = f"Your VPS RAM usage is {ram_percent}%. High RAM usage alert."
        await send_telegram_alert(reboot_chat_id, message)

if __name__ == "__main__":
    asyncio.run(main())

crontab -e

*/5 * * * * /usr/bin/python3 /root/ram_monitor.py

متاسفانه دانشم در این حد هست ، فقط خواستم یک ایده بدم که اگه همچین چیزی رو خودتون اضافه کنید ممکنه به افرادی که مثل من سرورشون مشکل مدیریت منابع داره کمک بشه.

lymanjre commented 8 months ago

این ایشو برای بررسی بیشتر به پروژه منتقل شد. از اینجا بسته میشود