Search code examples
amazon-cloudwatch

Cloudwatch includes all the metrics in a namespace?


I have a custom Namespace on Cloudwatch that contains a list of metrics.

The metric name is the IP of each of the servers connecting to mine, and this can change over time, with new ones coming, older not connecting during a time frame, etc.

What I'm trying to have is a graph that shows all the metrics inside that namespace by including the new arriving ones automatically and setting at 0 the ones that aren't present at a specific timeframe.

(For instance, if IP 1.2.3.4 connects at 9:01, 9:02 but not 9:03, 9:04 then reconnects at 9:05, the graph will show 0 for 9:03 and 9:04 for that IP. If a new IP arrives at 9:05, it will be added automatically in the graph).

Is it possible to do that? How can I do? I haven't found how on Cloudwatch so far.


Solution

  • The answer depends on how many metrics you have in the namespace.

    1. Dashboard Widget can show a maximum of 500 metrics (docs). If you have less than 500 metrics in the namespace, you can simply use the metric math SEARCH and FILL functions like this:

      "FILL(SEARCH('{YOUR_NAMESPACE}', 'Average', 300), 0)"

    SEARCH will fetch the metrics and FILL will default the values to 0 for intervals that don't have datapoints present. Also, if a metric didn't receive new datapoints in over two weeks, it won't be returned by the search.

    1. If you have between 500 and 2500 metrics in the namespace (limit is 500 metrics per widget and 2500 metrics per dashboard), you could potentialy split IP ranges into multiple graphs with SEARCH expressions like this:

      "FILL(SEARCH('{YOUR_NAMESPACE} MetricName="1.2', 'Average', 300), 0)"

    This will include all metrics for IPs starting with 1.2 in one graph. You would then need to create similar graphs for different ranges.

    1. You can still use CloudWatch to graph more than 2500 metrics on a graph/dashboard, but then you need to write custom widgets. You would need to write a lambda function that would fetch all of the datapoints from every metric in the namespace and render the graph using something like Matplotlib.