Does someone have a boto3 example of how to get the same results as this AWS CLI command:
aws cloudwatch list-metrics --namespace "CWAgent" --metric-name "LogicalDisk % Free Space" --query Metrics[*]
I am trying to get the value for these Dimensions:
instance, InstanceId, ImageId, objectname, InstanceType
This is the code I am trying to use:
import boto3
# Create CloudWatch client
client = boto3.client('cloudwatch')
obj = []
response = client.list_metrics(
Namespace='CWagent',
MetricName='LogicalDisk % Free Space',
Dimensions=[
{
'Name': 'instance',
'Value': obj
},
{
'Name': 'InstanceId',
'Value': obj
},
{
'Name': 'ImageId',
'Value': obj
},
{
'Name': 'objectname',
'Value': obj
},
{
'Name': 'InstanceType',
'Value': obj
},
],
NextToken='string'
)
for r in response:
a = instance
b = InstanceId
c = ImageId
d = objectname
e = InstanceType
print(a, b, c, d, e)
This boto3 code will access the CWAgent Metrics Dimensions form an individual instance or all instances on how you set the instances variable: `
`