Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cloudwatch command get-metric-data

I'm not able to get the metric data through this command.

aws cloudwatch get-metric-data --metric-data-queries jsonfile.json \
   --start-time 2019-02-01T10:40:0000 --end-time 2019-02-27T14:12:0000 

The following error is getting shown.

Error parsing parameter '--metric-data-queries': Expected: '=', received: 'EOF' for input:

jsonfile.json

Here, the jsonfile.json contains my query, defined below.

[
    {
        "Id": "MyRequest",
        "MetricStat": {
            "Metric": {
                "Namespace": "AWS/EBS",
                "MetricName": "VolumeReadBytes",
                "Dimensions": [
                    {
                        "Name": "VolumeId",
                        "Value": "vol-******420********"
                    }
                ]
            },
            "Period": "3600",
            "Stat": "Average",
            "Unit": "Bytes"
        },
        "Label": "myRequestLabel",
        "ReturnData": "true"
    }
]
like image 620
Prakhar Singh Dhaila Avatar asked Mar 08 '19 05:03

Prakhar Singh Dhaila


People also ask

How do I get CloudWatch metrics?

Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/ . In the navigation pane, choose Metrics, and then choose All metrics. Select a metric namespace (for example, EC2). Select a metric dimension (for example, Per-Instance Metrics).

How do I export metrics from CloudWatch?

You will specify the EC2 Instance Id in the --dimensions Name=InstanceId,Value=i-xxxxxxxxxxxxxxxxx parameter. --start-time and --end-time specify the range. --period The granularity, in seconds, of the returned data points. --region The region where the CloudWatch metric is being meatured (us-east-1, us-west-2 etc.)

What is metric value in CloudWatch?

A metric represents a time-ordered set of data points that are published to CloudWatch. Think of a metric as a variable to monitor, and the data points as representing the values of that variable over time. For example, the CPU usage of a particular EC2 instance is one metric provided by Amazon EC2.


2 Answers

I think what you need to run is;

    aws cloudwatch get-metric-data --cli-input-json file://jsonfile.json

The content of your jsonfile.json should be as follows;

{
    "MetricDataQueries": [
        {
            "Id": "myRequest",
            "MetricStat": {
                "Metric": {
                    "Namespace": "AWS/EBS",
                    "MetricName": "VolumeReadBytes",
                    "Dimensions": [
                        {
                            "Name": "VolumeId",
                            "Value": "vol-******420********"
                        }
                    ]
                },
                "Period": 3600,
                "Stat": "Average",
                "Unit": "Bytes"
            },
            "Label": "myRequestLabel",
            "ReturnData": true
        }
    ],
    "StartTime": "2019-02-01T10:40:0000",
    "EndTime": "2019-02-27T14:12:0000"
}
like image 84
marcincuber Avatar answered Oct 16 '22 07:10

marcincuber


If you prefer a bash script:

#!/bin/bash

start_time=$(date --utc -d "24 hours ago" '+%Y-%m-%dT%H:%M:%S')
now=$(date '+%Y-%m-%dT%H:%M:%S')

aws --output json cloudwatch get-metric-statistics --namespace AWS/NetworkELB \
    --metric-name ActiveFlowCount --statistics Sum  --period 3600 \
    --dimensions Name=LoadBalancer,Value=net/YourHash1/YourHash2 \
    --start-time $start_time --end-time $now
like image 36
AAber Avatar answered Oct 16 '22 09:10

AAber