-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2_cpucreditbalance
executable file
·55 lines (42 loc) · 1.46 KB
/
ec2_cpucreditbalance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# AWS CloudWatch から EC2/CPUCreditBalance の値を取得します。
# t2.* 系のインスタンス以外は無意味かも
# Parameters:
# config (required)
# autoconf (optional - used by munin-config)
#%# family=manual
#%# capabilities=autoconf
instance_id=${instanceid-""}
aws_credential_file=${credentialfile-""}
aws_region=${region-"ap-northeast-1"}
export AWS_REGION=$aws_region
export JAVA_HOME=/usr/lib/jvm/jre
export AWS_CLOUDWATCH_HOME=/opt/aws/apitools/mon
export AWS_CLOUDWATCH_URL=https://monitoring.${AWS_REGION}.amazonaws.com
export PATH=$PATH:$HOME/bin:$AWS_CLOUDWATCH_HOME/bin
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
if [ "$1" = "config" ]; then
echo "graph_title EC2 CPUCreditBalance"
echo 'graph_args --lower-limit 0'
echo 'graph_vlabel CPUCreditBalance'
echo 'graph_scale no'
echo 'graph_category AWS'
echo 'graph_info This graph shows the EC2 CPUCreditBalance'
echo "CPUCreditBalance.label $instance_id"
echo "CPUCreditBalance.draw LINE2"
echo "CPUCreditBalance.info The average EC2 CPU Credit Balance"
echo "CPUCreditBalance.min 0"
exit 0
fi
if [ "$instance_id" = "" ]; then
exit 0
fi
if [ "$aws_credential_file" = "" ]; then
exit 0
fi
stats=`/opt/aws/bin/mon-get-stats CPUCreditBalance --namespace "AWS/EC2" --statistics "Average" --unit "Count" --dimensions "InstanceId=$instance_id" --aws-credential-file "$aws_credential_file" | tail -n 1 | awk '{printf "%.2f", $3}'`
echo -n "CPUCreditBalance.value "
echo $stats