CloudWatchLogs / Client / put_metric_filter

put_metric_filter#

CloudWatchLogs.Client.put_metric_filter(**kwargs)#

Creates or updates a metric filter and associates it with the specified log group. With metric filters, you can configure rules to extract metric data from log events ingested through PutLogEvents.

The maximum number of metric filters that can be associated with a log group is 100.

When you create a metric filter, you can also optionally assign a unit and dimensions to the metric that is created.

Warning

Metrics extracted from log events are charged as custom metrics. To prevent unexpected high charges, do not specify high-cardinality fields such as IPAddress or requestID as dimensions. Each different value found for a dimension is treated as a separate metric and accrues charges as a separate custom metric.

CloudWatch Logs might disable a metric filter if it generates 1,000 different name/value pairs for your specified dimensions within one hour.

You can also set up a billing alarm to alert you if your charges are higher than expected. For more information, see Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges.

See also: AWS API Documentation

Request Syntax

response = client.put_metric_filter(
    logGroupName='string',
    filterName='string',
    filterPattern='string',
    metricTransformations=[
        {
            'metricName': 'string',
            'metricNamespace': 'string',
            'metricValue': 'string',
            'defaultValue': 123.0,
            'dimensions': {
                'string': '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'
        },
    ]
)
Parameters:
  • logGroupName (string) –

    [REQUIRED]

    The name of the log group.

  • filterName (string) –

    [REQUIRED]

    A name for the metric filter.

  • filterPattern (string) –

    [REQUIRED]

    A filter pattern for extracting metric data out of ingested log events.

  • metricTransformations (list) –

    [REQUIRED]

    A collection of information that defines how metric data gets emitted.

    • (dict) –

      Indicates how to transform ingested log events to metric data in a CloudWatch metric.

      • metricName (string) – [REQUIRED]

        The name of the CloudWatch metric.

      • metricNamespace (string) – [REQUIRED]

        A custom namespace to contain your metric in CloudWatch. Use namespaces to group together metrics that are similar. For more information, see Namespaces.

      • metricValue (string) – [REQUIRED]

        The value to publish to the CloudWatch metric when a filter pattern matches a log event.

      • defaultValue (float) –

        (Optional) The value to emit when a filter pattern does not match a log event. This value can be null.

      • dimensions (dict) –

        The fields to use as dimensions for the metric. One metric filter can include as many as three dimensions.

        Warning

        Metrics extracted from log events are charged as custom metrics. To prevent unexpected high charges, do not specify high-cardinality fields such as IPAddress or requestID as dimensions. Each different value found for a dimension is treated as a separate metric and accrues charges as a separate custom metric.

        CloudWatch Logs disables a metric filter if it generates 1000 different name/value pairs for your specified dimensions within a certain amount of time. This helps to prevent accidental high charges.

        You can also set up a billing alarm to alert you if your charges are higher than expected. For more information, see Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges.

        • (string) –

          • (string) –

      • unit (string) –

        The unit to assign to the metric. If you omit this, the unit is set as None.

Returns:

None

Exceptions