Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / nova / nova_floating_ips @ d168d49e

Historique | Voir | Annoter | Télécharger (2,16 ko)

1
#!/usr/bin/env python3
2
"""
3

    
4
=head1 NAME
5

    
6
nova_floating_ips - monitor status of Floating IPs in Nova
7

    
8

    
9
=head1 CONFIGURATION
10

    
11
To monitor a floating ips, link floating_ips to this file.
12
E.g.
13

    
14
 ln -s /usr/share/munin/plugins/nova_floating_ips /etc/munin/plugins/
15

    
16
Needs following minimal configuration in plugin-conf.d/nova:
17

    
18
 [nova_*]
19
 user nova
20

    
21

    
22
=head1 AUTHORS
23

    
24
Copyright 2012 Mehdi Abaakouk <sileht@sileht.net>
25

    
26

    
27
=head1 MAGIC MARKERS
28

    
29
 #%# capabilities=autoconf
30
 #%# family=auto
31

    
32
=cut
33
"""
34

    
35
import sys
36

    
37
try:
38
    from nova import context
39
    from nova import db
40
    from nova import flags
41
    from nova import utils
42
except ImportError:
43
    successful_import = False
44
else:
45
    successful_import = True
46

    
47

    
48
states = ['total', 'allocated', 'associated']
49

    
50

    
51
def print_config():
52
    global states
53
    print('graph_title Nova Floating IPs')
54
    print('graph_vlabel IPs')
55
    print('graph_args --base 1000 --lower-limit 0')
56
    print('graph_category cloud')
57
    print('graph_scale no')
58
    print('graph_info This graph shows the number of Floating IPs in Nova and their status')
59
    for state in states:
60
        print('%s.label %s' % (state, state))
61
        print('%s.draw LINE2' % state)
62
        print('%s.info %s IPs' % (state, state))
63

    
64

    
65
def get_status():
66
    status = {}
67
    for k in states:
68
        status[k] = 0
69

    
70
    ctxt = context.get_admin_context()
71
    floating_ips = db.floating_ip_get_all(ctxt)
72
    for floating_ip in floating_ips:
73
        status['total'] += 1
74
        if floating_ip['fixed_ip_id']:
75
            status['associated'] += 1
76
        if floating_ip['project_id']:
77
            status['allocated'] += 1
78

    
79
    return status
80

    
81

    
82
def print_values():
83
    status = get_status()
84
    for (state, value) in status.items():
85
        print("%s.value %s" % (state, value))
86

    
87

    
88
if __name__ == '__main__':
89
    if len(sys.argv) > 1:
90
        if sys.argv[1] == "config":
91
            print_config()
92
        elif sys.argv[1] == "autoconf":
93
            if not successful_import:
94
                print('no (failed import nova module)')
95
                sys.exit(0)
96
            else:
97
                print('yes')
98
    elif successful_import:
99
        utils.default_flagfile()
100
        flags.FLAGS(sys.argv)
101
        print_values()