Skip to content

Commit

Permalink
Merge pull request #1468 from woowacourse/feature/1402-로그_모니터링_시스템_구축
Browse files Browse the repository at this point in the history
Feature/1402 로그 모니터링 시스템 구축
  • Loading branch information
java-saeng authored Jul 31, 2023
2 parents 10f1bf4 + c829825 commit 8ff6c20
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions backend/.ebextensions/02-set-filebeat.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"files": {
"/tmp/make_filebeat_yml.sh": {
"mode": "000755",
"content": "#!/bin/bash\nPASSWORD=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_PASSWORD)\nHOST=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_HOST)\nPORT=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_PORT)\nUSER=$(sudo /opt/elasticbeanstalk/bin/get-config environment -k ELASTICSEARCH_USER)\ncat > /home/ec2-user/filebeat-7.14.1-linux-x86_64/filebeat.yml <<EOF\nfilebeat.inputs:\n- type: log\n enabled: true\n paths:\n - /var/app/current/logs/info/info.log\n - /var/app/current/logs/error/error.log\n - /var/app/current/logs/warn/*.log\n fields:\n log_type: legacy-log\n- type: log\n enabled: true\n paths:\n - /var/log/nginx/access.log\n fields:\n log_type: access-log\noutput.elasticsearch:\n hosts: [\"$HOST:$PORT\"]\n username: \"$USER\"\n password: \"$PASSWORD\"\n indices:\n - index: \"filebeat-%{[agent.version]}-access-log\"\n when.equals:\n fields.log_type: \"access-log\"\n - index: \"filebeat-%{[agent.version]}-legacy-log\"\n when.equals:\n fields.log_type: \"legacy-log\"\nEOF"
},
"/tmp/install_filebeat.sh": {
"mode": "000755",
"content": "#!/bin/bash\nwget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.14.1-linux-x86_64.tar.gz\ntar xzvf filebeat-7.14.1-linux-x86_64.tar.gz -C /home/ec2-user\n"
},
"/tmp/restart_filebeat.sh": {
"mode": "000755",
"content": "#!/bin/bash\n\nPID=$(ps -ef | grep ./filebeat | grep -v grep | awk '{print $2}')\n\nif [[ -n \"$PID\" ]]; then\n echo \"Filebeat PID : $PID\"\n sudo kill -9 $PID\nelse\n echo \"Filebeat is not running.\"\nfi\n\necho \"Restarting Filebeat\"\ncd /home/ec2-user/filebeat-7.14.1-linux-x86_64 && sudo chmod 644 filebeat.yml && (nohup ./filebeat -e > filebeat.log 2>&1 &)\necho \"Filebeat restarted\"\n"
}
},
"commands": {
"01_run_install_filebeat": {
"command": "bash /tmp/install_filebeat.sh"
},
"02_run_make_filebeat_yml_script": {
"command": "bash /tmp/make_filebeat_yml.sh"
},
"03_run_filebeat": {
"command": "bash /tmp/restart_filebeat.sh"
}
}
}

0 comments on commit 8ff6c20

Please sign in to comment.