AWS CloudWatch custom metric publishing example

1

1

I'm badly struggling with publishing a custom metric into AWS CloudWatch. The problem is that my metric 'testmetric' is not showing up on the CloudWatch UI. I might be missing the part on the UI where the metric should be visible, or I might not enable something somewhere... Clueless

I tried with Boto (python package boto==2.8.0)

from boto.ec2.cloudwatch import CloudWatchConnection
cwc = CloudWatchConnection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
cwc.put_metric_data(**{
    "namespace" : "testns",
    "name" : "testmetric",
    "unit" : "Count",
    "value" : 3
})

Also tried this simple module from loggly: https://github.com/loggly/loggly-watch/blob/master/cloudwatch.py

Thx

Vajk Hermecz

Posted 2014-02-21T09:02:36.473

Reputation: 121

What is the problem exactly? – Guy – 2014-02-22T07:15:09.650

Added the problem. Dammit, how could I left it out... o_O thx – Vajk Hermecz – 2014-02-22T09:13:22.933

Answers

0

If region is not provided for the CloudWatchConnection, it automatically picks up us-east-1, the metric should be available there.

Also be careful with getting your region, as of boto v2.27.0, boto.ec2.get_region("us-west-1") returns CloudWatchConnection:ec2.us-west-1.amazonaws.com while you would need CloudWatchConnection:monitoring.us-west-1.amazonaws.com. Use something like the code below instead:

for r in boto.ec2.cloudwatch.regions():
    if (r.name == 'us-west-1'):
        region = r

The AWS UI should either show the metric if you filter for it by name, of it can be reached through selecting your custom namespace from the dropdown:

enter image description here

Vajk Hermecz

Posted 2014-02-21T09:02:36.473

Reputation: 121

3

You're passing the arguments to put_metric_data incorrectly. You are passing them as a single dictionary, while they should be individual arguments like this:

cwc.put_metric_data(namespace="testns",name="testmetric",unit="Count",value=3.0)

Also, value should be a float, as seen above, and not an integer.

uberdog

Posted 2014-02-21T09:02:36.473

Reputation: 131

Thanks for your notes, yeah, I made a typo there with the dict. fixed. – Vajk Hermecz – 2014-04-30T07:48:21.037