CloudWatch Metrics
Overview
CloudWatch allows you to create metrics from log data by applying metric filters. These filters search for specific patterns in log events and convert matching events into numerical CloudWatch metrics, which can be graphed or monitored through alarms.
Key Elements of Metric Filters:
Default Value:
Reports a value (e.g.,
0
) during periods when no matching logs are found.Prevents gaps ("spotty" metrics) in the metric data.
Dimensions:
Key-value pairs that further define the metric (e.g.,
Service:API
).Each unique dimension combination creates a new variation of the metric.
Filter Pattern:
A pattern describing how CloudWatch should interpret the log data (e.g., matching "Error" or IP addresses).
This determines what log data should be converted into metrics.
Metric Name & Namespace:
Metric Name: The name under which the metric will be published (e.g.,
ErrorCount
).Metric Namespace: The logical grouping for related metrics (e.g.,
AppMetrics
).
Metric Value:
The numerical value to report for each matching event (e.g.,
1
for each occurrence of "Error" or byte count from log data).
Important Considerations:
No Retroactive Filtering:
Filters only apply to log events ingested after the filter is created.
Results include the first 50 lines but exclude entries with timestamps earlier than the metric creation time.
Log Classes:
Metric filters are available only for Standard log class log groups.
Percentile Statistics:
Only available for metrics with non-negative values.
Metrics reporting negative numbers will not support percentile-based statistics.
Creating and Managing Metric Filters:
Create a Filter:
Define a filter pattern for the log data to monitor.
Specify the metric name, namespace, and dimensions.
List or Delete Filters:
View active filters or delete them when no longer needed.
Last updated