CloudWatch Metric Filter

CloudWatch Metric Filter

  1. Return to the main screen of CloudWatch

    • Select Log groups
    • Search for /ec2.
    • Select /ec2/linux/var/log/messages

4.3.1

  1. In the interface of /ec2/linux/var/log/messages

    • Click on Actions.
    • Click Create metric filter.

4.3.2

  1. In the Define Pattern section, enter the following information:

    • Filter pattern: select ERROR from the dropdown.
    • Test pattern: select any instance, but it’s recommended to choose the instance where we created processes in the previous two steps.

4.3.3

  1. Click Test pattern to check if the filter works properly.

4.3.4

  1. In the Create filter name section of Assign metric, enter PythonAppErrors.

4.3.5

  1. In the Metric details section, enter the following information:

    • Metric namespace: ec2-logs.
    • Metric name: /var/log/messages - ERROR.
    • Metric value: 1.
    • Default value: 0.
    • Unit: select Count from the dropdown.
    • Click Next.

4.3.6

  1. After reviewing, click Create metric filter.

4.3.7

4.3.8

  1. Go back to Metrics > All metrics.

    • Search for the keywords /var/log/messages and ERROR.
    • Select ec2-logs > Metrics with no dimensions.

4.3.9

4.3.10

Now we have a metric that retrieves ERROR logs from the application. In the next step, we will set up an alarm for this metric.