Amazon CloudWatch

2018/04/04 - Amazon CloudWatch - 1 new api methods

Changes  The new GetMetricData API enables you to collect batch amounts of metric data and optionally perform math expressions on the data. With one GetMetricData call you can retrieve as many as 100 different metrics and a total of 100,800 data points.

GetMetricData (new) Link ΒΆ

You can use the GetMetricData API to retrieve as many as 100 different metrics in a single request, with a total of as many as 100,800 datapoints. You can also optionally perform math expressions on the values of the returned statistics, to create new time series that represent new insights into your data. For example, using Lambda metrics, you could divide the Errors metric by the Invocations metric to get an error rate time series. For more information about metric math expressions, see Metric Math Syntax and Functions in the Amazon CloudWatch User Guide .

Calls to the GetMetricData API have a different pricing structure than calls to GetMetricStatistics . For more information about pricing, see Amazon CloudWatch Pricing .

See also: AWS API Documentation

Request Syntax

client.get_metric_data(
    MetricDataQueries=[
        {
            'Id': 'string',
            'MetricStat': {
                'Metric': {
                    'Namespace': 'string',
                    'MetricName': 'string',
                    'Dimensions': [
                        {
                            'Name': 'string',
                            'Value': 'string'
                        },
                    ]
                },
                'Period': 123,
                'Stat': 'string',
                'Unit': 'Seconds'|'Microseconds'|'Milliseconds'|'Bytes'|'Kilobytes'|'Megabytes'|'Gigabytes'|'Terabytes'|'Bits'|'Kilobits'|'Megabits'|'Gigabits'|'Terabits'|'Percent'|'Count'|'Bytes/Second'|'Kilobytes/Second'|'Megabytes/Second'|'Gigabytes/Second'|'Terabytes/Second'|'Bits/Second'|'Kilobits/Second'|'Megabits/Second'|'Gigabits/Second'|'Terabits/Second'|'Count/Second'|'None'
            },
            'Expression': 'string',
            'Label': 'string',
            'ReturnData': True|False
        },
    ],
    StartTime=datetime(2015, 1, 1),
    EndTime=datetime(2015, 1, 1),
    NextToken='string',
    ScanBy='TimestampDescending'|'TimestampAscending',
    MaxDatapoints=123
)
type MetricDataQueries

list

param MetricDataQueries

[REQUIRED]

The metric queries to be returned. A single GetMetricData call can include as many as 100 MetricDataQuery structures. Each of these structures can specify either a metric to retrieve, or a math expression to perform on retrieved data.

  • (dict) --

    This structure indicates the metric data to return, and whether this call is just retrieving a batch set of data for one metric, or is performing a math expression on metric data. A single GetMetricData call can include up to 100 MetricDataQuery structures.

    • Id (string) -- [REQUIRED]

      A short name used to tie this structure to the results in the response. This name must be unique within a single call to GetMetricData . If you are performing math expressions on this set of data, this name represents that data and can serve as a variable in the mathematical expression. The valid characters are letters, numbers, and underscore. The first character must be a lowercase letter.

    • MetricStat (dict) --

      The metric to be returned, along with statistics, period, and units. Use this parameter only if this structure is performing a data retrieval and not performing a math expression on the returned data.

      Within one MetricDataQuery structure, you must specify either Expression or MetricStat but not both.

      • Metric (dict) -- [REQUIRED]

        The metric to return, including the metric name, namespace, and dimensions.

        • Namespace (string) --

          The namespace of the metric.

        • MetricName (string) --

          The name of the metric.

        • Dimensions (list) --

          The dimensions for the metric.

          • (dict) --

            Expands the identity of a metric.

            • Name (string) -- [REQUIRED]

              The name of the dimension.

            • Value (string) -- [REQUIRED]

              The value representing the dimension measurement.

      • Period (integer) -- [REQUIRED]

        The period to use when retrieving the metric.

      • Stat (string) -- [REQUIRED]

        The statistic to return. It can include any CloudWatch statistic or extended statistic.

      • Unit (string) --

        The unit to use for the returned data points.

    • Expression (string) --

      The math expression to be performed on the returned data, if this structure is performing a math expression. For more information about metric math expressions, see Metric Math Syntax and Functions in the Amazon CloudWatch User Guide .

      Within one MetricDataQuery structure, you must specify either Expression or MetricStat but not both.

    • Label (string) --

      A human-readable label for this metric or expression. This is especially useful if this is an expression, so that you know what the value represents. If the metric or expression is shown in a CloudWatch dashboard widget, the label is shown. If Label is omitted, CloudWatch generates a default.

    • ReturnData (boolean) --

      Indicates whether to return the time stamps and raw data values of this metric. If you are performing this call just to do math expressions and do not also need the raw data returned, you can specify False . If you omit this, the default of True is used.

type StartTime

datetime

param StartTime

[REQUIRED]

The time stamp indicating the earliest data to be returned.

type EndTime

datetime

param EndTime

[REQUIRED]

The time stamp indicating the latest data to be returned.

type NextToken

string

param NextToken

Include this value, if it was returned by the previous call, to get the next set of data points.

type ScanBy

string

param ScanBy

The order in which data points should be returned. TimestampDescending returns the newest data first and paginates when the MaxDatapoints limit is reached. TimestampAscending returns the oldest data first and paginates when the MaxDatapoints limit is reached.

type MaxDatapoints

integer

param MaxDatapoints

The maximum number of data points the request should return before paginating. If you omit this, the default of 100,800 is used.

rtype

dict

returns

Response Syntax

{
    'MetricDataResults': [
        {
            'Id': 'string',
            'Label': 'string',
            'Timestamps': [
                datetime(2015, 1, 1),
            ],
            'Values': [
                123.0,
            ],
            'StatusCode': 'Complete'|'InternalError'|'PartialData',
            'Messages': [
                {
                    'Code': 'string',
                    'Value': 'string'
                },
            ]
        },
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) --

    • MetricDataResults (list) --

      The metrics that are returned, including the metric name, namespace, and dimensions.

      • (dict) --

        A GetMetricData call returns an array of MetricDataResult structures. Each of these structures includes the data points for that metric, along with the time stamps of those data points and other identifying information.

        • Id (string) --

          The short name you specified to represent this metric.

        • Label (string) --

          The human-readable label associated with the data.

        • Timestamps (list) --

          The time stamps for the data points, formatted in Unix timestamp format. The number of time stamps always matches the number of values and the value for Timestamps[x] is Values[x].

          • (datetime) --

        • Values (list) --

          The data points for the metric corresponding to Timestamps . The number of values always matches the number of time stamps and the time stamp for Values[x] is Timestamps[x].

          • (float) --

        • StatusCode (string) --

          The status of the returned data. Complete indicates that all data points in the requested time range were returned. PartialData means that an incomplete set of data points were returned. You can use the NextToken value that was returned and repeat your request to get more data points. NextToken is not returned if you are performing a math expression. InternalError indicates that an error occurred. Retry your request using NextToken , if present.

        • Messages (list) --

          A list of messages with additional information about the data returned.

          • (dict) --

            A message returned by the GetMetricData API, including a code and a description.

            • Code (string) --

              The error code or status code associated with the message.

            • Value (string) --

              The message text.

    • NextToken (string) --

      A token that marks the next batch of returned results.