Re: instance monitoring

255 views
Skip to first unread message
Message has been deleted
Message has been deleted

samuelololol

unread,
Oct 23, 2012, 5:02:53 AM10/23/12
to boto-...@googlegroups.com
end = datetime.datetime.utcnow()


use UTC time, in my case, it works!

On Saturday, September 29, 2012 7:36:04 AM UTC+8, Belred wrote:
I have some instances, auto scaling groups, elastic load balances, SQS, DynamoDB, S3, etc.  In the AWS Console, I can view many metrics.  such as CPUUtilization, etc.  According to the boto documentation,  list_metrics() will only return a metric for which there is data. I then printed each metric (which there was at least 100), and then queried for each metric statistics. In every case, the data result that came back was emply.   I also tried calling get_metric_statistics() and got the same empty data results.  Am I missing a step?

import boto.ec2.cloudwatch as cw

cw_conn = cw.connect_to_region(AWS_REGION, aws_access_key_id=AWSAccessKeyId,
                                                                                           aws_secret_access_key=AWSSecretKey)

metrics = cw_conn.list_metrics()

end = datetime.datetime.now()
start = end - datetime.timedelta(days=1)

for m in metrics:
    data = m.query(start, end, m.Statistics)
    print m.name, m.dimensions, m.namespace
    print data
    print '---------'


Mitchell Garnaat

unread,
Oct 23, 2012, 8:36:19 AM10/23/12
to boto-...@googlegroups.com
Hi -

Perhaps I'm misunderstanding what you are trying to do but if you want to find the CPUUtilization metric for a particular instance, the easiest approach is to filter the metrics based on that.  So, this:

import boto.ec2.cloudwatch
import datetime

cw = boto.ec2.cloudwatch.connect_to_region('ap-northeast-1')

metric = cw.list_metrics(dimensions={'InstanceId': 'i-xxxxxxxx'}, metric_name='CPUUtilization')[0]

The variable metric will now contain the CPUUtilization metric for that particular instance.

Secondly, your timestamps should be UTC.  So, instead of doing this:

end = datetime.datetime.now()

You should be doing this:

end = datetime.datetime.utcnow()

I have tried this locally and the call to query returns the expected data.

Mitch

On Tue, Oct 23, 2012 at 1:35 AM, samuelololol <samue...@gmail.com> wrote:
I have the same question,
I have instance in region: 'ap-northeast-1'
and it goes with the detailed monitering enabled.

But I got nothing return


here is my ez-testing code


<code>
import boto.ec2.cloudwatch
import datetime
cw = boto.ec2.cloudwatch.connect_to_region('ap-northeast-1')
metrics = cw.list_metrics(metric_name = 'CPUUtilization')

x = 0
z = int()
for i in metrics:
    for j in i.__dict__['dimensions'].values():
        if j[0] == <instance name>:
            z = x
    x = x + 1

end = datetime.datetime.now()
start = end - datetime.timedelta(minutes=30)
my = ['Average', 'Sum', 'Maximum', 'Minimum']
data = metrics[z].query(start_time=start, end_time=end, 
                             statistics=my, unit='Percent', 
                             period=60)
print len(data)
</code>


my output
<output>
0
</output>

--
You received this message because you are subscribed to the Google Groups "boto-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/boto-users/-/ijwjhTJZJVoJ.

To post to this group, send email to boto-...@googlegroups.com.
To unsubscribe from this group, send email to boto-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/boto-users?hl=en.

Reply all
Reply to author
Forward
0 new messages