Skip to content

Instantly share code, notes, and snippets.

@jaylett
Created July 27, 2012 10:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaylett/3187317 to your computer and use it in GitHub Desktop.
Save jaylett/3187317 to your computer and use it in GitHub Desktop.
ELB status plugin for munin
#!/usr/bin/python
# -*- python-mode -*-
import boto.ec2.elb
import sys
elbs = [ 'my_elb' ] # or whatever
AWS_ACCESS_KEY_ID = '' # fill this out!
AWS_SECRET_ACCESS_KEY = '' # this too!
def _name(elb):
"""Convert to a munin-compatible name"""
return elb.replace('-', '_')
if len(sys.argv) > 1 and sys.argv[1]=='config':
print """multigraph elb_status
graph_title Instances across all ELBs
graph_vlabel Active instances
graph_args -l 0
graph_category Other
graph_info Number of ELB instances in different states (inservice, outofservice &c)
inservice.label In service
outofservice.label Out of service
"""
for elb in elbs:
print """multigraph elb_status.%(elb)s
graph_title Instances in %(elb)s
graph_vlabel Active instances
graph_args -l 0
graph_category Other
graph_info Number of ELB instances in different states (inservice, outofservice &c)
inservice.label In service
inservice.warning 2:
inservice.critical 1:
outofservice.label Out of service
outofservice.warning 1
""" % { 'elb': _name(elb) }
sys.exit(0)
# connect to EC2, find our ELBs, describe instance health for each
# and turn that into awesome data.
c = boto.ec2.elb.ELBConnection(aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
total_inservice = 0
total_outofservice = 0
for elb in elbs:
inservice = outofservice = 0
for instance_state in c.describe_instance_health(elb):
if instance_state.state==u'InService':
inservice += 1
elif instance_state.state==u'OutOfService':
outofservice += 1
else:
# eek!
pass
print "multigraph elb_status.%(elb)s" % { 'elb': _name(elb) }
print "inservice.value %(count)i" % {
'elb': _name(elb),
'count': inservice,
}
print "outofservice.value %(count)i" % {
'elb': _name(elb),
'count': outofservice,
}
total_inservice += inservice
total_outofservice += outofservice
print "multigraph elb_status"
print "inservice.value %i" % total_inservice
print "outofservice.value %i" % total_outofservice
@DavidGoodwin
Copy link

I was clearly too stupid to get the right versions of boto or something and this didn't work for me.
However a bash based plugin based around :

aws elb describe-instance-health --load-balancer-name=mylbname --query "InstanceStates[?State!='InService'].InstanceId" --output text
and
aws elb describe-instance-health --load-balancer-name=mylbname --query "InstanceStates[?State=='InService'].InstanceId" --output text

seemed to work well enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment