Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Let's say my application publishes AWS CloudWatch metrics with a single dimension. The value of that dimension can be any string. Then, in any given time interval, I'll have something like this:

(myDimension: "foo", value: 12)
(myDimension: "bar", value: 5)
(myDimension: "foo", value: 99)
(myDimension: "quux", value: 42)

Now I want to create an alarm based on a metric derived from this. I want to ignore the values and only count the unique occurrences of each dimension. In this case, the value would be 3 -- 1 for "foo" (even though it appeared twice), 1 for "bar" and 1 for "quux".

How can I do that? I've looked at the Metric Math documentation, but I didn't find any function that could help me. The one that seems to get close is IF, but I'm not sure if I can use it to solve this problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.9k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can do it using CloudWatch Insights https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html

Create a query similar to this:

parse @message '*(myDimension: "*"*' as f1, myDimensionKey, f2
| filter @message like '(myDimension:'
| stats count(*) by myDimensionKey

And add the result to a dashboard. This would display a table with the distinct keys and the number of occurrences


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...