Skip to content

Instantly share code, notes, and snippets.

@haitaoyao
Created July 6, 2017 13:51
Show Gist options
  • Save haitaoyao/80737861081a4dacb7c51201e49c7984 to your computer and use it in GitHub Desktop.
Save haitaoyao/80737861081a4dacb7c51201e49c7984 to your computer and use it in GitHub Desktop.
Get rds replica lag metric value
def get_cloudwatch_replica_lag(rds_id, start_time, end_time)
local_timezone = pytz.timezone('Asia/Shanghai')
cloudwatch = boto3.client('cloudwatch')
start_time_with_tz = local_timezone.localize(start_time)
end_time_with_tz = local_timezone.localize(end_time)
values = cloudwatch.get_metric_statistics(Namespace='AWS/RDS',
MetricName='ReplicaLag',
Dimensions=[dict(Name='DBInstanceIdentifier', Value=rds_id)],
StartTime=start_time_with_tz,
EndTime=end_time_with_tz,
Period=60,
Statistics=['Maximum'],
Unit='Seconds').get('Datapoints')
return values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment