I am querying GetMetricsData
from AWS CloudWatch:
{
StartTime: lastWeek ,
EndTime: today,
MetricDataQueries: [
{
Id: 'invocations',
Label: 'Invocations',
MetricStat: {
Metric: {
Dimensions: [
{
Name: 'FunctionName',
Value: /* FunctionName */,
},
],
MetricName: 'Invocations',
Namespace: 'AWS/Lambda'
},
Period: 60*60*24, // day
Stat: 'Sum',
Unit: 'Count',
},
},
],
}
This is what I get:
Instead of getting data for 7 days (i.e. a week) I get 5 days. I have 2 missing days (as you can see in the graph).
Those missing days did not have any data.
CloudWatch is not returning points which have no data. How can I make the Sum
operation return the actual count (0
) instead?
You can use metric math and FILL function to default missing values to 0.
Id of your metric is
invocations
so the expression would be:Full query would be something like:
This will return 2 metrics, with zeros and without. You can then hide the original metric by setting
ReturnData: false
in that MetricDataQuery.See here for more details:
https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html