Skip to content

Instantly share code, notes, and snippets.

@velopert
Created September 6, 2024 17:03
Show Gist options
  • Save velopert/9aaed8843ad5fc4bdf635aeac55535ac to your computer and use it in GitHub Desktop.
Save velopert/9aaed8843ad5fc4bdf635aeac55535ac to your computer and use it in GitHub Desktop.
path=$1
process_name="Server"
check_unity_memory_usage() {
# 유니티 관련 프로세스의 메모리 사용량 및 프로세스 ID 확인
# linux
ps -eo pid,%cpu,rss,comm --sort=-rss | grep -i "$process_name" | awk '{printf "PID: %d, CPU: %.2f%%, RSS: %d, COMMAND: %s\n", $1, $2, $3, $4}' >> "$path/memory-log.txt"
echo "\n" >> "$path/memory-log.txt"
free -m >> "$path/memory-log.txt"
}
check_unity_memory_usage
@velopert
Copy link
Author

velopert commented Sep 6, 2024

aws gamelift upload-build --name "velev beta" --operating-system "AMAZON_LINUX_2" --server-sdk-version 5.1.2 --build-root . --build-version "v0.4.32" --region ap-northeast-2

@velopert
Copy link
Author

#!/bin/bash

# Download and install the agent
wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
sudo rpm -U ./amazon-cloudwatch-agent.rpm

# Copy the cloudwatch agent configuration file to the right directory
sudo cp amazon-cloudwatch-agent.json /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json

# Start the agent
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s
sleep 15
cat /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log

current_directory=$(pwd)
cron_script="$current_directory/memory.sh"
cron_script_log="$current_directory/memory.sh.log"

setup_cron() {
    # 임시 파일에 현재 crontab 저장
    crontab -l > mycron
    
    # 기존 크론 작업 중복 방지를 위해 기존 작업을 주석처리
    sed -i '/memory.sh/d' mycron
    
    # 새로운 크론 작업 추가 (1분마다 실행)
    echo "* * * * * $cron_script $current_directory>> $cron_script_log 2>&1" >> mycron
    echo "* * * * * sleep 10; $cron_script $current_directory>> $cron_script_log 2>&1" >> mycron
    echo "* * * * * sleep 20; $cron_script $current_directory>> $cron_script_log 2>&1" >> mycron
    echo "* * * * * sleep 30; $cron_script $current_directory>> $cron_script_log 2>&1" >> mycron
    echo "* * * * * sleep 40; $cron_script $current_directory>> $cron_script_log 2>&1" >> mycron
    echo "* * * * * sleep 50; $cron_script $current_directory>> $cron_script_log 2>&1" >> mycron

    # 크론 작업 적용
    crontab mycron
    
    # 임시 파일 삭제
    rm mycron
}

sudo chmod +x ./memory.sh
setup_cron
exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment