【AWS】【AmazonLinux2】CloudWatch エージェントでログ監視をする設定手順【awslogsd】【追記:awslogsdがなくてもログ監視が可能になった】

公開日時:2019年09月15日 / 最終更新日時:2019年09月17日

Amazon CloudWatch エージェントをインストールし、Amazon Linux2 でログ監視をする設定手順について解説します。

/var/log/messages などのログファイルを監視して特定のエラーなどが出力されたらアラートメールを送信するということは Zabbix で既に設定されている企業も多いかと思いますが、今後クラウド環境、特に AWS 環境に移行する場合は CloudWatch エージェントを利用する方向になると思います。

 

 

 

CloudWatch と Zabbix のメリットデメリット

Zabbix は監視対象のサーバーに Zabbix エージェントを導入してリモート監視を実現し、スクリプトを利用すればほぼほぼ何でも出来ます。

リモート監視で何でも出来るという部分では、Amazon CloudWatch エージェントも同様に何でもできます。

しかも CloudWatch から AWS の機能が利用できるので、Zabbix よりもいろんなことが出来るでしょう。

むしろできないことがないくらいです。(例えば、Lambda やその他サービスとの組み合わせで)

 

ただ、Zabbix は長年利用してきて操作に慣れているという部分と、CloudWatch は初めてなのでどう設定すれば分からないとい学習コストの面を考えると、Zabbix を使い続けた方が学習コストが低いと言えるでしょう。

ただし、学習コストが低いという理由で Zabbix を使い続けるのはもったいないとも言えます。

 

また、Zabbix は定期的にバージョンアップをする必要があります。

更に Zabbix のメジャーバージョンアップ(Zabbix 2 → Zabbix 3 や、Zabbix 3 → Zabbix 4 など)を実施すると、データベースのテーブルの構成が異なるためバージョンアップが非常に難しくなります。

誰でも簡単にバージョンアップが可能ではなくなります。

 

この先クラウド環境でサーバーを運用するなら、ここで CloudWatch エージェントによる監視に移行することも一つの手だと思います。

 

 

 

手順概要

今回の設定手順は以下のようになりました。

  1. CloudWatch エージェントをインストール
  2. CloudWatch エージェントの設定
  3. CloudWatch の設定
  4. 動作確認
  5. CloudWatch Logs エージェントのインストール
  6. CloudWatch Logs エージェントの設定
  7. 動作確認
  8. 【修正】CloudWatch エージェントの設定
  9. 動作確認

 

 

 

環境

OS は Amazon Linux 2 です。

■OS

[root@AmazonLinux2 logs]# cat /etc/system-release
Amazon Linux release 2 (Karoo)
[root@AmazonLinux2 logs]#

 

 

■カーネル

[root@AmazonLinux2 ~]# uname -a
Linux AmazonLinux2 4.14.138-114.102.amzn2.x86_64 #1 SMP Thu Aug 15 15:29:58 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@AmazonLinux2 ~]#

 

 

 

 

CloudWatch エージェントをインストール

以下の記事は RedHat に CloudWatch エージェントをインストールする手順です。

 

【AWS】CloudWatch エージェントをインストールして EC2 インスタンス(RedHat Linux)のメモリ使用率を取得する設定手順

 

 

root にスイッチします。

[ec2-user@AmazonLinux2 ~]$ sudo su -
Last login: Sun Sep 15 10:19:52 JST 2019 on pts/0
[root@AmazonLinux2 ~]#

 

 

以下のコマンドで Amazon Linux2 用の CloudWatch エージェントのインストールパッケージをダウンロードします。

[root@AmazonLinux2 ~]# wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm 

 

 

以下のコマンドで CloudWatch エージェントをインストールします。

[root@AmazonLinux2 ~]# yum install amazon-cloudwatch-agent.rpm

 

 

 

「/opt/aws/amazon-cloudwatch-agent/bin/」ディレクトリに移動して「amazon-cloudwatch-agent-config-wizard」ファイルを確認します。

[root@AmazonLinux2 ~]# cd /opt/aws/amazon-cloudwatch-agent/bin/ 
[root@AmazonLinux2 bin]# ls 
amazon-cloudwatch-agent                config-downloader  start-amazon-cloudwatch-agent 
amazon-cloudwatch-agent-config-wizard  config-translator 
amazon-cloudwatch-agent-ctl            CWAGENT_VERSION 
[root@AmazonLinux2 bin]#

 

 

 

 

「amazon-cloudwatch-agent-config-wizard」コマンドを実行します。

[root@AmazonLinux2 bin]# ./amazon-cloudwatch-agent-config-wizard 
============================================================= 
= Welcome to the AWS CloudWatch Agent Configuration Manager = 
============================================================= 
On which OS are you planning to use the agent? 
1. linux 
2. windows 
default choice: [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]: 

Which user are you planning to run the agent? 
1. root 
2. cwagent 
3. others 
default choice: [1]: 

Do you want to turn on StatsD daemon? 
1. yes 
2. no 
default choice: [1]: 

Which port do you want StatsD daemon to listen to? 
default choice: [8125] 
 
What is the collect interval for StatsD daemon? 
1. 10s 
2. 30s 
3. 60s 
default choice: [1]: 

What is the aggregation interval for metrics collected by StatsD daemon? 
1. Do not aggregate 
2. 10s 
3. 30s 
4. 60s 
default choice: [4]: 

Do you want to monitor metrics from CollectD? 
1. yes 
2. no 
default choice: [1]: 

Do you want to monitor any host metrics? e.g. CPU, memory, etc. 
1. yes 
2. no 
default choice: [1]: 

Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply. 
1. yes 
2. no 
default choice: [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]: 

Would you like to collect your metrics at high resolution (sub-minute resolution)? This enables sub-minute resolutio                            n 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]: 

Which default metrics config do you want? 
1. Basic 
2. Standard 
3. Advanced 
4. None 
default choice: [1]: 

Current config as follows: 

        "agent": { 
                "metrics_collection_interval": 60, 
                "run_as_user": "root" 
        }, 
        "metrics": { 
                "append_dimensions": { 
                        "AutoScalingGroupName": "${aws:AutoScalingGroupName}", 
                        "ImageId": "${aws:ImageId}", 
                        "InstanceId": "${aws:InstanceId}", 
                        "InstanceType": "${aws:InstanceType}" 
                }, 
                "metrics_collected": { 
                        "collectd": { 
                                "metrics_aggregation_interval": 60 
                        }, 
                        "cpu": { 
                                "measurement": [ 
                                        "cpu_usage_idle", 
                                        "cpu_usage_iowait", 
                                        "cpu_usage_user", 
                                        "cpu_usage_system" 
                                ], 
                                "metrics_collection_interval": 60, 
                                "resources": [ 
                                        "*" 
                                ], 
                                "totalcpu": false 
                        }, 
                        "disk": { 
                                "measurement": [ 
                                        "used_percent", 
                                        "inodes_free" 
                                ], 
                                "metrics_collection_interval": 60, 
                                "resources": [ 
                                        "*" 
                                ] 
                        }, 
                        "diskio": { 
                                "measurement": [ 
                                        "io_time", 
                                        "write_bytes", 
                                        "read_bytes", 
                                        "writes", 
                                        "reads" 
                                ], 
                                "metrics_collection_interval": 60, 
                                "resources": [ 
                                        "*" 
                                ] 
                        }, 
                        "mem": { 
                                "measurement": [ 
                                        "mem_used_percent" 
                                ], 
                                "metrics_collection_interval": 60 
                        }, 
                        "netstat": { 
                                "measurement": [ 
                                        "tcp_established", 
                                        "tcp_time_wait" 
                                ], 
                                "metrics_collection_interval": 60 
                        }, 
                        "statsd": { 
                                "metrics_aggregation_interval": 60, 
                                "metrics_collection_interval": 60, 
                                "service_address": ":8125" 
                        }, 
                        "swap": { 
                                "measurement": [ 
                                        "swap_used_percent" 
                                ], 
                                "metrics_collection_interval": 60 
                        } 
                } 
        } 

Are you satisfied with the above config? Note: it can be manually customized after the wizard completes to add addit                            ional items. 
1. yes 
2. no 
default choice: [1]: 

Do you have any existing CloudWatch Log Agent (http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReferenc                            e.html) configuration file to import for migration? 
1. yes 
2. no 
default choice: [2]: 

Do you want to monitor any log files? 
1. yes 
2. no 
default choice: [1]: 

Log file path: 
/var/log/messages 
Log group name: 
default choice: [messages] 
 
Log stream name: 
default choice: [{instance_id}] 
 
Do you want to specify any additional log files to monitor? 
1. yes 
2. no 
default choice: [1]: 

Saved config file to /opt/aws/amazon-cloudwatch-agent/bin/config.json successfully. 
Current config as follows: 

        "agent": { 
                "metrics_collection_interval": 60, 
                "run_as_user": "root" 
        }, 
        "logs": { 
                "logs_collected": { 
                        "files": { 
                                "collect_list": [ 
                                        { 
                                                "file_path": "/var/log/messages", 
                                                "log_group_name": "messages", 
                                                "log_stream_name": "{instance_id}" 
                                        } 
                                ] 
                        } 
                } 
        }, 
        "metrics": { 
                "append_dimensions": { 
                        "AutoScalingGroupName": "${aws:AutoScalingGroupName}", 
                        "ImageId": "${aws:ImageId}", 
                        "InstanceId": "${aws:InstanceId}", 
                        "InstanceType": "${aws:InstanceType}" 
                }, 
                "metrics_collected": { 
                        "collectd": { 
                                "metrics_aggregation_interval": 60 
                        }, 
                        "cpu": { 
                                "measurement": [ 
                                        "cpu_usage_idle", 
                                        "cpu_usage_iowait", 
                                        "cpu_usage_user", 
                                        "cpu_usage_system" 
                                ], 
                                "metrics_collection_interval": 60, 
                                "resources": [ 
                                        "*" 
                                ], 
                                "totalcpu": false 
                        }, 
                        "disk": { 
                                "measurement": [ 
                                        "used_percent", 
                                        "inodes_free" 
                                ], 
                                "metrics_collection_interval": 60, 
                                "resources": [ 
                                        "*" 
                                ] 
                        }, 
                        "diskio": { 
                                "measurement": [ 
                                        "io_time", 
                                        "write_bytes", 
                                        "read_bytes", 
                                        "writes", 
                                        "reads" 
                                ], 
                                "metrics_collection_interval": 60, 
                                "resources": [ 
                                        "*" 
                                ] 
                        }, 
                        "mem": { 
                                "measurement": [ 
                                        "mem_used_percent" 
                                ], 
                                "metrics_collection_interval": 60 
                        }, 
                        "netstat": { 
                                "measurement": [ 
                                        "tcp_established", 
                                        "tcp_time_wait" 
                                ], 
                                "metrics_collection_interval": 60 
                        }, 
                        "statsd": { 
                                "metrics_aggregation_interval": 60, 
                                "metrics_collection_interval": 60, 
                                "service_address": ":8125" 
                        }, 
                        "swap": { 
                                "measurement": [ 
                                        "swap_used_percent" 
                                ], 
                                "metrics_collection_interval": 60 
                        } 
                } 
        } 

Please check the above content of the config. 
The config file is also located at /opt/aws/amazon-cloudwatch-agent/bin/config.json. 
Edit it manually if needed. 
Do you want to store the config in the SSM parameter store? 
1. yes 
2. no 
default choice: [1]: 

What parameter store name do you want to use to store your config? (Use 'AmazonCloudWatch-' prefix if you use our ma                            naged AWS policy) 
default choice: [AmazonCloudWatch-linux] 
 
Trying to fetch the default region based on ec2 metadata... 
Which region do you want to store the config in the parameter store? 
default choice: [ap-northeast-1] 
 
Which AWS credential should be used to send json config to parameter store? 
1. ASIAUJQZRURBZGAE5WM2(From SDK) 
2. Other 
default choice: [1]: 
 
Successfully put config to parameter store AmazonCloudWatch-linux. 
Program exits now. 
[root@AmazonLinux2 bin]#

 

 

 

CloudWatch エージェントのステータスを確認します。

■CloudWatch エージェントのステータス確認

[root@AmazonLinux2 bin]#  /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status 

  "status": "stopped", 
  "starttime": "", 
  "version": "1.227496.0" 

[root@AmazonLinux2 bin]#

 

 

CloudWatch エージェントを起動します。

■CloudWatch エージェントの起動

[root@AmazonLinux2 bin]# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a start 
amazon-cloudwatch-agent is not configured. Applying default configuration before starting it. 
/opt/aws/amazon-cloudwatch-agent/bin/config-downloader --output-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --download-source default --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
Successfully fetched the config and saved in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/default.tmp 
Start configuration validation... 
/opt/aws/amazon-cloudwatch-agent/bin/config-translator --input /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json --input-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --output /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
2019/09/15 10:34:56 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/default.tmp ... 
Valid Json input schema. 
I! Detecting runasuser... 
No csm configuration found. 
No log configuration found. 
Configuration validation first phase succeeded 
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -schematest -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml 
Configuration validation second phase succeeded 
Configuration validation succeeded 
Created symlink from /etc/systemd/system/multi-user.target.wants/amazon-cloudwatch-agent.service to /etc/systemd/system/amazon-cloudwatch-agent.service. 
Redirecting to /bin/systemctl restart amazon-cloudwatch-agent.service 
[root@AmazonLinux2 bin]#

 

 

 

再度 CloudWatch エージェントのステータスを確認します。

■CloudWatch エージェントのステータス確認

[root@AmazonLinux2 bin]# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status 

  "status": "running", 
  "starttime": "2019-09-15T01:34:56+0000", 
  "version": "1.227496.0" 

[root@AmazonLinux2 bin]#

 

 

 

 

動作確認(ログが表示されなかった)

結論から言えば、CloudWatch にログが表示されませんでした。

おそらく設定が足りないのか間違っているかと思われます。

 

CloudWatch ダッシュボードに移動し、左側ペインより「ログ」を選択します。

【AWS】【AmazonLinux2】CloudWatch エージェントでログ監視をする設定手順【awslogsd】

 

 

 

時間を置いて何度か確認しましたが、設定が間違っているのか、何か設定が足りないのかログは表示されませんでした。

→引き続き原因の調査

【AWS】【AmazonLinux2】CloudWatch エージェントでログ監視をする設定手順【awslogsd】

 

 

 

※下に記載していますが、awslogsd がなくてもログ監視が可能になりました。

原因は設定方法が間違っていたからです。下で詳しく解説します。

 

 

 

 

CloudWatch Logs でログ監視をする

原因が不明なので CloudWatch Logs エージェントをインストールしてログ監視を試します。

 

awslogs のインストール

awslogs をインストールします。

[root@AmazonLinux2 logs]# yum install awslogs 
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd 
Resolving Dependencies 
--> Running transaction check 
---> Package awslogs.noarch 0:1.1.4-3.amzn2 will be installed 
--> Processing Dependency: aws-cli-plugin-cloudwatch-logs for package: awslogs-1.1.4-3.amzn2.noarch 
--> Running transaction check 
---> Package aws-cli-plugin-cloudwatch-logs.noarch 0:1.4.4-1.amzn2.0.1 will be installed 
--> Finished Dependency Resolution 
 
Dependencies Resolved 
 
==================================================================================================================== 
 Package                                  Arch             Version                       Repository            Size 
==================================================================================================================== 
Installing: 
 awslogs                                  noarch           1.1.4-3.amzn2                 amzn2-core           8.2 k 
Installing for dependencies: 
 aws-cli-plugin-cloudwatch-logs           noarch           1.4.4-1.amzn2.0.1             amzn2-core            62 k 
 
Transaction Summary 
==================================================================================================================== 
Install  1 Package (+1 Dependent package) 
 
Total download size: 70 k 
Installed size: 243 k 
Is this ok [y/d/N]: y 
Downloading packages: 
(1/2): awslogs-1.1.4-3.amzn2.noarch.rpm                                                      | 8.2 kB  00:00:00 
(2/2): aws-cli-plugin-cloudwatch-logs-1.4.4-1.amzn2.0.1.noarch.rpm                           |  62 kB  00:00:00 
-------------------------------------------------------------------------------------------------------------------- 
Total                                                                               529 kB/s |  70 kB  00:00:00 
Running transaction check 
Running transaction test 
Transaction test succeeded 
Running transaction 
  Installing : aws-cli-plugin-cloudwatch-logs-1.4.4-1.amzn2.0.1.noarch                                          1/2 
  Installing : awslogs-1.1.4-3.amzn2.noarch                                                                     2/2 
  Verifying  : awslogs-1.1.4-3.amzn2.noarch                                                                     1/2 
  Verifying  : aws-cli-plugin-cloudwatch-logs-1.4.4-1.amzn2.0.1.noarch                                          2/2 
 
Installed: 
  awslogs.noarch 0:1.1.4-3.amzn2 
 
Dependency Installed: 
  aws-cli-plugin-cloudwatch-logs.noarch 0:1.4.4-1.amzn2.0.1 
 
Complete! 
[root@AmazonLinux2 logs]#

 

 

 

/etc/awslogs/awscli.conf の設定

/etc/awslogs/awscli.conf を設定します。

[root@AmazonLinux2 logs]# vi /etc/awslogs/awscli.conf

[plugins]
cwlogs = cwlogs
[default]
#region = us-east-1
region = ap-northeast-1

 

 

 

 

/etc/awslogs/awslogs.conf の設定 or 確認

/etc/awslogs/awslogs.conf の設定もしくは確認をします。

デフォルトではほとんどコメントアウトされており、「/var/log/messages」のみが設定されています。

今回の場合は messages のみ監視するのでデフォルトのままにしておきます。

[root@AmazonLinux2 logs]# less /etc/awslogs/awslogs.conf 
 

# ------------------------------------------ 
# CLOUDWATCH LOGS AGENT CONFIGURATION FILE 
# ------------------------------------------ 

# --- DESCRIPTION --- 
# This file is used by the CloudWatch Logs Agent to specify what log data to send to the service and how. 
# You can modify this file at any time to add, remove or change configuration. 

# NOTE: A running agent must be stopped and restarted for configuration changes to take effect. 

# --- CLOUDWATCH LOGS DOCUMENTATION --- 
# https://aws.amazon.com/documentation/cloudwatch/ 

# --- CLOUDWATCH LOGS CONSOLE --- 
# https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logs: 

# --- AGENT COMMANDS --- 
# To check or change the running status of the CloudWatch Logs Agent, use the following: 

# To check running status: service awslogs status 
# To stop the agent: service awslogs stop 
# To start the agent: service awslogs start 
# To start the agent on server startup: chkconfig awslogs on 

# --- AGENT LOG OUTPUT --- 
# You can find logs for the agent in /var/log/awslogs.log 

 
# ------------------------------------------ 
# CONFIGURATION DETAILS 
# ------------------------------------------ 
 
[general] 
# Path to the CloudWatch Logs agent's state file. The agent uses this file to maintain 
# client side state across its executions. 
state_file = /var/lib/awslogs/agent-state 
 
## Each log file is defined in its own section. The section name doesn't 
## matter as long as its unique within this file. 
#[kern.log] 

## Path of log file for the agent to monitor and upload. 
#file = /var/log/kern.log 

## Name of the destination log group. 
#log_group_name = kern.log 

## Name of the destination log stream. You may use {hostname} to use target machine's hostname. 
#log_stream_name = {instance_id} # Defaults to ec2 instance id 

## Format specifier for timestamp parsing. Here are some sample formats: 
## Use '%b %d %H:%M:%S' for syslog (Apr 24 08:38:42) 
## Use '%d/%b/%Y:%H:%M:%S' for apache log (10/Oct/2000:13:55:36) 
## Use '%Y-%m-%d %H:%M:%S' for rails log (2008-09-08 11:52:54) 
#datetime_format = %b %d %H:%M:%S # Specification details in the table below. 

## A batch is buffered for buffer-duration amount of time or 32KB of log events. 
## Defaults to 5000 ms and its minimum value is 5000 ms. 
#buffer_duration = 5000 

# Use 'end_of_file' to start reading from the end of the file. 
# Use 'start_of_file' to start reading from the beginning of the file. 
#initial_position = start_of_file 

## Encoding of file 
#encoding = utf-8 # Other supported encodings include: ascii, latin-1 



# Following table documents the detailed datetime format specification: 
# ---------------------------------------------------------------------------------------------------------------------- 
# Directive     Meaning                                                                                 Example 
# ---------------------------------------------------------------------------------------------------------------------- 
# %a            Weekday as locale's abbreviated name.                                                   Sun, Mon, ..., Sat (en_US) 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %A           Weekday as locale's full name.                                                          Sunday, Monday, ..., Saturday (en_US) 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %w           Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.                       0, 1, ..., 6 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %d           Day of the month as a zero-padded decimal numbers.                                      01, 02, ..., 31 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %b           Month as locale's abbreviated name.                                                     Jan, Feb, ..., Dec (en_US) 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %B           Month as locale's full name.                                                            January, February, ..., December (en_US) 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %m           Month as a zero-padded decimal number.                                                  01, 02, ..., 12 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %y           Year without century as a zero-padded decimal number.                                   00, 01, ..., 99 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %Y           Year with century as a decimal number.                                                  1970, 1988, 2001, 2013 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %H           Hour (24-hour clock) as a zero-padded decimal number.                                   00, 01, ..., 23 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %I           Hour (12-hour clock) as a zero-padded decimal numbers.                                  01, 02, ..., 12 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %p           Locale's equivalent of either AM or PM.                                                 AM, PM (en_US) 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %M           Minute as a zero-padded decimal number.                                                 00, 01, ..., 59 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %S           Second as a zero-padded decimal numbers.                                                00, 01, ..., 59 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %f           Microsecond as a decimal number, zero-padded on the left.                               000000, 000001, ..., 999999 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %z           UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).        (empty), +0000, -0400, +1030 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %j           Day of the year as a zero-padded decimal number.                                        001, 002, ..., 365 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %U           Week number of the year (Sunday as the first day of the week) as a zero padded          00, 01, ..., 53 
#               decimal number. All days in a new year preceding the first Sunday are considered 
#               to be in week 0. 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %W           Week number of the year (Monday as the first day of the week) as a decimal number.      00, 01, ..., 53 
#               All days in a new year preceding the first Monday are considered to be in week 0. 
# ---------------------------------------------------------------------------------------------------------------------- 
#  %c           Locale's appropriate date and time representation.                                      Tue Aug 16 21:30:00 1988 (en_US) 
# ---------------------------------------------------------------------------------------------------------------------- 
 
 
[/var/log/messages] 
datetime_format = %b %d %H:%M:%S 
file = /var/log/messages 
buffer_duration = 5000 
log_stream_name = {instance_id} 
initial_position = start_of_file 
log_group_name = /var/log/messages 
[root@AmazonLinux2 logs]#

 

 

 

awslogsd.service の起動

設定が完了したら「awslogsd.service」を起動します。

 

 

awslogsd.service の起動

[root@AmazonLinux2 logs]# systemctl start awslogsd.service

 

 

■awslogsd.service のステータス確認

[root@AmazonLinux2 logs]# systemctl status awslogsd.service 
● awslogsd.service - awslogs daemon 
   Loaded: loaded (/usr/lib/systemd/system/awslogsd.service; disabled; vendor preset: disabled) 
   Active: active (running) since Sun 2019-09-15 10:51:26 JST; 4s ago 
 Main PID: 4764 (aws) 
   CGroup: /system.slice/awslogsd.service 
           mq4764 /usr/bin/python2 -s /usr/bin/aws logs push --config-file /etc/awslogs/awslogs.conf --additional-configs-dir /etc/awslogs/co... 
 
Sep 15 10:51:26 AmazonLinux2 systemd[1]: Started awslogs daemon. 
Sep 15 10:51:26 AmazonLinux2 systemd[1]: Starting awslogs daemon... 
[root@AmazonLinux2 logs]#

 

 

 

 

 

 

 

 

ログ監視確認

CloudWatch のダッシュボードに移動し左側ペインより「ログ」をクリックします。

【AWS】【AmazonLinux2】CloudWatch エージェントでログ監視をする設定手順【awslogsd】

 

 

 

 

対象のロググループ(今回の場合は /var/log/messages)をクリックします。

【AWS】【AmazonLinux2】CloudWatch エージェントでログ監視をする設定手順【awslogsd】

 

 

 

 

下図のようにログが取得できていることを確認します。

【AWS】【AmazonLinux2】CloudWatch エージェントでログ監視をする設定手順【awslogsd】

 

 

 

追記:awslogsdがなくてもログ監視が可能になった

設定が間違っていたためログ監視が出来ませんでした。

再度設定をし直します。

 

まず初めに CloudWatch エージェントのステータスを確認します。

■CloudWatch エージェントのステータス確認

[root@AmazonLinux2 bin]#  /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status 

  "status": "stopped", 
  "starttime": "", 
  "version": "1.227496.0" 

[root@AmazonLinux2 bin]#

 

 

 

CloudWatch エージェントを起動しますが、その際にコンフィグを指定する必要があります。

 

■コンフィグの場所

amazon-cloudwatch-agent-config-wizard コマンドを実行した直後の場合は以下にコンフィグがあります。

[root@AmazonLinux2 bin]# pwd 
/opt/aws/amazon-cloudwatch-agent/bin 
[root@AmazonLinux2 bin]# ls -lh 
total 149M 
-rwxr-xr-x 1 root root  71M Aug 23 14:49 amazon-cloudwatch-agent 
-rwxr-xr-x 1 root root  14M Aug 23 14:49 amazon-cloudwatch-agent-config-wizard 
-rwxr-xr-x 1 root root 9.7K Aug 23 14:49 amazon-cloudwatch-agent-ctl 
-rwxr-xr-x 1 root root  12M Aug 23 14:49 config-downloader 
-rwxr-xr-x 1 root root 1.7K Sep 16 23:08 config.json ← これがコンフィグになります。このコンフィグを読み込み amazon-cloudwatch-agent(CloudWatch エージェント)を起動する必要があります。
-rwxr-xr-x 1 root root  27M Aug 23 14:49 config-translator 
-rw-r--r-- 1 root root   11 Aug 23 14:49 CWAGENT_VERSION 
-rwxr-xr-x 1 root root  27M Aug 23 14:49 start-amazon-cloudwatch-agent 
[root@AmazonLinux2 bin]#

 

 

 

 

CloudWatch エージェントを起動します。

■CloudWatch エージェントの起動(コンフィグを指定せずに起動する)

[root@AmazonLinux2 bin]# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a start 
amazon-cloudwatch-agent is not configured. Applying default configuration before starting it. 
/opt/aws/amazon-cloudwatch-agent/bin/config-downloader --output-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --download-source default --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
Successfully fetched the config and saved in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/default.tmp 
Start configuration validation... 
/opt/aws/amazon-cloudwatch-agent/bin/config-translator --input /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json --input-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --output /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
2019/09/16 14:38:29 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/default.tmp ... 
Valid Json input schema. 
I! Detecting runasuser... 
No csm configuration found. 
No log configuration found. 
Configuration validation first phase succeeded 
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -schematest -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml 
Configuration validation second phase succeeded 
Configuration validation succeeded 
Created symlink from /etc/systemd/system/multi-user.target.wants/amazon-cloudwatch-agent.service to /etc/systemd/system/amazon-cloudwatch-agent.service. 
Redirecting to /bin/systemctl restart amazon-cloudwatch-agent.service 
[root@AmazonLinux2 bin]#

 

 

 

次にコンフィグを指定して起動します。

■CloudWatch エージェントの起動(コンフィグを指定して起動する)

※しかしエラーが出力されてしまいました。

[root@AmazonLinux2 bin]# /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 
/opt/aws/amazon-cloudwatch-agent/bin/config-downloader --output-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --download-source file:/opt/aws/amazon-cloudwatch-agent/bin/config.json --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
Successfully fetched the config and saved in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp 
Start configuration validation... 
/opt/aws/amazon-cloudwatch-agent/bin/config-translator --input /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json --input-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --output /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
2019/09/16 14:38:47 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp ... 
Valid Json input schema. 
I! Detecting runasuser... 
No csm configuration found. 
Configuration validation first phase succeeded 
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -schematest -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml 
Configuration validation second phase failed 
======== Error Log ======== 
2019/09/16 14:38:47 I! AmazonCloudWatchAgent Version 1.227496.0. 
2019/09/16 14:38:47 E! Error parsing /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml, open /usr/share/collectd/types.db: no such file or directory 
[root@AmazonLinux2 bin]#

 

 

 

 

collectd のインストール

調べたところ collectd のインストールが必要のようです。

理由はエラーで「open /usr/share/collectd/types.db: no such file or directory」とエラーメッセージが出力されているからです。

 

■epel-release のインストール(失敗)

[root@AmazonLinux2 bin]# yum install epel-release 
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd 
amzn2-core                                  | 2.4 kB  00:00:00 
No package epel-release available. 
Error: Nothing to do 
 
 
epel-release is available in Amazon Linux Extra topic "epel" 
 
To use, run 
# sudo amazon-linux-extras install epel 
 
Learn more at 
https://aws.amazon.com/amazon-linux-2/faqs/#Amazon_Linux_Extras 
 
 
[root@AmazonLinux2 bin]#

 

 

 

■epel-release のインストール(成功)

[root@AmazonLinux2 bin]# amazon-linux-extras install epel 
Installing epel-release 
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd 
Cleaning repos: amzn2-core amzn2extra-docker amzn2extra-epel 
10 metadata files removed 
4 sqlite files removed 
0 metadata files removed 
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd 
amzn2-core                   | 2.4 kB  00:00:00 
amzn2extra-docker            | 1.3 kB  00:00:00 
amzn2extra-epel              | 1.3 kB  00:00:00 
(1/5): amzn2-core/2/x86_64/group_gz         | 2.4 kB  00:00:00 
(2/5): amzn2-core/2/x86_64/updateinfo       | 134 kB  00:00:00 
(3/5): amzn2extra-epel/2/x86_64/primary_db  | 1.8 kB  00:00:00 
(4/5): amzn2extra-docker/2/x86_64/primary_db  |  56 kB  00:00:00 
(5/5): amzn2-core/2/x86_64/primary_db       |  32 MB  00:00:00 
Resolving Dependencies 
--> Running transaction check 
---> Package epel-release.noarch 0:7-11 will be installed 
--> Finished Dependency Resolution 
 
Dependencies Resolved 
 
============================================================================ 
 Package           Arch         Version          Repository          Size 
============================================================================ 
Installing: 
 epel-release      noarch           7-11    amzn2extra-epel         15 k 
 
Transaction Summary 
============================================================================ 
Install  1 Package 
 
Total download size: 15 k 
Installed size: 24 k 
Is this ok [y/d/N]: y 
Downloading packages: 
epel-release-7-11.noarch.rpm                                                                                              |  15 kB  00:00:00 
Running transaction check 
Running transaction test 
Transaction test succeeded 
Running transaction 
  Installing : epel-release-7-11.noarch          1/1 
  Verifying  : epel-release-7-11.noarch          1/1 
 
Installed:   epel-release.noarch 0:7-11 
 
Complete! 
  0  ansible2                 available    [ =2.4.2  =2.4.6 ] 
  2  httpd_modules            available    [ =1.0 ] 
  3  memcached1.5             available    [ =1.5.1  =1.5.16 ] 
  4  nginx1.12                available    [ =1.12.2 ] 
  5  postgresql9.6            available    [ =9.6.6  =9.6.8 ] 
  6  postgresql10             available    [ =10 ] 
  8  redis4.0                 available    [ =4.0.5  =4.0.10 ] 
  9  R3.4                     available    [ =3.4.3 ] 
 10  rust1                    available    \ 
        [ =1.22.1  =1.26.0  =1.26.1  =1.27.2  =1.31.0 ] 
 11  vim                      available    [ =8.0 ] 
 13  ruby2.4                  available    [ =2.4.2  =2.4.4 ] 
 15  php7.2                   available    \ 
        [ =7.2.0  =7.2.4  =7.2.5  =7.2.8  =7.2.11  =7.2.13  =7.2.14 
          =7.2.16  =7.2.17  =7.2.19  =7.2.21 ] 
 16  php7.1                   available    \ 
        [ =7.1.22  =7.1.25  =7.1.27  =7.1.28  =7.1.30  =7.1.31 ] 
 17  lamp-mariadb10.2-php7.2  available    \ 
        [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5 
          =10.2.10_7.2.8  =10.2.10_7.2.11  =10.2.10_7.2.13 
          =10.2.10_7.2.14  =10.2.10_7.2.16  =10.2.10_7.2.17 
          =10.2.10_7.2.19  =10.2.10_7.2.21 ] 
 18  libreoffice              available    [ =5.0.6.2_15  =5.3.6.1 ] 
 19  gimp                     available    [ =2.8.22 ] 
 20  docker=latest            enabled      \ 
        [ =17.12.1  =18.03.1  =18.06.1 ] 
 21  mate-desktop1.x          available    [ =1.19.0  =1.20.0 ] 
 22  GraphicsMagick1.3        available    [ =1.3.29  =1.3.32 ] 
 23  tomcat8.5                available    \ 
        [ =8.5.31  =8.5.32  =8.5.38  =8.5.40  =8.5.42 ] 
 24  epel=latest              enabled      [ =7.11 ] 
 25  testing                  available    [ =1.0 ] 
 26  ecs                      available    [ =stable ] 
 27  corretto8                available    \ 
        [ =1.8.0_192  =1.8.0_202  =1.8.0_212  =1.8.0_222 ] 
 28  firecracker              available    [ =0.11 ] 
 29  golang1.11               available    \ 
        [ =1.11.3  =1.11.11  =1.11.13 ] 
 30  squid4                   available    [ =4 ] 
 31  php7.3                   available    \ 
        [ =7.3.2  =7.3.3  =7.3.4  =7.3.6  =7.3.8 ] 
 32  lustre2.10               available    [ =2.10.5 ] 
 33  java-openjdk11           available    [ =11 ] 
 34  lynis                    available    [ =stable ] 
 35  kernel-ng                available    [ =stable ] 
 36  BCC                      available    [ =0.x ] 
 37  mono                     available    [ =5.x ] 
[root@AmazonLinux2 bin]#

 

 

 

■collectd のインストール

[root@AmazonLinux2 bin]# yum install collectd

 

 

 

■collectd の自動起動の設定確認

[root@AmazonLinux2 bin]# systemctl list-unit-files | grep collectd
collectd.service        disabled
[root@AmazonLinux2 bin]#

 

 

 

■collectd の自動起動の設定

[root@AmazonLinux2 bin]# systemctl enable collectd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/collectd.service to /usr/lib/systemd/system/collectd.service.
[root@AmazonLinux2 bin]#

 

 

 

■collectd の自動起動の設定確認

[root@AmazonLinux2 bin]# systemctl list-unit-files | grep collectd
collectd.service       enabled
[root@AmazonLinux2 bin]#

 

 

 

■collectd の起動

[root@AmazonLinux2 bin]# systemctl start collectd.service

 

 

 

 

■collectd の起動確認

[root@AmazonLinux2 bin]# systemctl status collectd.service 
● collectd.service - Collectd statistics daemon 
   Loaded: loaded (/usr/lib/systemd/system/collectd.service; enabled; vendor preset: disabled) 
   Active: active (running) since Mon 2019-09-16 14:41:59 UTC; 6s ago 
     Docs: man:collectd(1) 
           man:collectd.conf(5) 
 Main PID: 3958 (collectd) 
   CGroup: /system.slice/collectd.service 
           mq3958 /usr/sbin/collectd 
 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
Sep 16 14:41:59 AmazonLinux2.ap-northeast-1.compute.internal collectd[3958]: Available write targets: [none] 
[root@AmazonLinux2 bin]#

 

 

 

■CloudWatch エージェントの起動(コンフィグを指定して起動する)

[root@AmazonLinux2 bin]# /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 
/opt/aws/amazon-cloudwatch-agent/bin/config-downloader --output-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --download-source file:/opt/aws/amazon-cloudwatch-agent/bin/config.json --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
Successfully fetched the config and saved in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp 
Start configuration validation... 
/opt/aws/amazon-cloudwatch-agent/bin/config-translator --input /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json --input-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --output /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
2019/09/16 14:42:17 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json.tmp ... 
Valid Json input schema. 
I! Detecting runasuser... 
No csm configuration found. 
Configuration validation first phase succeeded 
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -schematest -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml 
Configuration validation second phase succeeded 
Configuration validation succeeded 
Redirecting to /bin/systemctl stop amazon-cloudwatch-agent.service 
Redirecting to /bin/systemctl restart amazon-cloudwatch-agent.service 
[root@AmazonLinux2 bin]#

 

 

 

※失敗パターン

■CloudWatch エージェントの起動(以下のコマンドだけだとコンフィグを読んでくれないのでログ取得ができない)

[root@AmazonLinux2 bin]# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a start 
amazon-cloudwatch-agent is not configured. Applying default configuration before starting it. 
/opt/aws/amazon-cloudwatch-agent/bin/config-downloader --output-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --download-source default --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
Successfully fetched the config and saved in /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/default.tmp 
Start configuration validation... 
/opt/aws/amazon-cloudwatch-agent/bin/config-translator --input /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json --input-dir /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d --output /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml --mode ec2 --config /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml --multi-config default 
2019/09/16 06:47:14 Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/default.tmp ... 
Valid Json input schema. 
I! Detecting runasuser... 
No csm configuration found. 
No log configuration found. 
Configuration validation first phase succeeded 
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -schematest -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml 
Configuration validation second phase succeeded 
Configuration validation succeeded 
Created symlink from /etc/systemd/system/multi-user.target.wants/amazon-cloudwatch-agent.service to /etc/systemd/system/amazon-cloudwatch-agent.service. 
Redirecting to /bin/systemctl restart amazon-cloudwatch-agent.service 
[root@AmazonLinux2 bin]#

上記コマンドではコンフィグ(/opt/aws/amazon-cloudwatch-agent/bin/config.json)を指定していないためか CloudWatch ログを取得できませんでした。

 

 

■原因

amazon-cloudwatch-agent-config-wizard コマンドで設定を作りますが、その後失敗したパターンのように単純に「amazon-cloudwatch-agent」エージェントを起動しただけでは、直前に amazon-cloudwatch-agent-config-wizard コマンドで設定した値が反映されません。

そのため、一度「/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 」コマンドで設定を読み込む必要があります。

このコマンドで「/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml」「/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/file_config.json」が更新されます。

 

 

再度 CloudWatch エージェントのステータスを確認します。

■CloudWatch エージェントのステータス確認

[root@AmazonLinux2 bin]# /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status 

  "status": "running", 
  "starttime": "2019-09-16T06:47:14+0000", 
  "version": "1.227496.0" 

[root@AmazonLinux2 bin]#

 

 

 

amazon-cloudwatch-agent-ctl コマンド

■amazon-cloudwatch-agent-ctl コマンドのヘルプ

[root@AmazonLinux2 ~]# amazon-cloudwatch-agent-ctl -help 
 
 usage: amazon-cloudwatch-agent-ctl -a stop|start|status|fetch-config|append-config|remove-config [-m ec2|onPremise|auto] [-c default|ssm:|file:] [-s] 
 
 e.g. 
 1. apply a SSM parameter store config on EC2 instance and restart the agent afterwards: 
     amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-Config.json -s 
 2. append a local json config file on onPremise host and restart the agent afterwards: 
     amazon-cloudwatch-agent-ctl -a append-config -m onPremise -c file:/tmp/config.json -s 
 3. query agent status: 
     amazon-cloudwatch-agent-ctl -a status 
 
  -a: action 
      stop:                    stop the agent process. 
      start:                   start the agent process. 
      status:                  get the status of the agent process. 
      fetch-config:            use this json config as the agent's only configuration. 
                               このjson configをエージェントの唯一の構成として使用します。
      append-config:           append json config with the existing json configs if any. 

                               既存のjson構成があれば、json構成を追加します。
      remove-config:           remove json config based on the location (ssm parameter store name, file name) 

                               場所(ssmパラメーターストア名、ファイル名)に基づいてjson構成を削除します
 
  -m: mode 
      ec2:                     indicate this is on ec2 host. 

                               これがec2ホスト上にあることを示します。
      onPremise:               indicate this is on onPremise host. 

                               これがオンプレミスホスト上にあることを示します。
      auto:                    use ec2 metadata to determine the environment, may not be accurate if ec2 metadata is not available for some reason on EC2. 

                              ec2メタデータを使用して環境を決定します。EC2で何らかの理由でec2メタデータが利用できない場合、正確でない可能性があります。
 
  -c: configuration 
      default:                 default configuration for quick trial. 

                               クイックトライアル用のデフォルト設定。
      ssm::                    ssm parameter store name 

                               ssmパラメーターストア名
      file::                   file path on the host 
                               ホスト上のファイルパス
  -s: optionally restart after configuring the agent configuration 
      this parameter is used for 'fetch-config', 'append-config', 'remove-config' action only. 

   オプションで、エージェント構成の構成後に再起動します。
   このパラメーターは、「fetch-config」、「append-config」、「remove-config」アクションにのみ使用されます。

 
 
[root@AmazonLinux2 ~]#

 

 

 

 

ログ監視確認

CloudWatch のダッシュボードに移動し左側ペインより「ログ」をクリックします。

【AWS】【AmazonLinux2】CloudWatch エージェントでログ監視をする設定手順【awslogsd】

 

 

 

 

対象のロググループ(今回の場合は messages)をクリックします。

 

 

 

 

対象のインスタンスIDをクリックします。

 

 

 

 

下図のようにログが取得できていることを確認します。

 

 

 

 

Posted by 100%レンタルサーバーを使いこなすサイト管理人

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

AlphaOmega Captcha Medica  –  What Do You See?
     
 

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

Secured By miniOrange