三歩あるけば物も忘れる

お腹のお肉がメタボックル

ユーザ用ツール

サイト用ツール


Aws:Cloudwatch:InstallCloudWatchAgent-Linux

CloudWatchAgentのインストール-Linux

Redhat8.xを例にインストール手順を記載します。

インストール

CloudWatchAgentのインストール

https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-commandline-fleet.html

cd /tmp
curl -OL https://s3.ap-northeast-1.amazonaws.com/amazoncloudwatch-agent-ap-northeast-1/redhat/amd64/latest/amazon-cloudwatch-agent.rpm
rpm -ivh ./amazon-cloudwatch-agent.rpm

collectdのインストール

# EPELレポジトリの追加
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install collectd

コマンドメモ

Linux

# wizardの開始
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

# EC2
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:config.json   #「-s」はcloudwatch-agentの停止/開始するオプション
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:AmazonCloudWatch-xxxxx

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a stop
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a start

# オンプレ
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -c file:config.json   #「-s」はcloudwatch-agentの停止/開始するオプション
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -c ssm:AmazonCloudWatch-xxxxx

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m onPremise -a stop
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m onPremise -a status
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m onPremise -a start

デフォルト参照先[/root/.aws]配下の資格情報を読み込んでくれない場合の対処法

vi /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml

###変更前###
# [credentials]
#    shared_credential_profile = "{profile_name}"
#    shared_credential_file = "{file_name}"

###変更後###
[credentials]
shared_credential_profile = "default"
#    shared_credential_file = "{file_name}"

wizard

メトリクス関連


=============================================================
= Welcome to the AWS CloudWatch Agent Configuration Manager =
=============================================================
# OSを選択します。
On which OS are you planning to use the agent?
1. linux
2. windows
3. darwin
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]:

# StatsDの使用を選択します。https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-custom-metrics-statsd.html
Do you want to turn on StatsD daemon?
1. yes
2. no
default choice: [1]:

# StatsDのポートを指定します。
Which port do you want StatsD daemon to listen to?
default choice: [8125]

# StatsDの収集間隔を選択します。
What is the collect interval for StatsD daemon?
1. 10s
2. 30s
3. 60s
default choice: [1]:

# StatsDのメトリクス間隔を選択します。
What is the aggregation interval for metrics collected by StatsD daemon?
1. Do not aggregate
2. 10s
3. 30s
4. 60s
default choice: [4]:

# メトリクス収集にCollectDを利用するか選択します。
Do you want to monitor metrics from CollectD?
1. yes
2. no
default choice: [1]:

# CPUやメモリのメトリクスを収集するか選択します。
Do you want to monitor any host metrics? e.g. CPU, memory, etc.
1. yes
2. no
default choice: [1]:

# コアあたりのCPUを監視するか選択します。
Do you want to monitor cpu metrics per core? Additional CloudWatch charges may apply.
1. yes
2. no
default choice: [1]:

# メトリクスの画面にディメンション(ImageId, InstanceId, InstanceType, AutoScalingGroupName)を追加するか選択します。
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 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]:

# メトリクスの事前定義されたメトリクスセットを選択します。https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/monitoring/create-cloudwatch-agent-configuration-file-wizard.html
Which default metrics config do you want?
1. Basic
2. Standard
3. Advanced
4. None
default choice: [1]:

# 上記設定で良いかの確認です。
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]:

ログ関連

# 既存のCloudWatchLogAgentがあるかの確認です。
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]:

# モニターするログがあるかの確認です。
Do you want to monitor any log files?
1. yes
2. no
default choice: [1]:

# ファイルパスを指定します。
Log file path:

# ロググループ名を指定します。
Log group name:
default choice: [.]

# ログストリーム名を指定します。
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]:

パラメータストア関連

# /opt/aws/amazon-cloudwatch-agent/bin/config.jsonにコンフィグを保存しました。
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]:

# パラメータストアに保存するパラメータ名の確認です。※AmazonCloudWatch-XXXX形式で入力してください。
What parameter store name do you want to use to store your config? (Use 'AmazonCloudWatch-' prefix if you use our managed AWS policy)
default choice: [AmazonCloudWatch-linux]

# パラメータストアのリージョンの確認です。
Which region do you want to store the config in the parameter store?
default choice: [ap-northeast-1]

# Credentialの確認です。
Which AWS credential should be used to send json config to parameter store?
1. XXXXXXXXXXXXXXXXXXXX(From SDK)
2. Other
default choice: [1]:

Aws/Cloudwatch/InstallCloudWatchAgent-Linux.txt · 最終更新: 2021/03/07 by 127.0.0.1