-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2_cpuutilization
executable file
·55 lines (42 loc) · 1.42 KB
/
ec2_cpuutilization
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/CPUUtilization の値を取得します。
# 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 CPUUtilization"
echo 'graph_args --lower-limit 0'
echo 'graph_vlabel CPUUtilization'
echo 'graph_scale no'
echo 'graph_category AWS'
echo 'graph_info This graph shows the average EC2 CPUUtilization'
echo "CPUUtilization.label $instance_id"
echo "CPUUtilization.draw LINE2"
echo "CPUUtilization.info The average EC2 CPU Utilization"
echo "CPUUtilization.min 0"
echo "CPUUtilization.max 100"
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 CPUUtilization --namespace "AWS/EC2" --statistics "Average" --unit "Percent" --dimensions "InstanceId=$instance_id" --aws-credential-file "$aws_credential_file" | tail -n 1 | awk '{printf "%.2f", $3}'`
echo -n "CPUUtilization.value "
echo $stats