Monitor AWS DynamoDB with AppDynamics
Pre-requisite
- Machine Agent installed on any Linux box that has access to the DynamoDb Database
- Linux box should have permission to fetch CloudWatch metrics
Installation
- If your Linux Box is on EC2, then please select the IAM Role associated with that EC2 instance and add “CloudWatchFullAccess” permission.
- Once done, SSH inside the box where your Machine Agent is running.
- In the Machine Agent Home folder, go to the Monitors folder and create a directory called "DynamoDb". In my case, MA_HOME = /opt/appdynamics/ma
cd /opt/appdynamics/ma/monitors mkdir DynamoDb
- Inside the 'DynamoDb' folder, create a file called script.sh with the below content:
NOTE: Please edit TABLE_NAME and AWS_REGION with your desired TABLE_NAME and AWS_REGION#!/bin/bash # Define the DynamoDB table name TABLE_NAME="aws-lambda-standalone-dynamodb" # Define your AWS region AWS_REGION="us-west-2" # Change this to your region # List of all metrics you want to fetch declare -a METRICS=("ConsumedReadCapacityUnits" "ConsumedWriteCapacityUnits" "ProvisionedReadCapacityUnits" "ProvisionedWriteCapacityUnits" "ReadThrottleEvents" "WriteThrottleEvents" "UserErrors" "SystemErrors" "ConditionalCheckFailedRequests" "SuccessfulRequestLatency" "ReturnedItemCount" "ReturnedBytes" "ReturnedRecordsCount") # Define the time period (in ISO8601 format) START_TIME=$(date --date='60 minutes ago' --utc +%Y-%m-%dT%H:%M:%SZ) END_TIME=$(date --utc +%Y-%m-%dT%H:%M:%SZ) # Loop through each metric and fetch the data for METRIC_NAME in "${METRICS[@]}" do # Fetch the metric data using AWS CLI METRIC_VALUE=$(aws cloudwatch get-metric-statistics --namespace AWS/DynamoDB \ --metric-name $METRIC_NAME \ --dimensions Name=TableName,Value=$TABLE_NAME \ --start-time "$START_TIME" \ --end-time "$END_TIME" \ --period 3600 \ --statistics Average \ --query 'Datapoints[0].Average' \ --output text \ --region $AWS_REGION) # Check if metric value is 'None' or empty if [ "$METRIC_VALUE" == "None" ] || [ -z "$METRIC_VALUE" ]; then METRIC_VALUE="0" else # Round the metric value to the nearest whole number METRIC_VALUE=$(printf "%.0f" "$METRIC_VALUE") fi # Echo the metric in the specified format echo "name=Custom Metrics|DynamoDB|$TABLE_NAME|$METRIC_NAME,value=$METRIC_VALUE" done
If you have multiple tables, then use the script below:
#!/bin/bash # List of DynamoDB table names declare -a TABLE_NAMES=("Table1" "Table2" "Table3") # Add your table names here # Define your AWS region AWS_REGION="us-west-2" # Change this to your region # List of all metrics you want to fetch declare -a METRICS=("ConsumedReadCapacityUnits" "ConsumedWriteCapacityUnits" "ProvisionedReadCapacityUnits" "ProvisionedWriteCapacityUnits" "ReadThrottleEvents" "WriteThrottleEvents" "UserErrors" "SystemErrors" "ConditionalCheckFailedRequests" "SuccessfulRequestLatency" "ReturnedItemCount" "ReturnedBytes" "ReturnedRecordsCount") # Define the time period (in ISO8601 format) START_TIME=$(date --date='60 minutes ago' --utc +%Y-%m-%dT%H:%M:%SZ) END_TIME=$(date --utc +%Y-%m-%dT%H:%M:%SZ) # Loop through each table for TABLE_NAME in "${TABLE_NAMES[@]}" do # Loop through each metric and fetch the data for the current table for METRIC_NAME in "${METRICS[@]}" do # Fetch the metric data using AWS CLI METRIC_VALUE=$(aws cloudwatch get-metric-statistics --namespace AWS/DynamoDB \ --metric-name $METRIC_NAME \ --dimensions Name=TableName,Value=$TABLE_NAME \ --start-time "$START_TIME" \ --end-time "$END_TIME" \ --period 3600 \ --statistics Average \ --query 'Datapoints[0].Average' \ --output text \ --region $AWS_REGION) # Check if metric value is 'None' or empty if [ "$METRIC_VALUE" == "None" ] || [ -z "$METRIC_VALUE" ]; then METRIC_VALUE="0" else # Round the metric value to the nearest whole number METRIC_VALUE=$(printf "%.0f" "$METRIC_VALUE") fi # Echo the metric in the specified format echo "name=Custom Metrics|DynamoDB|$TABLE_NAME|$METRIC_NAME,value=$METRIC_VALUE" done done
- Great. Create another file called monitor.xml with the below content:
<monitor> <name>DynamoDb monitoring</name> <type>managed</type> <description>DynamoDb monitoring</description> <monitor-configuration> </monitor-configuration> <monitor-run-task> <execution-style>periodic</execution-style> <name>Run</name> <type>executable</type> <task-arguments> </task-arguments> <executable-task> <type>file</type> <file>script.sh</file> </executable-task> </monitor-run-task> </monitor>
- Great work!! Now, Llet’s restart your Machine Agent
- Once you are done, you will be able to see your DynamoDB metrics in the AppDynamics Machine Agent’s metric browser