0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ZabbixでCloudWatchの値を監視する

Last updated at Posted at 2023-10-30

zabbix-agent側の設定

zabbixユーザー用の.bash_profile(無ければ作る)に下記を追加

vi /var/lib/zabbix/.bash_profile
-----
export AWS_ACCESS_KEY_ID=**********
export AWS_SECRET_ACCESS_KEY=**********
export AWS_DEFAULT_REGION=**********
-----

ELB(ALB) 「ELB_5XX」の監視

1.監視用スクリプト

vi /var/lib/zabbix/HTTPCode_ELB_5XX_Count.sh
-----------------------------------------
#!/bin/bash

source /var/lib/zabbix/.bash_profile

START_DATE=`date "+%Y-%m-%dT%H:%M:00Z" -d '6 minutes ago' --utc`
END_DATE=`date "+%Y-%m-%dT%H:%M:59Z" -d '1 minutes ago' --utc`

error_count=$(aws cloudwatch get-metric-statistics \
--namespace AWS/ApplicationELB \
--metric-name HTTPCode_ELB_5XX_Count \
--statistics Sum \
--period 60 \
--dimensions Name=LoadBalancer,Value=app/*****/***** \
--start-time $START_DATE \
--end-time $END_DATE \
--query "reverse(sort_by(Datapoints,&Timestamp))[?Sum>\`0\`][Sum]" \
--output text | head -n 1)

if [ -z "$error_count" ]; then
	error_count=0
fi

echo -n $error_count
-----------------------------------------

※直近5分間の最大値を取得
※--dimensionsのValueは環境に合わせて変更

2.zabbix-agentの設定

vi /etc/zabbix/zabbix_agentd.d/userparameter_HTTPCode_ELB_5XX_Count.conf
-----------------------------------------
UserParameter=HTTPCode_ELB_5XX_Count.HTTPCode_ELB_5XX_Count,HOME=/var/lib/zabbix /bin/bash /var/lib/zabbix/HTTPCode_ELB_5XX_Count.sh
-----------------------------------------

RDS 「BurstBalance」の監視

1.監視用スクリプト

vi /var/lib/zabbix/RDS_BurstBalance_Average.sh
-----------------------------------------
#!/bin/bash

source /var/lib/zabbix/.bash_profile

START_DATE=`date "+%Y-%m-%dT%H:%M:00Z" -d '6 minutes ago' --utc`
END_DATE=`date "+%Y-%m-%dT%H:%M:59Z" -d '1 minutes ago' --utc`

average_percent=$(aws cloudwatch get-metric-statistics \
--namespace AWS/RDS \
--metric-name BurstBalance \
--statistics Average \
--period 300 \
--dimensions Name=DBInstanceIdentifier,Value=***** \
--start-time $START_DATE \
--end-time $END_DATE \
--output text | awk '{print $2}')

if [ -z "$average_percent" ]; then
	average_percent=99
fi

echo -n $average_percent
-----------------------------------------

※直近5分間の平均値を取得
※--dimensionsのValueは環境に合わせて変更

2.zabbix-agentの設定

vi /etc/zabbix/zabbix_agentd.d/userparameter_RDS_BurstBalance_Average.conf
-----------------------------------------
UserParameter=RDS_BurstBalance_Average.RDS_BurstBalance_Average,HOME=/var/lib/zabbix /bin/bash /var/lib/zabbix/RDS_BurstBalance_Average.sh
-----------------------------------------

RDS 「CPUUtilization」の監視

1.監視用スクリプト

vi /var/lib/zabbix/RDS_CPUUtilization_Average.sh
-----------------------------------------
#!/bin/bash

source /var/lib/zabbix/.bash_profile

START_DATE=`date "+%Y-%m-%dT%H:%M:00Z" -d '6 minutes ago' --utc`
END_DATE=`date "+%Y-%m-%dT%H:%M:59Z" -d '1 minutes ago' --utc`

average_percent=$(aws cloudwatch get-metric-statistics \
--namespace AWS/RDS \
--metric-name CPUUtilization \
--statistics Average \
--period 300 \
--dimensions Name=DBInstanceIdentifier,Value=***** \
--start-time $START_DATE \
--end-time $END_DATE \
--output text | awk '{print $2}')

if [ -z "$average_percent" ]; then
	average_percent=0
fi

echo -n $average_percent
-----------------------------------------

※直近5分間の平均値を取得
※--dimensionsのValueは環境に合わせて変更

2.zabbix-agentの設定

vi /etc/zabbix/zabbix_agentd.d/userparameter_RDS_CPUUtilization_Average.conf
-----------------------------------------
UserParameter=RDS_CPUUtilization_Average.RDS_CPUUtilization_Average,HOME=/var/lib/zabbix /bin/bash /var/lib/zabbix/RDS_CPUUtilization_Average.sh
-----------------------------------------

RDS 「DatabaseConnections」の監視

1.監視用スクリプト

vi /var/lib/zabbix/RDS_DatabaseConnections_Maximum.sh
-----------------------------------------
#!/bin/bash

source /var/lib/zabbix/.bash_profile

START_DATE=`date "+%Y-%m-%dT%H:%M:00Z" -d '6 minutes ago' --utc`
END_DATE=`date "+%Y-%m-%dT%H:%M:59Z" -d '1 minutes ago' --utc`

maximum=$(aws cloudwatch get-metric-statistics \
--namespace AWS/RDS \
--metric-name DatabaseConnections \
--statistics Maximum \
--period 60 \
--dimensions Name=DBInstanceIdentifier,Value=***** \
--start-time $START_DATE \
--end-time $END_DATE \
--query "reverse(sort_by(Datapoints,&Timestamp))[?Maximum>\`0\`][Maximum]" \
--output text  | head -n 1)

if [ -z "$maximum" ]; then
	maximum=0
fi

echo -n $maximum
-----------------------------------------

※直近5分間の最大値を取得
※--dimensionsのValueは環境に合わせて変更

2.zabbix-agentの設定

vi /etc/zabbix/zabbix_agentd.d/userparameter_RDS_DatabaseConnections_Maximum.conf
-----------------------------------------
UserParameter=RDS_DatabaseConnections_Maximum.RDS_DatabaseConnections_Maximum,HOME=/var/lib/zabbix /bin/bash /var/lib/zabbix/RDS_DatabaseConnections_Maximum.sh
-----------------------------------------

オーナーを変更

chown -R zabbix:zabbix /var/lib/zabbix

zabbix-agentの再起動

systemctl restart zabbix-agent

zabbixの設定

アイテム(HTTPCode_ELB_5XX_Count)の追加

2023-10-30 13_48_01-.png

アイテム(RDS_BurstBalance_Average)の追加

2023-10-30 13_09_20-zabbix.ca-ret.co.jp_ アイテムの設定 — Mozilla Firefox.png

アイテム(RDS_CPUUtilization_Average)の追加

2023-10-30 13_10_43-zabbix.ca-ret.co.jp_ アイテムの設定 — Mozilla Firefox.png

アイテム(RDS_DatabaseConnections_Maximum)の追加

2023-10-30 13_11_47-zabbix.ca-ret.co.jp_ アイテムの設定 — Mozilla Firefox.png

トリガー(HTTPCode_ELB_5XX_Count)の追加

2023-10-30 13_13_07-zabbix.ca-ret.co.jp_ トリガーの設定 — Mozilla Firefox.png
※最新の取得値が0より大きければアラートを出す

トリガー(RDS_BurstBalance_Average)の追加

2023-10-30 13_14_27-zabbix.ca-ret.co.jp_ トリガーの設定 — Mozilla Firefox.png
※最新の取得値が50(%)未満になったらアラートを出す

トリガー(RDS_CPUUtilization_Average)の追加

2023-10-30 13_18_03-zabbix.ca-ret.co.jp_ トリガーの設定 — Mozilla Firefox.png
※最新の取得値が60(%)を超えたらアラートを出す

トリガー(RDS_CPUUtilization_Average)の追加

2023-10-30 13_19_25-zabbix.ca-ret.co.jp_ トリガーの設定 — Mozilla Firefox.png
※最新の取得値が2000を超えたらアラートを出す

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?