CloudWatch Metric Filter
CloudWatch Metric Filter
Return to the main screen of CloudWatch
- Select Log groups
- Search for
/ec2
. - Select /ec2/linux/var/log/messages
![4.3.1](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.1.png)
In the interface of /ec2/linux/var/log/messages
- Click on Actions.
- Click Create metric filter.
![4.3.2](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.2.png)
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](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.3.png)
- Click Test pattern to check if the filter works properly.
![4.3.4](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.4.png)
- In the Create filter name section of Assign metric, enter
PythonAppErrors
.
![4.3.5](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.5.png)
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](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.6.png)
- After reviewing, click Create metric filter.
![4.3.7](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.7.png)
![4.3.8](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.8.png)
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](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.9.png)
![4.3.10](https://fcj-dntu.github.io/000008-cloud-watch-workshop/images/4-cloud-watch-logs/4.3-metric-filter/4.3.10.png)
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.