Question

I have a custom cloud watch metric with unit Seconds. (representing the age of a cache)

As usual values are around 125,000 I'd like to convert them into Hours - for better readability.

Is that possible?

Was it helpful?

Solution 2

Cloudwatch does not do any Unit conversion (i.e seconds into hours etc). So you cannot use the AWS console to display your 'Seconds' datapoint values converted to Hours.

You could either publish your metric values as 'Hours' (leaving the Unit field blank or set it to 'None').

Otherwise if you still want to provide the datapoints with units 'Seconds' you could retrieve the datapoints (using the GetMetricStatistics API) and graph the values using some other dashboard/graphing solution.

OTHER TIPS

This has changed with the addition of Metrics Math. You can do all sorts of transformations on your data, both manually (from the console) and from CloudFormation dashboard templates.


From the console: see the link above, which says:

To add a math expression to a graph

  1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

  2. Create or edit a graph or line widget.

  3. Choose Graphed metrics.

  4. Choose Add a math expression. A new line appears for the expression.

  5. For the Details column, type the math expression. The tables in the following section list the functions you can use in the expression.

    To use a metric or the result of another expression as part of the formula for this expression, use the value shown in the Id column. For example, m1+m2 or e1-MIN(e1).


From a CloudFormation Template

You can add new metrics which are Metrics Math expressions, transforming existing metrics. You can add, subtract, multiply, etc. metrics and scalars. In your case, you probably just want to use divide, like in this example:

Say you have the following bucket request latency metrics object in your template:

"metrics":[
  ["AWS/S3","TotalRequestLatency","BucketName","MyBucketName"]
]

The latency default is in milliseconds. Let's plot it in seconds, just for fun. 1s = 1,000ms so we'll add the following:

"metrics":[
  ["AWS/S3","TotalRequestLatency","BucketName","MyBucketName",{"id": "timeInMillis"}],
  [{"expression":"timeInMillis / 1000", "label":"LatencyInSeconds","id":"timeInSeconds"}]
]

Note that the expression has access to the ID of the other metrics. Helpful naming can be useful when things get more complicated, but the key thing is just to match the variables you put in the expression to the ID you assign to the corresponding metric.

This leaves us with a graph with two metrics on it: one milliseconds, the other seconds. If we want to lose the milliseconds, we can, but we need to keep the metric values around to compute the math expression, so we use the following work-around:

"metrics":[
  ["AWS/S3","TotalRequestLatency","BucketName","MyBucketName",{"id": "timeInMillis","visible":false}],
  [{"expression":"timeInMillis / 1000", "label":"LatencyInSeconds","id":"timeInSeconds"}]
]

Making the metric invisible takes it off the graph while still allowing us to compute our expression off of it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top