root / plugins / nova / nova_floating_ips @ 33cff547
Historique | Voir | Annoter | Télécharger (2,03 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monitor status of Floating IPs in Nova |
| 4 |
# |
| 5 |
# To monitor a floating ips, link floating_ips to this file. |
| 6 |
# E.g. |
| 7 |
# ln -s /usr/share/munin/plugins/nova_floating_ips /etc/munin/plugins/ |
| 8 |
# |
| 9 |
# Needs following minimal configuration in plugin-conf.d/nova: |
| 10 |
# [nova_*] |
| 11 |
# user nova |
| 12 |
# |
| 13 |
# Magic markers |
| 14 |
#%# capabilities=autoconf |
| 15 |
#%# family=auto |
| 16 |
|
| 17 |
import sys |
| 18 |
|
| 19 |
try: |
| 20 |
from nova import context |
| 21 |
from nova import db |
| 22 |
from nova import flags |
| 23 |
from nova import utils |
| 24 |
except ImportError: |
| 25 |
succesful_import = False |
| 26 |
else: |
| 27 |
succesful_import = True |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
states = ['total', 'allocated', 'associated'] |
| 32 |
|
| 33 |
def print_config(): |
| 34 |
global states |
| 35 |
print 'graph_title Nova Floating IPs' |
| 36 |
print 'graph_vlabel IPs' |
| 37 |
print 'graph_args --base 1000 --lower-limit 0' |
| 38 |
print 'graph_category nova' |
| 39 |
print 'graph_scale no' |
| 40 |
print 'graph_info This graph shows the number of Floating IPs in Nova and their status' |
| 41 |
for state in states: |
| 42 |
print '%s.label %s' % (state, state) |
| 43 |
print '%s.draw LINE2' % state |
| 44 |
print '%s.info %s IPs' % (state, state) |
| 45 |
|
| 46 |
|
| 47 |
def get_status(): |
| 48 |
status = {}
|
| 49 |
for k in states: |
| 50 |
status[k] = 0 |
| 51 |
|
| 52 |
ctxt = context.get_admin_context() |
| 53 |
floating_ips = db.floating_ip_get_all(ctxt) |
| 54 |
for floating_ip in floating_ips: |
| 55 |
status['total'] += 1 |
| 56 |
if floating_ip['fixed_ip_id']: |
| 57 |
status['associated'] += 1 |
| 58 |
if floating_ip['project_id']: |
| 59 |
status['allocated'] += 1 |
| 60 |
|
| 61 |
return status |
| 62 |
|
| 63 |
|
| 64 |
def print_values(): |
| 65 |
status = get_status() |
| 66 |
for (state, value) in status.iteritems(): |
| 67 |
print "%s.value %s" % (state, value) |
| 68 |
|
| 69 |
|
| 70 |
if __name__ == '__main__': |
| 71 |
if len(sys.argv) > 1: |
| 72 |
if sys.argv[1] == "config": |
| 73 |
print_config() |
| 74 |
elif sys.argv[1] == "autoconf": |
| 75 |
if not succesful_import: |
| 76 |
print 'no (failed import nova module)' |
| 77 |
sys.exit(0) |
| 78 |
else: |
| 79 |
print 'yes' |
| 80 |
elif succesful_import: |
| 81 |
utils.default_flagfile() |
| 82 |
flags.FLAGS(sys.argv) |
| 83 |
print_values() |
