Create a metric filter for a log group
To create a metric filter for a log group, follow these steps. The metric won't be visible until there are some data points for it.
To create a metric filter using the CloudWatch console
-
Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/
. -
In the navigation pane, choose Logs, and then choose Log groups.
-
Choose the name of the log group.
-
Choose
Actions
, and then choose Create metric filter. -
For Filter pattern, enter a filter pattern. For more information, see Filter pattern syntax for metric filters, subscription filters, filter log events, and Live Tail.
-
(Optional) To test your filter pattern, under Test Pattern, enter one or more log events to test the pattern. Each log event must be formatted on one line. Line breaks are used to separate log events in the Log event messages box.
-
Choose Next, and then enter a name for your metric filter.
-
Under Metric details, for Metric namespace, enter a name for the CloudWatch namespace where the metric will be published. If the namespace doesn't already exist, make sure that Create new is selected.
-
For Metric name, enter a name for the new metric.
-
For Metric value, if your metric filter is counting occurrences of the keywords in the filter, enter 1. This increments the metric by 1 for each log event that includes one of the keywords.
Alternatively, enter a token, such as
$size
. This increments the metric by the value of the number in thesize
field for every log event that contains asize
field. -
(Optional) For Unit, select a unit to assign to the metric. If you do not specify a unit, the unit is set as
None
. -
(Optional) Enter the names and tokens for as many as three dimensions for the metric. If you assign dimensions to metrics that metric filters create, you cannot assign default values for those metrics.
Note
Dimensions are supported only in JSON or space-delimited metric filters.
-
Choose Create metric filter. You can find the metric filter that you created from the navigation pane. Choose Logs, and then choose Log groups. Choose the name of the log group that you created your metric filter for, and then select the Metric filters tab.