- Newest
- Most votes
- Most comments
Hi there,
It is possible to achieve what you want using CloudWatch Logs Metric Filters and some additional processing. Here's one approach you can take:
- Create a Metric Filter to extract the session_id: Create a metric filter on your log group that extracts the session_id from your log events. Set the metric value to 1 for each occurrence of the session_id.
For example, if your log events contain a field like "session_id": "abc123"
, you can create a metric filter with the following filter pattern:
{ $.session_id = "session_id" }
This will create a metric with the name SessionId
and a value of 1 for each log event containing a session_id.
- Create a Metric Math to count unique session_ids: Use CloudWatch Metric Math to count the unique session_ids within a given time period. This will give you the number of sessions with failures.
Go to the "Metric Math" section in the CloudWatch console, and create a new metric math expression like this:
UNIQUE(m1, "SessionId")
Here, m1
is the namespace for your log group metrics. This expression will count the unique values of the SessionId
metric, effectively giving you the number of distinct sessions with failures.
- Create a Dashboard Widget: Finally, create a dashboard widget that displays the result of the metric math expression. Choose the "Gauge" widget type, and select the metric math expression you created in step 2 as the metric to display.
With this approach, you'll get a gauge that shows the number of distinct sessions with failures, even if there are multiple error log entries for a single session.
Alternatively, if you want to count the total number of errors across all sessions, you can skip step 2 and simply create a dashboard widget that displays the sum of the SessionId
metric values from step 1. This will give you the total number of error log entries, regardless of the number of distinct sessions.
If you face any further issues here, it is advised to create a Support Ticket to the cloudwatch team through the AWS Support.
Relevant content
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 8 months ago