-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
09장. 로그 분석 #9
Comments
cloudwatch agent 설치$ cd /var/www
$ wget https://s3.amazonaws.com/amazoncloudwatch-agent/linux/amd64/latest/AmazonCloudWatchAgent.zip
$ unzip AmazonCloudWatchAgent.zip -d AmazonCloudWatchAgent
$ rm AmazonCloudWatchAgent.zip
$ cd AmazonCloudWatchAgent/
$ sudo ./install.sh cloudwatch agent 설치 마법사 실행$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard 특정 설정파일을 이용하여 cloudwatch agent 서비스 시작$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s cloudwatch agent 시작$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a start cloudwatch agent 실행 상태 확인$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status cloudwatch agent 멈춰!$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a stop cloudwatch agent 설정 파일 작성/opt/aws/amazon-cloudwatch-agent/bin/config.json {
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/nginx/access.log",
"log_group_name": "exercise-nginx-access-logs",
"log_stream_name": "{instance_id}"
}
]
}
}
},
"agent": {
"metrics_collection_interval": 30,
"run_as_user": "root"
},
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"metrics_collected": {
"cpu": {
"measurement": [
"cpu_usage_idle",
"cpu_usage_iowait",
"cpu_usage_user",
"cpu_usage_system"
],
"metrics_collection_interval": 30,
"totalcpu": false
},
"disk": {
"measurement": [
"used_percent",
"inodes_free"
],
"metrics_collection_interval": 30,
"resources": [
"*"
]
},
"diskio": {
"measurement": [
"io_time"
],
"metrics_collection_interval": 30,
"resources": [
"*"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 30
},
"swap": {
"measurement": [
"swap_used_percent"
],
"metrics_collection_interval": 30
}
}
}
} |
nginx의 위치가 책과 다른 부분이 있어 내용 추가합니다 :) sudo chmod -R 755 /var/log/nginx; # root계정만 nginx 디렉토리에 접근이 가능하기에 권한을 풀어줌
sudo vim /opt/aws/amazon-cloudwatch-agent/bin/config.json
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/nginx/access.log", # nginx 경로가 다름!
"log_group_name": "exercise-nginx-access-logs",
"log_stream_name": "i-086a308a797ad08b8" # 인스턴스의 id를 자동 할당 해주기 위해선 "{instance_id}"가 맞습니다!
}
]
}
}
} |
@aegis1920 log stream name을 지정할 때 인스턴스 ID를 직접 지정하신 이유가 있나요? |
@KS-KIM |
저는
로그스트림 이름을 인스턴스 이름으로 지정하는 이유는 어떤 인스턴스에서 이슈가 발생했는지 트래킹 하기 위한 목적도 있지 않나 싶습니다. |
엥 나중에 다시 보니까 |
log appender에 설정할 수 있는 encoder가 있네요. 이 방식을 이용하면 application에서 발생한 로그를 json 형식으로 바꿔서 logstash로 쏴줄 수 있나봅니다. |
질문을 남겨주세요!
The text was updated successfully, but these errors were encountered: