Not a customer? Click the 'Start a free trial' link to begin a 30-day SaaS trial of our product and to join our community.
Existing Cisco AppDynamics customers should click the 'Sign In' button to authenticate to access the community
on 05-14-2024 05:06 AM
cd /opt/appdynamics/ma/monitors
mkdir DynamoDb
#!/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
<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>
Thank you! Your submission has been received!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form