Quote
"Program to create EBS Volumes Metric alarm in AWS lambda python"

In this article, I have given a code which can be used as reference while writing a  program for EBS Volumes Metric alarm in AWS lambda python.

###########################################################################
#########
######### EBS Volumes
#########
###########################################################################

vol_id = instance.volumes.all()
for v in vol_id:

if logging_verbosity > 2:
print("Found EBS volume %s on instance %s" % (v.id, instanceid))

###############################################
#Create Metric "Volume Idle Time <= 30 sec (of 5 minutes) for 30 Minutes
severity = "Warning"
alarm_title = "Low_Volume_Idle_Time"
response = cw.put_metric_alarm(
AlarmName = "%s_%s_%s_%s_(Lambda)" % (severity, nameinstance, v.id, alarm_title),
#AlarmName="%s %s High Volume Activity Warning" % (v.id, instanceid),
AlarmDescription='Volume Idle Time <= 30 sec (of 5 minutes) for 30 Minutes',
ActionsEnabled=True,
AlarmActions=[
ec2_sns
],
MetricName='VolumeIdleTime',
Namespace='AWS/EBS',
Statistic='Average',
Dimensions=[
{
'Name': 'VolumeId',
'Value': v.id
},
],
Period=300,
EvaluationPeriods=6,
Threshold=30.0,
ComparisonOperator='LessThanOrEqualToThreshold'
)
if logging_verbosity > 9:
print (response)

###############################################
#Create Metric "Volume Idle Time <= 30 sec (of 5 minutes) for 60 Minutes
severity = "Critical"
alarm_title = "Low_Volume_Idle_Time"
response = cw.put_metric_alarm(
AlarmName = "%s_%s_%s_%s_(Lambda)" % (severity, nameinstance, v.id, alarm_title),
#AlarmName="%s %s High Volume Activity Critical" % (v.id, instanceid),
AlarmDescription='Volume Idle Time <= 30 sec (of 5 minutes) for 60 Minutes',
ActionsEnabled=True,
AlarmActions=[
ec2_sns
],
MetricName='VolumeIdleTime',
Namespace='AWS/EBS',
Statistic='Average',
Dimensions=[
{
'Name': 'VolumeId',
'Value': v.id
},
],
Period=300,
EvaluationPeriods=12,
Threshold=30.0,
ComparisonOperator='LessThanOrEqualToThreshold'
)

###########################################################################
#########
######### Instance Level EBS Metrics
#########
###########################################################################

# Nitro does not seem to provide these...
if (instance.hypervisor == 'xen'):
###############################################
#Create DiskWriteOps Alarms
severity = "Warning"
alarm_title = "DiskWriteOps"
response = cw.put_metric_alarm(
AlarmName = "%s_%s_%s_(Lambda)" % (severity, nameinstance, alarm_title),
#AlarmName = (nameinsta) +"_DiskWriteOps_(Lambda)",
AlarmDescription='DiskWriteOps ',
ActionsEnabled=True,
AlarmActions=[ec2_sns,],
MetricName='DiskWriteOps',
Namespace='AWS/EC2',
Statistic='Average',
Dimensions=[ {'Name': "InstanceId",'Value': instanceid},],
Period=900,
EvaluationPeriods=1,
Threshold=2500,
ComparisonOperator='GreaterThanOrEqualToThreshold'
)
if logging_verbosity > 9:
print (response)

###############################################
#Create DiskReadOps Alarms
severity = "Warning"
alarm_title = "DiskReadOps"
response = cw.put_metric_alarm(
AlarmName = "%s_%s_%s_(Lambda)" % (severity, nameinstance, alarm_title),
#AlarmName= (nameinsta) +"_DiskReadOps_(Lambda)",
AlarmDescription='DiskReadOps ',
ActionsEnabled=True,
AlarmActions=[ec2_sns,],
MetricName='DiskReadOps',
Namespace='AWS/EC2',
Statistic='Average',
Dimensions=[ {'Name': "InstanceId",'Value': instanceid},],
Period=900,
EvaluationPeriods=1,
Threshold=2500,
ComparisonOperator='GreaterThanOrEqualToThreshold'
)
if logging_verbosity > 9:
print (response)

“If you are passionate about technology and like to share your knowledge or the latest on technology, mail us on info@saniconservices.com and get featured on our blog page”

I hope you find this program useful to create EBS Volumes Metric alarm in AWS lambda python. Feel free to ask your valuable questions in the comments section below.

About SANICON IT SERVICES PVT. LTD.: Over the years SANICON – A One-Stop Cloud Solution Company have provided the most credible cutting-edge IT technology & services across various domains which helped customers around the world to start and grow their businesses and their digital transformation to cloud.

Reach out to us today at sales@saniconservices.com to get a reliable and affordable cloud managed service and IT technology partner

Visit website www.saniconservices.com to learn more about all great products and services offered.

Leave a Reply

Your email address will not be published. Required fields are marked *