#NEWLINE# def metric_network( asg_name , definition , configuration , args , info , force ) : #NEWLINE# #INDENT# period = int ( configuration . get ( 'Period' , 300 ) ) #NEWLINE# evaluation_periods = int ( configuration . get ( 'EvaluationPeriods' , 2 ) ) #NEWLINE# statistic = configuration . get ( 'Statistic' , 'Average' ) #NEWLINE# scale_up_threshold = normalize_network_threshold ( configuration [ 'ScaleUpThreshold' ] ) #NEWLINE# scale_down_threshold = normalize_network_threshold ( configuration [ 'ScaleDownThreshold' ] ) #NEWLINE# if ( 'ScaleUpThreshold' in configuration ) : #NEWLINE# #INDENT# definition [ 'Resources' ] [ ( asg_name + 'NetworkAlarmHigh' ) ] = { #NEWLINE# #INDENT# 'Type' : 'AWS::CloudWatch::Alarm' , #NEWLINE# 'Properties' : { #NEWLINE# #INDENT# 'MetricName' : configuration [ 'MetricType' ] , #NEWLINE# 'Namespace' : 'AWS/EC2' , #NEWLINE# 'Period' : str ( period ) , #NEWLINE# 'Threshold' : scale_up_threshold [ 0 ] , #NEWLINE# 'Unit' : scale_up_threshold [ 1 ] , #NEWLINE# 'EvaluationPeriods' : str ( evaluation_periods ) , #NEWLINE# 'Statistic' : statistic , #NEWLINE# 'ComparisonOperator' : 'GreaterThanThreshold' , #NEWLINE# 'Dimensions' : [ { #NEWLINE# #INDENT# 'Name' : 'AutoScalingGroupName' , #NEWLINE# 'Value' : { #NEWLINE# #INDENT# 'Ref' : asg_name , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'AlarmDescription' : 'Scale-up if {} > {} {} for {} minutes ({})' . format ( configuration [ 'MetricType' ] , scale_up_threshold [ 0 ] , scale_up_threshold [ 1 ] , ( ( period / 60 ) * evaluation_periods ) , statistic ) , #NEWLINE# 'AlarmActions' : [ { #NEWLINE# #INDENT# 'Ref' : ( asg_name + 'ScaleUp' ) , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( 'ScaleDownThreshold' in configuration ) : #NEWLINE# #INDENT# definition [ 'Resources' ] [ ( asg_name + 'NetworkAlarmLow' ) ] = { #NEWLINE# #INDENT# 'Type' : 'AWS::CloudWatch::Alarm' , #NEWLINE# 'Properties' : { #NEWLINE# #INDENT# 'MetricName' : configuration [ 'MetricType' ] , #NEWLINE# 'Namespace' : 'AWS/EC2' , #NEWLINE# 'Threshold' : scale_down_threshold [ 0 ] , #NEWLINE# 'Unit' : scale_down_threshold [ 1 ] , #NEWLINE# 'Period' : str ( period ) , #NEWLINE# 'EvaluationPeriods' : str ( evaluation_periods ) , #NEWLINE# 'Statistic' : statistic , #NEWLINE# 'ComparisonOperator' : 'LessThanThreshold' , #NEWLINE# 'Dimensions' : [ { #NEWLINE# #INDENT# 'Name' : 'AutoScalingGroupName' , #NEWLINE# 'Value' : { #NEWLINE# #INDENT# 'Ref' : asg_name , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'AlarmDescription' : 'Scale-down if {} < {} {} for {} minutes ({})' . format ( configuration [ 'MetricType' ] , scale_down_threshold [ 0 ] , scale_down_threshold [ 1 ] , ( ( period / 60 ) * evaluation_periods ) , statistic ) , #NEWLINE# 'AlarmActions' : [ { #NEWLINE# #INDENT# 'Ref' : ( asg_name + 'ScaleDown' ) , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# return definition