'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"
}
]
Solution 1:[1]
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"
}
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Vipin Kumar |
Solution 2 |