How to setup Cloudwatch Agent ?

From PheonixSolutions
Jump to navigation Jump to search

Install Cloudwatch-agent setup

[edit]
  1. To install Cloudwatchagent, please add IAM role EC2-S3

  1. Login to the server and execute the below commands

 wget https://s3.cn-north-1.amazonaws.com.cn/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
 dpkg -i -E ./amazon-cloudwatch-agent.deb

Open the file and append the content mentioned below

   vi /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_amazon-cloudwatch-agent.json
    {
     "agent": {
       "metrics_collection_interval": 10,
       "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
     },
     "metrics": {
       "namespace": "Leapfinance-PheonixSolutions",
       "metrics_collected": {
         "cpu": {
           "resources": [
             "*"
           ],
           "measurement": [
             {"name": "cpu_usage_idle", "rename": "CPU_USAGE_IDLE", "unit": "Percent"},
             {"name": "cpu_usage_nice", "unit": "Percent"},
             "cpu_usage_guest"
           ],
           "totalcpu": false,
           "metrics_collection_interval": 10,
           "append_dimensions": {
             "customized_dimension_key_1": "customized_dimension_value_1",
             "customized_dimension_key_2": "customized_dimension_value_2"
           }
         },
         "disk": {
           "resources": [
             "/",
             "/tmp"
           ],
           "measurement": [
             {"name": "free", "rename": "DISK_FREE", "unit": "Gigabytes"},
             "total",
             "used"
           ],
            "ignore_file_system_types": [
             "sysfs", "devtmpfs"
           ],
           "metrics_collection_interval": 60,
           "append_dimensions": {
             "customized_dimension_key_3": "customized_dimension_value_3",
             "customized_dimension_key_4": "customized_dimension_value_4"
           }
         },
         "diskio": {
           "resources": [
             "*"
           ],
           "measurement": [
             "reads",
             "writes",
             "read_time",
             "write_time",
             "io_time"
           ],
           "metrics_collection_interval": 60
         },
         "swap": {
           "measurement": [
             "swap_used",
             "swap_free",
             "swap_used_percent"
           ]
         },
         "mem": {
           "measurement": [
             "mem_used",
             "mem_cached",
             "mem_total"
           ],
           "metrics_collection_interval": 1
         },
         "net": {
           "resources": [
             "eth0"
           ],
           "measurement": [
             "bytes_sent",
             "bytes_recv",
             "drop_in",
             "drop_out"
           ]
         },
         "netstat": {
           "measurement": [
             "tcp_established",
             "tcp_syn_sent",
             "tcp_close"
           ],
           "metrics_collection_interval": 60
         },
         "processes": {
           "measurement": [
             "running",
             "sleeping",
             "dead"
           ]
         }
       },
       "append_dimensions": {
         "ImageId": "${aws:ImageId}",
         "InstanceId": "${aws:InstanceId}",
         "InstanceType": "${aws:InstanceType}",
         "AutoScalingGroupName": "${aws:AutoScalingGroupName}"
       },
       "aggregation_dimensions" : [["ImageId"], ["InstanceId", "InstanceType"], ["d1"],[]],
       "force_flush_interval" : 30
     },
     "logs": {
       "logs_collected": {
         "files": {
           "collect_list": [
             {
               "file_path": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log",
               "log_group_name": "amazon-cloudwatch-agent.log",
               "log_stream_name": "amazon-cloudwatch-agent.log",
               "timezone": "UTC"
             },
             {
               "file_path": "/var/log/nginx/acces.log",
               "log_group_name": "ProdLFLogs",
               "log_stream_name": "Prodnginx.log",
               "timezone": "Local"
             }
           ]
         }
       },
       "log_stream_name": "my_log_stream_name",
       "force_flush_interval" : 15
     }
   }
  1. Start the agent

 service amazon-cloudwatch-agent start
  1. Review the Namespace in Cloudwatch