Reputation: 257
I am trying to get elasticsearch cloud-watch metrics using boto but whatever I do, I do not get the value. Below is snippet of my code , same code works for example if I use for RDS metrics.
import datetime
import boto.ec2.cloudwatch
end = datetime.datetime.utcnow()
start = end - datetime.timedelta(minutes=5)
metric="CPUUtilization"
region = boto.regioninfo.RegionInfo(
name='ap-southeast-1',
endpoint='monitoring.ap-southeast-1.amazonaws.com')
conn = boto.ec2.cloudwatch.CloudWatchConnection(region=region)
data = conn.get_metric_statistics(60, start, end, metric, "AWS/ES", "Average", {"DomainName": "My-es-name"})
print data
[]
However if I change the namespace to RDS it works fine with proper dimension value. This is a simple code which I can write. I am not sure what is wrong here. Can anyone help me to figure out this?
What am I doing wrong here?
Thanks
Upvotes: 1
Views: 853
Reputation: 1098
I found the solution.
To pull Elasticsearch metrics for a specific domain name, you need to also indicate your ClientId in the dimensions.
My examples below are in Boto3, but for executing it with your code (boto2), I believe you only need to amend the dimensions as follow, assuming your syntax was originally right:
data = conn.get_metric_statistics(60, start, end, metric, "AWS/ES", "Average", {"ClientId":"My-client-id", "DomainName": "My-es-name"})
Try the code below (boto3). It worked for me.
import boto3
from datetime import datetime, timedelta
cloudwatch = boto3.resource('cloudwatch', region_name='ap-southeast-1')
cpu = cloudwatch.Metric('AWS/ES', 'CPUUtilization')
cpu_usage = cpu.get_statistics(
Dimensions=[
{'Name': 'ClientId', 'Value': 'YOUR-CLIENT-ID'},
{'Name': 'DomainName', 'Value': 'YOUR-DOMAIN-NAME'}
],
StartTime=(datetime.utcnow() - timedelta(minutes=5)).isoformat(),
EndTime=datetime.utcnow().isoformat(),
Period=60,
Statistics=['Average']
)
If you prefer to use a client, use the following instead:
client = boto3.client('cloudwatch', region_name='ap-southeast-1')
response = client.get_metric_statistics(
Namespace='AWS/ES',
MetricName='CPUUtilization',
Dimensions=[
{'Name': 'ClientId', 'Value': 'YOUR-CLIENT-ID'},
{'Name': 'DomainName', 'Value': 'YOUR-DOMAIN-NAME'}
],
StartTime=(datetime.utcnow() - timedelta(minutes=5)).isoformat(),
EndTime=datetime.utcnow().isoformat(),
Period=60,
Statistics=['Average']
)
Upvotes: 5