Skip to content

Latest commit

ย 

History

History
124 lines (86 loc) ยท 4.08 KB

File metadata and controls

124 lines (86 loc) ยท 4.08 KB

Server-Status-Report

๐Ÿ–ฅ๏ธ Tracking server status(CPU, Memory, GPU, Disk) and sending reports to email

๐Ÿš€ English version

๐Ÿ“Œ Function

  • ๋งค์ผ ์˜ค์ „ 8์‹œ์— ์ „๋‚ ์˜ ์„œ๋ฒ„ ์ถ”์ ์— ๊ด€ํ•œ ์ด๋ฉ”์ผ ๋ณด๊ณ ์„œ๋ฅผ ๋ณด๋‚ด๊ธฐ(์ด๋ฉ”์ผ์— ์ด๋ฏธ์ง€๋กœ ์ฒจ๋ถ€)
daily daily
  • ๋งค๋ถ„ ๋ฆฌ์†Œ์Šค ์‚ฌ์šฉ๋Ÿ‰์„ ํ™•์ธํ•˜๊ณ  80%๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด ์ด๋ฉ”์ผ ๋ณด๋‚ด๊ธฐ(ํ•ด๊ฒฐ ๋˜์ง€์•Š์€ ๋ฌธ์ œ๋Š” 6์‹œ๊ฐ„๋งˆ๋‹ค ๋‹ค์‹œ ์•Œ๋ฆผ)
cpu mem disk
  • ์ด๋ฉ”์ผ๋กœ ์„œ๋น„์Šค ์‹œ์ž‘ ์•Œ๋ฆผ(e.g. ์žฌ๋ถ€ํŒ… ์‹œ)
start

โœ๏ธ Usase

Note

  • ๋ณธ ํ”„๋กœ์ ํŠธ๋Š” ๋ฐœ์‹  ๊ณ„์ •์œผ๋กœ Gmail์„ ์‚ฌ์šฉํ•จ
  1. Git clone ํ›„ python ํŒจํ‚ค์ง€ ์„ค์น˜ํ•˜๊ธฐ

    git clone https://github.com/the0807/Server-Status-Report
    cd Server-Status-Report
    pip install -r requirements.txt
  2. Gmail์—์„œ ์•ฑ ํŒจ์Šค์›Œ๋“œ ์ƒ์„ฑํ•˜๊ธฐ

    a. Google Account ์ ‘์†ํ•˜๊ธฐ

    ๐Ÿš€ Google Account

    b. App Password ๊ฒ€์ƒ‰ํ•˜๊ธฐ

    c. ์•ฑ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ  ์ƒ์„ฑ ๋ฒ„ํŠผ ํด๋ฆญํ•˜๊ธฐ

    d. ์ฐฝ์ด ๋‚˜ํƒ€๋‚  ๋•Œ ๋‚˜ํƒ€๋‚˜๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ ๋ณต์‚ฌํ•˜๊ธฐ

Caution

  • ์ฐฝ์„ ๋‹ซ์œผ๋ฉด ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๋‹ค์‹œ ํ‘œ์‹œ๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๋ฐ˜๋“œ์‹œ ๋ณต์‚ฌํ•˜์„ธ์š”
  1. .env ํŒŒ์ผ์„ ์ƒ์„ฑ ํ•œ ํ›„ ์•„๋ž˜์˜ ๋‚ด์šฉ ์ž…๋ ฅํ•˜๊ธฐ

    SERVER_NAME = # Server name
    SMTP_SERVER = 'smtp.gmail.com'
    SMTP_PORT = 587
    EMAIL_ADDRESS = # Gmail address to send
    EMAIL_PASSWORD = # Gmail APP password
    RECIPIENT_EMAIL = # Email address to receive
  2. systemd ์„œ๋น„์Šค ๋“ฑ๋กํ•˜๊ธฐ

    a. server_status.service ์ƒ์„ฑํ•˜๊ธฐ

    sudo vim /etc/systemd/system/server_status.service
    
    # ์•„๋ž˜์— ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•˜์„ธ์š”(๊ฒฝ๋กœ์— ๋”ฐ๋ผ ์ˆ˜์ •)
    [Unit]
    Description=Server Status Monitoring Script
    After=multi-user.target
    
    [Service]
    # ExecStart, WorkingDirectory ๊ฒฝ๋กœ๊ฐ€ ์˜ฌ๋ฐ”๋ฅธ์ง€ ํ™•์ธํ•˜์„ธ์š”.
    ExecStart=/usr/bin/python3 /home/ubuntu/Server-Status-Report/main.py
    WorkingDirectory=/home/ubuntu/Server-Status-Report
    Restart=on-failure
    RestartSec=30s
    # ์‚ฌ์šฉ์ž๊ฐ€ ์˜ฌ๋ฐ”๋ฅธ์ง€ ํ™•์ธํ•˜์„ธ์š”.
    User=ubuntu
    
    [Install]
    WantedBy=multi-user.target

    b. ์„œ๋น„์Šค ํ™œ์„ฑํ™” ๋ฐ ์‹œ์ž‘

    # `server_status.service`์„ ์ˆ˜์ •ํ•˜๋ฉด ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ๋‹ค์‹œ ์‹คํ–‰ํ•˜์„ธ์š”
    sudo systemctl daemon-reload
    sudo systemctl enable server_status.service
    sudo systemctl start server_status.service

    c. ์„œ๋น„์Šค ์ƒํƒœ ํ™•์ธ

    sudo systemctl status server_status.service

Note

  • ์„œ๋ฒ„๋ฅผ ์‹œ์ž‘ํ•  ๋•Œ ์ด๋ฉ”์ผ ์•Œ๋ฆผ์„ ๋ฐ›์œผ๋ฉด ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

โ—๏ธ Troubleshooting

โญ๏ธ ์„œ๋น„์Šค ์ƒํƒœ๊ฐ€ ์‹คํŒจ์ธ ๊ฒฝ์šฐ

ํ„ฐ๋ฏธ๋„์—์„œ server_status.service ํŒŒ์ผ์˜ ExecStart๋ฅผ ์ง์ ‘ ์‹คํ–‰ํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

# ์‹ค์‹œ๊ฐ„ ๋กœ๊ทธ ํ™•์ธ
journalctl -f server_status.service