Hi gengz, di tutorial kali ini kita akan coba untuk instalasi cloudwatch untuk EC2, support monitor memory juga loh. Yuk kita coba aja.
Requirement : EC2 sudah terbuat dan sudah bisa diremote via ssh
Kita mulai dengan membuat IAM Roles dulu ya. Silahkan akses url berikut https://console.aws.amazon.com/iam/. Lalu masuk ke Roles

Pilih Create Roles

Pilih EC2, lalu klik Next: Permissions

Ketikkan “CloudWatchAgentServerPolicy”, lalu pilih Next: Tags

Klik Next: Review

Beri nama untuk Roles, lalu klik Create Role

Yuk kita modify IAM role untuk EC2 yang sudah kita buat

Mari pilih IAM role yang sudah kita buat, lalu klik save

Nah kita ke terminal ya gengz, mari kita download dulu package yang dibutuhkan. Silahkan cek ke link berikut untuk tipe linux yang lain https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/download-cloudwatch-agent-commandline.html

wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
Mari kita install dulu ya.

sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
Setelah selesai kita akan melakukan konfigurasi untuk config.json menggunakan wizard ya gengz.

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
Silahkan ikuti jawaban dibawah, pilihan yang berbeda bisa menyebabkan agent tidak berjalan sesuai keinginan.
On which OS are you planning to use the agent?
1. linux
2. windows
3. darwin
default choice: [1]:
1
Trying to fetch the default region based on ec2 metadata...
Are you using EC2 or On-Premises hosts?
1. EC2
2. On-Premises
default choice: [1]:
1
Which user are you planning to run the agent?
1. root
2. cwagent
3. others
default choice: [1]:
1
Do you want to turn on StatsD daemon?
1. yes
2. no
default choice: [1]:
2
Do you want to monitor metrics from CollectD?
1. yes
2. no
default choice: [1]:
2
Do you want to monitor any host metrics? e.g. CPU, memory, etc.
1. yes
2. no
default choice: [1]:
1
Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply.
1. yes
2. no
default choice: [1]:
1
Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if the info is available?
1. yes
2. no
default choice: [1]:
1
Would you like to collect your metrics at high resolution (sub-minute resolution)? This enables sub-minute resolution for all metrics, but you can customize for specific metrics in the output json file.
1. 1s
2. 10s
3. 30s
4. 60s
default choice: [4]:
4
Which default metrics config do you want?
1. Basic
2. Standard
3. Advanced
4. None
default choice: [1]:
1 (Silahkan memilih sesuai dengan keinginan, kita akan mendapatkan metric yang berbeda di cloudwatch)
Are you satisfied with the above config? Note: it can be manually customized after the wizard completes to add additional items.
1. yes
2. no
default choice: [1]:
1
Do you have any existing CloudWatch Log Agent (http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html) configuration file to import for migration?
1. yes
2. no
default choice: [2]:
2
Do you want to monitor any log files?
1. yes
2. no
default choice: [1]:
2
Do you want to store the config in the SSM parameter store?
1. yes
2. no
default choice: [1]:
2
Semua konfigurasi sudah selesai, saatnya kita menjalankan agent dengan perintah dibawah.

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
Agent sudah berhasil jalan, mari kita coba check menggunakan command dibawah.

amazon-cloudwatch-agent-ctl -a status
Mangstap, semua sudah running ya gengz. Yuk kita tengok Cloudwatch kita. Jika konfigurasi dilakukan dengan benar sesuai dengan EYD, eh tutorial maksudnya, kita akan mendapatkan namespace baru seperti dibawah.

Mari kita coba buat dashboard baru yuk.








Gokz mamang, kita sudah bisa membuat dashboard berisikan widget memory (by default memory tidak dimonitor oleh cloudwatch).
Sekian saja ya #belajarsambilberbagi kita kali ini, semoga bermanfaat.
Tinggalkan Balasan