☁️
CTHFM: AWS
  • Welcome
  • Getting Started
    • Account Setup
  • AWS CLI
    • AWS CLI Overview
    • Installation
  • AWS Fundamentals
    • AWS Documentation
    • AWS Shared Responsibility Model
    • Organizational Hierarchy
    • AWS Principals
    • IAM Fundamentals
      • IAM Policy Components
      • IAM Documentation References
    • AWS Security Services Overview
    • AWS Core Services
    • AWS Frameworks
    • Regions and Availability Zones
  • SQL
    • SQL Refresher for Threat Hunting
  • Logging Reference
    • Cloudtrail
      • What is Cloudtrail?
      • Setting Up Cloudtrail
      • Cloudtrail Events Structure
      • Filtering and Searching CloudTrail Logs
      • IAM ID Prefixes
      • Additional Resources
      • API References
    • VPCFlow Logs
    • GuardDuty
      • Multi-Account Setup
      • GuardDuty Concepts
      • GuardDuty Finding References
      • S3 Protection
      • Malware Protection
        • EC2 Malware Protection
          • EC2 Protection Resources
          • Monitoring Scans
          • EC2 Malware Protection Events: CloudWatch
        • S3 Malware Protection
          • Enabling S3 Malware Protection
          • After Enabling S3 Malware Protection
          • S3 Malware Resource Plan Status
          • S3 Malware Protection Quotas
      • RDS Protection Enablement
      • Lambda Protection Enablement
      • Trusted IP Lists and Threat Lists in Amazon GuardDuty
      • Remediation Recommendations
      • GuardDuty API Reference
      • GuardDuty Quotas
    • Access Analyzer
      • Setup
      • External Access and Unused Access Analyzer Findings
      • Review Findings
      • Access Analyzer Resources
      • Access Analyzer API Reference
    • AWS Network Firewall
      • Permissions
      • Firewall Log Contents
      • Logging Destinations
      • CloudWatch Firewall Metrics
    • AWS Config
      • Resource Management in AWS Config
      • AWS Config Integrations
      • AWS Config Resources
      • Configuration Item
      • Config Rules
        • Evaluation Modes
  • CloudWatch
    • Amazon CloudWatch
      • CloudWatch Concepts
      • CloudWatch Metrics
        • Filter Pattern Syntax
      • CloudWatch Alarms
        • Alarm Recommendations
      • Subscriptions
      • CloudWatch Agent
      • CloudWatch Insights
        • Supported Logs and Discovered Fields
        • CloudWatch Insights Query Syntax
      • Anomaly Detection
        • Create Anomaly Detector
        • Alarms for Anomaly Detections
      • CloudWatch Filter Syntax
      • CloudWatch Service Quota
  • Athena For Threat Hunting
    • Introduction to Athena
    • Setting Up Athena
    • SQL For Threat Hunters
    • Automated Response
    • Query Best Practices
  • AWS Security Research and Resources
    • AWS Security Blog
    • AWS Goat
    • Cloud Goat
    • Pacu
    • Prowler
    • Scout Suite
  • Threat Hunting in AWS
    • Threat Hunting in AWS
    • Threat Hunting Introduction
    • Threat Hunting Process
      • Hypothesis Generation
      • Investigation
      • Identification
      • Resolution & Follow Up
    • Pyramid of Pain
    • MITRE Att&ck
      • MITRE Att&ck Concepts
      • MITRE Att&CK Data Sources
      • MITRE Att&CK Mitigations
    • MITRE Att&ck: AWS
      • MITRE Att&CK Matrix
      • Amazon Web Services Security Control Mappings
    • AWS Threat Hunting Ideas
      • AWS Threat Hunting Ideas: EC2
      • AWS Threat Hunting Ideas: Lambda
      • AWS Threat Hunting Ideas: SQS
      • AWS Threat Hunting Ideas: SNS
      • AWS Threat Hunting Ideas: RDS
Powered by GitBook
On this page
  • Overview
  • How Metric Filters Differ from Logs Insights Queries:
  • How Metric Filters Work:
  • Examples of Filter Patterns:
  • Creating a Metric Filter:
  • Important Considerations:
  • Benefits of Metric Filters:
  1. CloudWatch
  2. Amazon CloudWatch
  3. CloudWatch Metrics

Filter Pattern Syntax

Overview

Metric filters in CloudWatch allow you to search log data for specific patterns and convert matching events into numerical metrics. These metrics are useful for monitoring trends, setting alarms, and visualizing key metrics in dashboards.


How Metric Filters Differ from Logs Insights Queries:

  • Metric Filters: Each match increments a metric with a specified numerical value.

  • Logs Insights Queries: Used to query historical logs but do not generate metrics.


How Metric Filters Work:

  1. Filter Patterns: Define how CloudWatch interprets log data (e.g., matching keywords, JSON fields, or space-delimited entries).

  2. Metrics Generation: A metric is created for every match, with an increment value specified.

  3. Dimensions: Key-value pairs (e.g., Service:API) provide context for metrics.

  4. Default Value: If no match is found during a period, CloudWatch reports a default value (e.g., 0) to prevent missing data.

Examples of Filter Patterns:

  • JSON Log Events: Extract specific values, like latency:

    { $.latency = * } metricValue: $.latency

    Example Log Entry:

    {
      "latency": 50,
      "requestType": "GET"
    }

    This filter publishes a latency value of 50 to the metric.

  • Space-Delimited Log Events: Example log:

    127.0.0.1 Prod frank [10/Oct/2000:13:25:15 -0700] "GET /index.html HTTP/1.0" 404 1534

    This type of log can be filtered using logical operators (e.g., AND, OR) to extract metrics based on different fields.

Creating a Metric Filter:

  1. Open the CloudWatch console.

  2. Navigate to Logs > Log Groups and select or create a log group.

  3. Choose Actions > Create metric filter.

  4. Define the filter pattern (e.g., { $.latency = * }).

  5. Set the metric name and value (e.g., latency).

  6. (Optional) Set a default value (e.g., 0) to ensure continuous reporting.

  7. Create the filter, and CloudWatch will aggregate the metric every minute.

Important Considerations:

  • JSON and Space-Delimited Logs: You can create filters for up to three dimensions from these logs.

  • Avoid High-Cardinality Fields: Using fields like IPAddress or requestID as dimensions may lead to unexpected costs and potential filter deactivation.

  • Default Value: Always set a default value (e.g., 0) to avoid gaps in metrics.

Benefits of Metric Filters:

  • Track Key Events: Monitor occurrences of keywords like "ERROR."

  • Extract Values Dynamically: Use JSON logs to publish specific metrics (e.g., latency).

  • Set Alarms: Use metrics to trigger alarms based on thresholds or trends.

PreviousCloudWatch MetricsNextCloudWatch Alarms

Last updated 8 months ago