-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from GSM-MSG/resource_watcher
🔀 :: 서버 리소스 와처
- Loading branch information
Showing
26 changed files
with
56 additions
and
636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.