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"
}
]
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).
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.)
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.
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"
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With