Although you cannot publish a StatisticSet
with a sampleCount
of 0, you can publish it with an extremely small sampleCount
since it is a double
. We have found that a sampleCount
of 0.000000001
seems to give the appearance of 0 on the graphs but it still fills in the holes in the graph appropriately and does not cause the INSUFFICIENT_DATA
alarms to happen.
double sampleCount = numSamples;
// our values come in as value and numSamples but StatisticSet wants a sum
double sum = value * numSamples;
if (numSamples == 0) {
// special case here, CloudWatch does not allow a 0 sample count so we have to
// set it to be slightly more
sampleCount = 0.000000001D;
// but sum can be 0
}
StatisticSet statisticSet =
new StatisticSet().withMinimum(min)
.withMaximum(max)
.withSampleCount(sampleCount)
.withSum(sum);
As an aside, I've coded some of this logic into my SimpleMetrics library which is designed to easily track and publish metrics.