How to use aws cloudwatch get-metric-widget-image?
I would like to get Cloudwatch screenshot automatically since I have many instances.
But when I try to run get-metric-widget-image by aws cli command tool, I always get error.
An error occurred (ValidationError) when calling the GetMetricWidgetImage operation: MetricWidget property 'metricWidget' has a bad JSON content.
Is there anyone who could help me out? Thanks.
I could not find an example from aws doc. No exact example in below link.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Metric-Widget-Structure.html
My command is like this.
aws cloudwatch get-metric-widget-image --metric-widget "{ "width":600,"height":395,"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-01234567890123456",{"stat":"Average"}]],"period":300,"start":"-P30D","end":"PT0H","stacked":false,"yAxis":{"left":{"min":0.1,"max":1},"right":{"min":0}},"title":"CPU","annotations":{"horizontal":[{"color":"#ff6961","label":"Troublethresholdstart","fill":"above","value":0.5}], "vertical":[{"visible":true, "color":"#9467bd","label":"Bugfixdeployed","value":"2018-11-19T07:25:26Z","fill":"after"}]}}}" --output-format "png"
amazon-web-services amazon-cloudwatch
add a comment |
I would like to get Cloudwatch screenshot automatically since I have many instances.
But when I try to run get-metric-widget-image by aws cli command tool, I always get error.
An error occurred (ValidationError) when calling the GetMetricWidgetImage operation: MetricWidget property 'metricWidget' has a bad JSON content.
Is there anyone who could help me out? Thanks.
I could not find an example from aws doc. No exact example in below link.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Metric-Widget-Structure.html
My command is like this.
aws cloudwatch get-metric-widget-image --metric-widget "{ "width":600,"height":395,"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-01234567890123456",{"stat":"Average"}]],"period":300,"start":"-P30D","end":"PT0H","stacked":false,"yAxis":{"left":{"min":0.1,"max":1},"right":{"min":0}},"title":"CPU","annotations":{"horizontal":[{"color":"#ff6961","label":"Troublethresholdstart","fill":"above","value":0.5}], "vertical":[{"visible":true, "color":"#9467bd","label":"Bugfixdeployed","value":"2018-11-19T07:25:26Z","fill":"after"}]}}}" --output-format "png"
amazon-web-services amazon-cloudwatch
add a comment |
I would like to get Cloudwatch screenshot automatically since I have many instances.
But when I try to run get-metric-widget-image by aws cli command tool, I always get error.
An error occurred (ValidationError) when calling the GetMetricWidgetImage operation: MetricWidget property 'metricWidget' has a bad JSON content.
Is there anyone who could help me out? Thanks.
I could not find an example from aws doc. No exact example in below link.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Metric-Widget-Structure.html
My command is like this.
aws cloudwatch get-metric-widget-image --metric-widget "{ "width":600,"height":395,"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-01234567890123456",{"stat":"Average"}]],"period":300,"start":"-P30D","end":"PT0H","stacked":false,"yAxis":{"left":{"min":0.1,"max":1},"right":{"min":0}},"title":"CPU","annotations":{"horizontal":[{"color":"#ff6961","label":"Troublethresholdstart","fill":"above","value":0.5}], "vertical":[{"visible":true, "color":"#9467bd","label":"Bugfixdeployed","value":"2018-11-19T07:25:26Z","fill":"after"}]}}}" --output-format "png"
amazon-web-services amazon-cloudwatch
I would like to get Cloudwatch screenshot automatically since I have many instances.
But when I try to run get-metric-widget-image by aws cli command tool, I always get error.
An error occurred (ValidationError) when calling the GetMetricWidgetImage operation: MetricWidget property 'metricWidget' has a bad JSON content.
Is there anyone who could help me out? Thanks.
I could not find an example from aws doc. No exact example in below link.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/CloudWatch-Metric-Widget-Structure.html
My command is like this.
aws cloudwatch get-metric-widget-image --metric-widget "{ "width":600,"height":395,"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-01234567890123456",{"stat":"Average"}]],"period":300,"start":"-P30D","end":"PT0H","stacked":false,"yAxis":{"left":{"min":0.1,"max":1},"right":{"min":0}},"title":"CPU","annotations":{"horizontal":[{"color":"#ff6961","label":"Troublethresholdstart","fill":"above","value":0.5}], "vertical":[{"visible":true, "color":"#9467bd","label":"Bugfixdeployed","value":"2018-11-19T07:25:26Z","fill":"after"}]}}}" --output-format "png"
amazon-web-services amazon-cloudwatch
amazon-web-services amazon-cloudwatch
edited Nov 20 '18 at 7:33
lagom
3,55181937
3,55181937
asked Nov 20 '18 at 6:19


ingsnow kwaningsnow kwan
83
83
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The best way to get the correct json for your request is to use CloudWatch Console to construct the graph, then click on the Source
tab, select Image API
view and click Copy Source
to copy the json generated there. You also need to wrap the json in single quotes, like this:
aws cloudwatch get-metric-widget-image --metric-widget
'{
"width": 600,
"height": 395,
"metrics": [
[ "AWS/EC2", "CPUUtilization", "InstanceId", "i-01234567890123456", { "stat": "Average" } ]
],
"period": 300,
"stacked": false,
"yAxis": {
"left": {
"min": 0.1,
"max": 1
},
"right": {
"min": 0
}
},
"title": "CPU",
"annotations": {
"horizontal": [
{
"color": "#ff6961",
"label": "Troublethresholdstart",
"fill": "above",
"value": 0.5
}
],
"vertical": [
{
"visible": true,
"color": "#9467bd",
"label": "Bugfixdeployed",
"value": "2018-11-19T07:25:26Z",
"fill": "after"
}
]
},
"view": "timeSeries"
}'
Response to this will be a base64 encoded image, like this:
{
"MetricWidgetImage": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAGLEAYA..."
}
If you need the raw png image, you'll need to decode the response by doing something like this:
aws cloudwatch get-metric-widget-image --metric-widget 'JSON_GOES_HERE' | grep MetricWidgetImage | awk '{split($0,a,"""); print a[4]}' | base64 --decode > graph.png
Thank you so much,Tartaglia! Very detailed answer. I am a green hand at AWS. It works for me and I could get the correct picture.
– ingsnow kwan
Nov 20 '18 at 9:13
add a comment |
JSONLint says that you've got one extra }
at the end of your JSON. Also, try wrapping the whole JSON block with single quotes '
for easier differentiating and no need to escape the double quotes in the JSON string.
This should work for you:
aws cloudwatch get-metric-widget-image --metric-widget '{ "width":600,"height":395,"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-01234567890123456",{"stat":"Average"}]],"period":300,"start":"-P30D","end":"PT0H","stacked":false,"yAxis":{"left":{"min":0.1,"max":1},"right":{"min":0}},"title":"CPU","annotations":{"horizontal":[{"color":"#ff6961","label":"Troublethresholdstart","fill":"above","value":0.5}], "vertical":[{"visible":true, "color":"#9467bd","label":"Bugfixdeployed","value":"2018-11-19T07:25:26Z","fill":"after"}]}}' --output-format "png"
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387313%2fhow-to-use-aws-cloudwatch-get-metric-widget-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The best way to get the correct json for your request is to use CloudWatch Console to construct the graph, then click on the Source
tab, select Image API
view and click Copy Source
to copy the json generated there. You also need to wrap the json in single quotes, like this:
aws cloudwatch get-metric-widget-image --metric-widget
'{
"width": 600,
"height": 395,
"metrics": [
[ "AWS/EC2", "CPUUtilization", "InstanceId", "i-01234567890123456", { "stat": "Average" } ]
],
"period": 300,
"stacked": false,
"yAxis": {
"left": {
"min": 0.1,
"max": 1
},
"right": {
"min": 0
}
},
"title": "CPU",
"annotations": {
"horizontal": [
{
"color": "#ff6961",
"label": "Troublethresholdstart",
"fill": "above",
"value": 0.5
}
],
"vertical": [
{
"visible": true,
"color": "#9467bd",
"label": "Bugfixdeployed",
"value": "2018-11-19T07:25:26Z",
"fill": "after"
}
]
},
"view": "timeSeries"
}'
Response to this will be a base64 encoded image, like this:
{
"MetricWidgetImage": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAGLEAYA..."
}
If you need the raw png image, you'll need to decode the response by doing something like this:
aws cloudwatch get-metric-widget-image --metric-widget 'JSON_GOES_HERE' | grep MetricWidgetImage | awk '{split($0,a,"""); print a[4]}' | base64 --decode > graph.png
Thank you so much,Tartaglia! Very detailed answer. I am a green hand at AWS. It works for me and I could get the correct picture.
– ingsnow kwan
Nov 20 '18 at 9:13
add a comment |
The best way to get the correct json for your request is to use CloudWatch Console to construct the graph, then click on the Source
tab, select Image API
view and click Copy Source
to copy the json generated there. You also need to wrap the json in single quotes, like this:
aws cloudwatch get-metric-widget-image --metric-widget
'{
"width": 600,
"height": 395,
"metrics": [
[ "AWS/EC2", "CPUUtilization", "InstanceId", "i-01234567890123456", { "stat": "Average" } ]
],
"period": 300,
"stacked": false,
"yAxis": {
"left": {
"min": 0.1,
"max": 1
},
"right": {
"min": 0
}
},
"title": "CPU",
"annotations": {
"horizontal": [
{
"color": "#ff6961",
"label": "Troublethresholdstart",
"fill": "above",
"value": 0.5
}
],
"vertical": [
{
"visible": true,
"color": "#9467bd",
"label": "Bugfixdeployed",
"value": "2018-11-19T07:25:26Z",
"fill": "after"
}
]
},
"view": "timeSeries"
}'
Response to this will be a base64 encoded image, like this:
{
"MetricWidgetImage": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAGLEAYA..."
}
If you need the raw png image, you'll need to decode the response by doing something like this:
aws cloudwatch get-metric-widget-image --metric-widget 'JSON_GOES_HERE' | grep MetricWidgetImage | awk '{split($0,a,"""); print a[4]}' | base64 --decode > graph.png
Thank you so much,Tartaglia! Very detailed answer. I am a green hand at AWS. It works for me and I could get the correct picture.
– ingsnow kwan
Nov 20 '18 at 9:13
add a comment |
The best way to get the correct json for your request is to use CloudWatch Console to construct the graph, then click on the Source
tab, select Image API
view and click Copy Source
to copy the json generated there. You also need to wrap the json in single quotes, like this:
aws cloudwatch get-metric-widget-image --metric-widget
'{
"width": 600,
"height": 395,
"metrics": [
[ "AWS/EC2", "CPUUtilization", "InstanceId", "i-01234567890123456", { "stat": "Average" } ]
],
"period": 300,
"stacked": false,
"yAxis": {
"left": {
"min": 0.1,
"max": 1
},
"right": {
"min": 0
}
},
"title": "CPU",
"annotations": {
"horizontal": [
{
"color": "#ff6961",
"label": "Troublethresholdstart",
"fill": "above",
"value": 0.5
}
],
"vertical": [
{
"visible": true,
"color": "#9467bd",
"label": "Bugfixdeployed",
"value": "2018-11-19T07:25:26Z",
"fill": "after"
}
]
},
"view": "timeSeries"
}'
Response to this will be a base64 encoded image, like this:
{
"MetricWidgetImage": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAGLEAYA..."
}
If you need the raw png image, you'll need to decode the response by doing something like this:
aws cloudwatch get-metric-widget-image --metric-widget 'JSON_GOES_HERE' | grep MetricWidgetImage | awk '{split($0,a,"""); print a[4]}' | base64 --decode > graph.png
The best way to get the correct json for your request is to use CloudWatch Console to construct the graph, then click on the Source
tab, select Image API
view and click Copy Source
to copy the json generated there. You also need to wrap the json in single quotes, like this:
aws cloudwatch get-metric-widget-image --metric-widget
'{
"width": 600,
"height": 395,
"metrics": [
[ "AWS/EC2", "CPUUtilization", "InstanceId", "i-01234567890123456", { "stat": "Average" } ]
],
"period": 300,
"stacked": false,
"yAxis": {
"left": {
"min": 0.1,
"max": 1
},
"right": {
"min": 0
}
},
"title": "CPU",
"annotations": {
"horizontal": [
{
"color": "#ff6961",
"label": "Troublethresholdstart",
"fill": "above",
"value": 0.5
}
],
"vertical": [
{
"visible": true,
"color": "#9467bd",
"label": "Bugfixdeployed",
"value": "2018-11-19T07:25:26Z",
"fill": "after"
}
]
},
"view": "timeSeries"
}'
Response to this will be a base64 encoded image, like this:
{
"MetricWidgetImage": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAGLEAYA..."
}
If you need the raw png image, you'll need to decode the response by doing something like this:
aws cloudwatch get-metric-widget-image --metric-widget 'JSON_GOES_HERE' | grep MetricWidgetImage | awk '{split($0,a,"""); print a[4]}' | base64 --decode > graph.png
edited Nov 20 '18 at 8:14
answered Nov 20 '18 at 8:08
TartagliaTartaglia
2,06211326
2,06211326
Thank you so much,Tartaglia! Very detailed answer. I am a green hand at AWS. It works for me and I could get the correct picture.
– ingsnow kwan
Nov 20 '18 at 9:13
add a comment |
Thank you so much,Tartaglia! Very detailed answer. I am a green hand at AWS. It works for me and I could get the correct picture.
– ingsnow kwan
Nov 20 '18 at 9:13
Thank you so much,Tartaglia! Very detailed answer. I am a green hand at AWS. It works for me and I could get the correct picture.
– ingsnow kwan
Nov 20 '18 at 9:13
Thank you so much,Tartaglia! Very detailed answer. I am a green hand at AWS. It works for me and I could get the correct picture.
– ingsnow kwan
Nov 20 '18 at 9:13
add a comment |
JSONLint says that you've got one extra }
at the end of your JSON. Also, try wrapping the whole JSON block with single quotes '
for easier differentiating and no need to escape the double quotes in the JSON string.
This should work for you:
aws cloudwatch get-metric-widget-image --metric-widget '{ "width":600,"height":395,"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-01234567890123456",{"stat":"Average"}]],"period":300,"start":"-P30D","end":"PT0H","stacked":false,"yAxis":{"left":{"min":0.1,"max":1},"right":{"min":0}},"title":"CPU","annotations":{"horizontal":[{"color":"#ff6961","label":"Troublethresholdstart","fill":"above","value":0.5}], "vertical":[{"visible":true, "color":"#9467bd","label":"Bugfixdeployed","value":"2018-11-19T07:25:26Z","fill":"after"}]}}' --output-format "png"
add a comment |
JSONLint says that you've got one extra }
at the end of your JSON. Also, try wrapping the whole JSON block with single quotes '
for easier differentiating and no need to escape the double quotes in the JSON string.
This should work for you:
aws cloudwatch get-metric-widget-image --metric-widget '{ "width":600,"height":395,"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-01234567890123456",{"stat":"Average"}]],"period":300,"start":"-P30D","end":"PT0H","stacked":false,"yAxis":{"left":{"min":0.1,"max":1},"right":{"min":0}},"title":"CPU","annotations":{"horizontal":[{"color":"#ff6961","label":"Troublethresholdstart","fill":"above","value":0.5}], "vertical":[{"visible":true, "color":"#9467bd","label":"Bugfixdeployed","value":"2018-11-19T07:25:26Z","fill":"after"}]}}' --output-format "png"
add a comment |
JSONLint says that you've got one extra }
at the end of your JSON. Also, try wrapping the whole JSON block with single quotes '
for easier differentiating and no need to escape the double quotes in the JSON string.
This should work for you:
aws cloudwatch get-metric-widget-image --metric-widget '{ "width":600,"height":395,"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-01234567890123456",{"stat":"Average"}]],"period":300,"start":"-P30D","end":"PT0H","stacked":false,"yAxis":{"left":{"min":0.1,"max":1},"right":{"min":0}},"title":"CPU","annotations":{"horizontal":[{"color":"#ff6961","label":"Troublethresholdstart","fill":"above","value":0.5}], "vertical":[{"visible":true, "color":"#9467bd","label":"Bugfixdeployed","value":"2018-11-19T07:25:26Z","fill":"after"}]}}' --output-format "png"
JSONLint says that you've got one extra }
at the end of your JSON. Also, try wrapping the whole JSON block with single quotes '
for easier differentiating and no need to escape the double quotes in the JSON string.
This should work for you:
aws cloudwatch get-metric-widget-image --metric-widget '{ "width":600,"height":395,"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-01234567890123456",{"stat":"Average"}]],"period":300,"start":"-P30D","end":"PT0H","stacked":false,"yAxis":{"left":{"min":0.1,"max":1},"right":{"min":0}},"title":"CPU","annotations":{"horizontal":[{"color":"#ff6961","label":"Troublethresholdstart","fill":"above","value":0.5}], "vertical":[{"visible":true, "color":"#9467bd","label":"Bugfixdeployed","value":"2018-11-19T07:25:26Z","fill":"after"}]}}' --output-format "png"
answered Nov 20 '18 at 6:50
Gabe HollombeGabe Hollombe
5,66333140
5,66333140
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387313%2fhow-to-use-aws-cloudwatch-get-metric-widget-image%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown