-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnova_floating_ips
executable file
·72 lines (60 loc) · 1.76 KB
/
nova_floating_ips
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
#
# Plugin to monitor status of Floating IPs in Nova
#
# To monitor a floating ips, link floating_ips to this file.
# E.g.
# ln -s /usr/share/munin/plugins/nova_floating_ips /etc/munin/plugins/
#
# Needs following minimal configuration in plugin-conf.d/nova:
# [nova_*]
# user nova
#
# Magic markers
#%# capabilities=autoconf
#%# family=nova
from nova import context
from nova import db
from nova import flags
from nova import utils
import sys
states = ['total', 'allocated', 'associated']
def print_config():
global states
print 'graph_title Nova Floating IPs'
print 'graph_vlabel %'
print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category nova'
print 'graph_scale no'
print 'graph_info This graph shows the number of Floating IPs in Nova and their status'
for state in states:
print '%s.label %s' % (state, state)
print '%s.draw LINE2' % state
print '%s.info %s IPs' % (state, state)
def get_status():
status = {}
for k in states:
status[k] = 0
ctxt = context.get_admin_context()
floating_ips = db.floating_ip_get_all(ctxt)
for floating_ip in floating_ips:
status['total'] += 1
if floating_ip['fixed_ip']:
status['associated'] += 1
if floating_ip['project_id']:
status['allocated'] += 1
return status
def print_values():
status = get_status()
for (state, value) in status.iteritems():
print "%s.value %s" % (state, value)
if __name__ == '__main__':
if len(sys.argv) > 1:
if sys.argv[1] == "config":
print_config()
elif sys.argv[1] == "autoconf":
print "yes"
else:
utils.default_flagfile()
flags.FLAGS(sys.argv)
print_values()