cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Abhi.Bajaj
AppDynamics Team

Pre-requisite

  1. Machine Agent installed on any Linux box that has access to the DynamoDb Database
  2. Linux box should have permission to fetch CloudWatch metrics

Installation

  1. If your Linux Box is on EC2, then please select the IAM Role associated with that EC2 instance and add “CloudWatchFullAccess” permission.
    RyanParedez_0-1715687787094.png
  2. Once done, SSH inside the box where your Machine Agent is running. 
  3. 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​
  4. 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

     

  5. 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>​
    RyanParedez_1-1715688314916.png

     



  6. Great work!! Now, Llet’s restart your Machine Agent
  7. Once you are done, you will be able to see your DynamoDB metrics in the AppDynamics Machine Agent’s metric browserScreenshot 2024-05-13 at 5.16.59 PM.png
Version history
Last update:
‎05-14-2024 05:06 AM
Updated by:
On-Demand Webinar
Discover new Splunk integrations and AI innovations for Cisco AppDynamics.


Register Now!

Observe and Explore
Dive into our Community Blog for the Latest Insights and Updates!


Read the blog here