I have a metrics map coming from different applications and I want to write them into AWSCloud watch.
How can I do that?
PS: I tried putting them using metrics name and metrics value after parsing whole map, but that does not looks a good approach to me.
Thanks!
Cloudwatch should easily be able to keep up with your metric volume so I would just use 1
PutMetricDataRequest
for each batch coming in from the source applications and let Cloudwatch do the aggregation.If you look at
PutMetricDataRequest
it takes aCollection<MetricDatum>
which is well suited to receive any number of keys you're receiving from the source applications in a single request.====
Converting a HashMap to a List is pretty straightforward with the Java8 streams API:
Assuming your map is a key => value map:
You can use the Java8 streams API with map and collect: