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