listMetrics method
List the specified metrics. You can use the returned metrics with GetMetricData or GetMetricStatistics to get statistical data.
Up to 500 results are returned for any one call. To retrieve additional results, use the returned token with subsequent calls.
After you create a metric, allow up to 15 minutes for the metric to appear. To see metric statistics sooner, use GetMetricData or GetMetricStatistics.
If you are using CloudWatch cross-account observability, you can use this operation in a monitoring account and view metrics from the linked source accounts. For more information, see CloudWatch cross-account observability.
ListMetrics doesn't return information about metrics if those
metrics haven't reported data in the past two weeks. To retrieve those
metrics, use GetMetricData
or GetMetricStatistics.
May throw InternalServiceFault.
May throw InvalidParameterValueException.
Parameter dimensions :
The dimensions to filter against. Only the dimension with names that match
exactly will be returned. If you specify one dimension name and a metric
has that dimension and also other dimensions, it will be returned.
Parameter includeLinkedAccounts :
If you are using this operation in a monitoring account, specify
true to include metrics from source accounts in the returned
data.
The default is false.
Parameter metricName :
The name of the metric to filter against. Only the metrics with names that
match exactly will be returned.
Parameter namespace :
The metric namespace to filter against. Only the namespace that matches
exactly will be returned.
Parameter nextToken :
The token returned by a previous call to indicate that there is more data
available.
Parameter owningAccount :
When you use this operation in a monitoring account, use this field to
return metrics only from one source account. To do so, specify that source
account ID in this field, and also specify true for
IncludeLinkedAccounts.
Parameter recentlyActive :
To filter the results to show only metrics that have had data points
published in the past three hours, specify this parameter with a value of
PT3H. This is the only valid value for this parameter.
The results that are returned are an approximation of the value you specify. There is a low probability that the returned results include metrics with last published data as much as 50 minutes more than the specified time interval.
Implementation
Future<ListMetricsOutput> listMetrics({
List<DimensionFilter>? dimensions,
bool? includeLinkedAccounts,
String? metricName,
String? namespace,
String? nextToken,
String? owningAccount,
RecentlyActive? recentlyActive,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'GraniteServiceVersion20100801.ListMetrics'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
if (dimensions != null) 'Dimensions': dimensions,
if (includeLinkedAccounts != null)
'IncludeLinkedAccounts': includeLinkedAccounts,
if (metricName != null) 'MetricName': metricName,
if (namespace != null) 'Namespace': namespace,
if (nextToken != null) 'NextToken': nextToken,
if (owningAccount != null) 'OwningAccount': owningAccount,
if (recentlyActive != null) 'RecentlyActive': recentlyActive.value,
},
);
return ListMetricsOutput.fromJson(jsonResponse.body);
}