diff --git a/resource_watcher/alert.py b/resource_watcher/alert.py new file mode 100644 index 0000000..d9aa680 --- /dev/null +++ b/resource_watcher/alert.py @@ -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)) diff --git a/resource_watcher/resource_watcher.sh b/resource_watcher/resource_watcher.sh new file mode 100644 index 0000000..7f2303c --- /dev/null +++ b/resource_watcher/resource_watcher.sh @@ -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 \ No newline at end of file diff --git a/sft/.gitignore b/sft/.gitignore deleted file mode 100644 index 234e5df..0000000 --- a/sft/.gitignore +++ /dev/null @@ -1,287 +0,0 @@ -# Created by https://www.toptal.com/developers/gitignore/api/python,django,visualstudiocode -# Edit at https://www.toptal.com/developers/gitignore?templates=python,django,visualstudiocode - -### Django ### -*.log -*.pot -*.pyc -__pycache__/ -local_settings.py -db.sqlite3 -db.sqlite3-journal -media -.env -static/images - -# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ -# in your Git repository. Update and uncomment the following line accordingly. -# /staticfiles/ - -### Django.Python Stack ### -# Byte-compiled / optimized / DLL files -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo - -# Django stuff: - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ - -### Python ### -# Byte-compiled / optimized / DLL files - -# C extensions - -# Distribution / packaging - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. - -# Installer logs - -# Unit test / coverage reports - -# Translations - -# Django stuff: - -# Flask stuff: - -# Scrapy stuff: - -# Sphinx documentation - -# PyBuilder - -# Jupyter Notebook - -# IPython - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm - -# Celery stuff - -# SageMath parsed files - -# Environments - -# Spyder project settings - -# Rope project settings - -# mkdocs documentation - -# mypy - -# Pyre type checker - -# pytype static type analyzer - -# Cython debug symbols - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. - -### Python Patch ### -# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration -poetry.toml - -# ruff -.ruff_cache/ - -# LSP config files -pyrightconfig.json - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -!.vscode/*.code-snippets - -# Local History for Visual Studio Code -.history/ - -# Built Visual Studio Code Extensions -*.vsix - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history -.ionide - -# End of https://www.toptal.com/developers/gitignore/api/python,django,visualstudiocode \ No newline at end of file diff --git a/sft/db.sqlite3 b/sft/db.sqlite3 deleted file mode 100644 index e69de29..0000000 diff --git a/sft/loginUser/__init__.py b/sft/loginUser/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/sft/loginUser/admin.py b/sft/loginUser/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/sft/loginUser/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/sft/loginUser/apps.py b/sft/loginUser/apps.py deleted file mode 100644 index cc6097f..0000000 --- a/sft/loginUser/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class LoginuserConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'loginUser' diff --git a/sft/loginUser/migrations/__init__.py b/sft/loginUser/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/sft/loginUser/models.py b/sft/loginUser/models.py deleted file mode 100644 index 71a8362..0000000 --- a/sft/loginUser/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/sft/loginUser/tests.py b/sft/loginUser/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/sft/loginUser/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/sft/loginUser/urls.py b/sft/loginUser/urls.py deleted file mode 100644 index cb7d092..0000000 --- a/sft/loginUser/urls.py +++ /dev/null @@ -1,6 +0,0 @@ -from loginUser import views -from django.urls import path - -urlpatterns = [ - path('test/', views.index), -] diff --git a/sft/loginUser/views.py b/sft/loginUser/views.py deleted file mode 100644 index bbb75d7..0000000 --- a/sft/loginUser/views.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.shortcuts import render -import os - -def index(request): - print("test") - return render(request, 'info.html') \ No newline at end of file diff --git a/sft/manage.py b/sft/manage.py deleted file mode 100755 index dff8064..0000000 --- a/sft/manage.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -"""Django's command-line utility for administrative tasks.""" -import os -import sys - - -def main(): - """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sft.settings') - try: - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc - execute_from_command_line(sys.argv) - - -if __name__ == '__main__': - main() diff --git a/sft/requirements.txt b/sft/requirements.txt deleted file mode 100644 index 4b8dc23..0000000 --- a/sft/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -asgiref==3.7.2 -Django==4.2.3 -django-rest-framework==0.1.0 -djangorestframework==3.14.0 -pytz==2023.3 -sqlparse==0.4.4 -typing_extensions==4.7.1 \ No newline at end of file diff --git a/sft/sft/__init__.py b/sft/sft/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/sft/sft/__pycache__/__init__.cpython-310.pyc b/sft/sft/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 2cf6015..0000000 Binary files a/sft/sft/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/sft/sft/__pycache__/settings.cpython-310.pyc b/sft/sft/__pycache__/settings.cpython-310.pyc deleted file mode 100644 index 42cfa03..0000000 Binary files a/sft/sft/__pycache__/settings.cpython-310.pyc and /dev/null differ diff --git a/sft/sft/__pycache__/urls.cpython-310.pyc b/sft/sft/__pycache__/urls.cpython-310.pyc deleted file mode 100644 index 2225e67..0000000 Binary files a/sft/sft/__pycache__/urls.cpython-310.pyc and /dev/null differ diff --git a/sft/sft/__pycache__/wsgi.cpython-310.pyc b/sft/sft/__pycache__/wsgi.cpython-310.pyc deleted file mode 100644 index 6e1246e..0000000 Binary files a/sft/sft/__pycache__/wsgi.cpython-310.pyc and /dev/null differ diff --git a/sft/sft/asgi.py b/sft/sft/asgi.py deleted file mode 100644 index 34ea617..0000000 --- a/sft/sft/asgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -ASGI config for sft project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/dev/howto/deployment/asgi/ -""" - -import os - -from django.core.asgi import get_asgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sft.settings') - -application = get_asgi_application() diff --git a/sft/sft/settings.py b/sft/sft/settings.py deleted file mode 100644 index f6df14a..0000000 --- a/sft/sft/settings.py +++ /dev/null @@ -1,103 +0,0 @@ -from pathlib import Path -import environ -import os - -BASE_DIR = Path(__file__).resolve().parent.parent - -TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates') - -env = environ.Env(DEBUG=(bool, True)) - -environ.Env.read_env( - env_file=os.path.join(BASE_DIR, '.env') -) - - -SECRET_KEY = env('SECRET_KEY') - - -DEBUG = env('DEBUG') - -ALLOWED_HOSTS = [] - - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'loginUser', -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = 'sft.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [TEMPLATE_DIR], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - - -WSGI_APPLICATION = 'sft.wsgi.application' - - -DATABASES = { - 'default': { - 'ENGINE': env('DATABASES_ENGINE'), - 'NAME': BASE_DIR / 'db.sqlite3', - } -} - - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_TZ = True - - -STATIC_URL = '/static/' -STATICFILES_DIRS=(os.path.join('static'), ) - - -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/sft/sft/urls.py b/sft/sft/urls.py deleted file mode 100644 index d3f0dd1..0000000 --- a/sft/sft/urls.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.contrib import admin -from django.urls import path, include - -urlpatterns = [ - path('admin/', admin.site.urls), - path('api/', include('loginUser.urls')) -] diff --git a/sft/sft/wsgi.py b/sft/sft/wsgi.py deleted file mode 100644 index 0cea06b..0000000 --- a/sft/sft/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for sft project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sft.settings') - -application = get_wsgi_application() diff --git a/sft/static/css/info.css b/sft/static/css/info.css deleted file mode 100644 index 172a30a..0000000 --- a/sft/static/css/info.css +++ /dev/null @@ -1,82 +0,0 @@ -.info{ - width:15vw; - height:100vh; - background-color:#23233E; - padding-top:5em; -} - -.info-sft-icon-conteinr{ - display: flex; - align-items: center; - justify-content: center; -} - -.info-sft-icon{ - font-family: 'Pretendard'; - font-weight: 700; - color:white; - font-size:1.33em; - text-align: center; - margin-bottom:1em; -} - -.info-sft-icon img{ - width:1.33em; - margin-right: 0.5em; -} - - - -.info-container { - display: flex; - flex-direction: column; - align-items: center; - -} - -.info-container div{ - display: flex; - justify-content: left; - align-items: center; - padding:0 1vw 0 1vw; - font-size:1em; - flex-basis: 3vw; - width:70%; - color:white; - font-family: 'Pretendard'; - font-weight: 500; - - margin-top:1vh; -} - -.info-container div:hover{ - background-color: #36385A ; - border-radius: 8px; -} - -.info-stf-icon{ - font-weight: 700; -} - -.info-container div img{ - margin-right:10px; -} - -.info-container img{ - width:1.33em; - margin-right: 1em; -} - -@font-face { - font-family: 'Pretendard'; - src: url('./images/Pretendard-Bold.woff') format('woff'); - font-weight: 700; - font-display: swap; -} - -@font-face { - font-family: 'Pretendard'; - src: url('./images/Pretendard-Medium.woff') format('woff'); - font-weight: 500; - font-display: swap; -} \ No newline at end of file diff --git a/sft/static/css/reset.css b/sft/static/css/reset.css deleted file mode 100644 index af94440..0000000 --- a/sft/static/css/reset.css +++ /dev/null @@ -1,48 +0,0 @@ -/* http://meyerweb.com/eric/tools/css/reset/ - v2.0 | 20110126 - License: none (public domain) -*/ - -html, body, div, span, applet, object, iframe, -h1, h2, h3, h4, h5, h6, p, blockquote, pre, -a, abbr, acronym, address, big, cite, code, -del, dfn, em, img, ins, kbd, q, s, samp, -small, strike, strong, sub, sup, tt, var, -b, u, i, center, -dl, dt, dd, ol, ul, li, -fieldset, form, label, legend, -table, caption, tbody, tfoot, thead, tr, th, td, -article, aside, canvas, details, embed, -figure, figcaption, footer, header, hgroup, -menu, nav, output, ruby, section, summary, -time, mark, audio, video { - margin: 0; - padding: 0; - border: 0; - font-size: 100%; - font: inherit; - vertical-align: baseline; -} -/* HTML5 display-role reset for older browsers */ -article, aside, details, figcaption, figure, -footer, header, hgroup, menu, nav, section { - display: block; -} -body { - line-height: 1; -} -ol, ul { - list-style: none; -} -blockquote, q { - quotes: none; -} -blockquote:before, blockquote:after, -q:before, q:after { - content: ''; - content: none; -} -table { - border-collapse: collapse; - border-spacing: 0; -} \ No newline at end of file diff --git a/sft/templates/info.html b/sft/templates/info.html deleted file mode 100644 index 19d3b11..0000000 --- a/sft/templates/info.html +++ /dev/null @@ -1,21 +0,0 @@ - -{% load static%} - - - - Info - - - - -
-
-
SFT
-
-
-
Dashboards
-
Settings
-
Logout
-
-
- \ No newline at end of file