Question: How can I filter Enhanced Monitoring CloudWatch logs to generate automated custom metrics for Amazon RDS?

How can I filter Enhanced Monitoring CloudWatch Logs to generate automated custom metrics for Amazon Relational Database Service (Amazon RDS)?Short descriptionEnhanced Monitoring for RDS provides the following OS metrics:Free MemoryActive MemorySwap FreeProcesses RunningFile System UsedYou can use these metrics to understand the environment's performance, and these metrics are ingested by Amazon CloudWatch Logs as log entries. You can use CloudWatch to create alarms based on metrics. These alarms run actions, and you can publish these metrics from within your infrastructure, device, or application into CloudWatch as a custom metric. By using Enhanced Monitoring and CloudWatch together, you can automate tasks by creating a custom metric for the CloudWatch Logs RDS ingested date from the Enhanced Monitoring metrics.

ResolutionNote: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI.Create a custom metric using filters on a log groupNote: These steps require that you enable Enhanced Monitoring in your RDS DB instance. For more information, see Monitoring an Amazon RDS DB instance.1.    Enable Enhanced Monitoring.2.    Open the Amazon CloudWatch console, and then choose Log groups from the navigation pane.3.    Filter for RDSOSMetrics from the list of Log Groups, and then choose Actions.4.    Choose Create Metric Filter, and then enter a Filter Pattern term for your RDS DB instance. For example:DISK UTILIZATION: { $.diskIO[0].writeKbPS="0.00"}DISK WRITE KBPS : { $.diskIO[0].util="0.00"}DISK READ KBPS : { $.diskIO[0].readKbPS="0.00"}DISK WRITE IOPS : { $.diskIO[0].writeKbPS="0.00"}Note: Be sure to update 0.00 to the value that you want to measure.5.    Select the Log Data to test, and then choose Test Pattern.6.    Choose Next.7.    Enter a Filter Name, and then select a Metric Namespace and Metric Name.8.    Enter a Metric Value—for example, $.cpuUtilization.idle—and then choose Create Filter.Repeat these steps for each additional metric that you add.AutomationThere are more than 60 monitoring metrics per RDS DB instance, and you can use a script to automate this process. See the GitHub repository for rds-support-tools for an example script that uses an RDS for MySQL DB instance that works with the following engines:MySQLMariaDBAmazon Aurora (MySQL and PostgreSQL)PostgreSQLSpecify the RDS DB instance that has Enhanced Monitoring enabled and the namespace where you want these metrics to reside—optionally, you can add the names of the metrics and the Region. If no optional fields are specified, the script considers all the metrics to publish, and then uses the Region that is specified by default in the file .aws/config using the AWS Command Line Interface (AWS CLI).Note: The script doesn't create metrics for process list, so you might need to create filters manually, depending on the process that you want to display.The names of the metrics must be specified by the following pattern:group.metricnameThe following sample code illustrates a call to enable this metric for cpuUtilization.idle and diskIO.readKbPS:python RDSCreateMetricsFromEnhancedMonitoring.py --rds_instance mysqltest --namespace MySQL --metrics_to_filter cpuUtilization.idle diskIO.readKbYou can then create alarms for these custom metrics. For more information, see Using Amazon CloudWatch alarms.

Related informationEnhanced MonitoringAmazon RDS database log files