Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cloudwatch Metrics - How to Format a Number in Dashboard Metric to more than two decimal places

I'm building a metric for the success rate of my API gateway and I'm trying to get more that 1-2 decimal places. I want to make sure that less than 99.9999% are successful. (Ultimately to set an alarm), but I would like to show this detail in the dashboard.

Is there some kind of value formatting syntax available. I have been digging around in the docs and haven't found anything.

{
    "metrics": [
        [ { "expression": "100*(1-(m1+m2/m3))", "label": "Success Rate", "id": "e1" } ],
        [ "AWS/ApiGateway", "4XXError", "ApiName", "my_webhook_api", "Stage", "prod", { "id": "m1", "visible": false } ],
        [ ".", "5XXError", ".", ".", ".", ".", { "id": "m2", "visible": false } ],
        [ ".", "Count", ".", ".", ".", ".", { "id": "m3", "visible": false } ]
    ],
    "view": "singleValue",
    "region": "us-west-2",
    "stat": "Sum",
    "period": 2592000,
    "setPeriodToTimeRange": true
}

Basically, I want the picture below to say 99.8XXXXX (6 decimal places)

AWS Metric Widget Should say 99.8xxxxx

like image 494
tim.breeding Avatar asked Nov 06 '22 09:11

tim.breeding


2 Answers

You should be able to accomplish this with Metric Math. Multiply by 1000000 FLOOR the result to get an integer then divide by 1000000 to get a floating point number again.

FLOOR(1000000*(100*(1-(m1+m2/m3))))/1000000)
like image 176
ayvazj Avatar answered Nov 15 '22 05:11

ayvazj


In the new-style CloudWatch UI (activated by the "Try out the new interface" link in the top-right corner) there's an Options tab where there's an option to "Show as many digits as can fit, before rounding", see the screenshot: CloudWatch Number graph options

As an alternative, open the Source tab and add the following option to the top-level object (in the provided example this can be after the line with setPeriodToTimeRange): "singleValueFullPrecision": true.

This doesn't let you control the number of decimal digits, but achieves the goal of displaying numbers with high precision.

like image 36
dskrvk Avatar answered Nov 15 '22 07:11

dskrvk