Skip to content

Commit

Permalink
Merge pull request #78 from GSM-MSG/resource_watcher
Browse files Browse the repository at this point in the history
🔀 :: 서버 리소스 와처
  • Loading branch information
HumanIearning authored Jun 30, 2024
2 parents e4cad02 + e224696 commit c871c83
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 636 deletions.
32 changes: 32 additions & 0 deletions resource_watcher/alert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from dotenv import load_dotenv
import os
import argparse
import asyncio
import aiohttp
from discord import Webhook, Embed, Color

parser = argparse.ArgumentParser(description='Add two numbers.')

# positional arguments 정의
parser.add_argument('category', type=str, help='system category e.g) cpu, mem, disk')
parser.add_argument('usage', type=int, help='usage of first arugment e.g) 100, 60, 55')
args = parser.parse_args()

load_dotenv()
discord_url = os.getenv('DISCORD_URL')
Content = Embed(
title='리소스 사용량 경고',
description='서버의 리소스 사용량이 높습니다.',
color=Color.random())

Content.add_field(name=f'{args.category}', value=f'{args.usage}%', inline=False)

Content.set_footer(text='으악 서버 죽어욧')

async def send_fee_data(content):
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(discord_url, session=session)
await webhook.send(embed=content, username='서버 리소스 와처')


asyncio.run(send_fee_data(Content))
24 changes: 24 additions & 0 deletions resource_watcher/resource_watcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh


while true; do
cpu_usage=$(top -bn1 | grep "Cpu(s)" | awk '$8 != "id," {printf("%.0f\n", 100 - $8)}')

if [ -z "$cpu_usage" ]; then
cpu_usage=0
fi


if [ $cpu_usage -gt "80" ]; then
python3 discord_hook.py cpu $cpu_usage
fi

mem_usage=$(free | grep Mem | awk '{printf("%.0f\n", $3 / $2 * 100)}')

if [ $mem_usage -gt "80" ]; then
python3 discord_hook.py mem $mem_usage
fi

sleep 1

done
287 changes: 0 additions & 287 deletions sft/.gitignore

This file was deleted.

Empty file removed sft/db.sqlite3
Empty file.
Empty file removed sft/loginUser/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions sft/loginUser/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions sft/loginUser/apps.py

This file was deleted.

Empty file.
3 changes: 0 additions & 3 deletions sft/loginUser/models.py

This file was deleted.

3 changes: 0 additions & 3 deletions sft/loginUser/tests.py

This file was deleted.

6 changes: 0 additions & 6 deletions sft/loginUser/urls.py

This file was deleted.

6 changes: 0 additions & 6 deletions sft/loginUser/views.py

This file was deleted.

Loading

0 comments on commit c871c83

Please sign in to comment.