Repository
Munin (contrib)
Last change
2020-11-26
Graph Categories
Family
auto
Capabilities
Keywords
Language
Python (3.x)
Authors

nova_floating_ips

Name

nova_floating_ips - monitor status of Floating IPs in Nova

Configuration

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

Authors

Copyright 2012 Mehdi Abaakouk sileht@sileht.net

Magic Markers

#%# capabilities=autoconf
#%# family=auto
#!/usr/bin/env python3
"""

=head1 NAME

nova_floating_ips - monitor status of Floating IPs in Nova


=head1 CONFIGURATION

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


=head1 AUTHORS

Copyright 2012 Mehdi Abaakouk <sileht@sileht.net>


=head1 MAGIC MARKERS

 #%# capabilities=autoconf
 #%# family=auto

=cut
"""

import sys

try:
    from nova import context
    from nova import db
    from nova import flags
    from nova import utils
except ImportError:
    successful_import = False
else:
    successful_import = True


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


def print_config():
    global states
    print('graph_title Nova Floating IPs')
    print('graph_vlabel IPs')
    print('graph_args --base 1000 --lower-limit 0')
    print('graph_category cloud')
    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_id']:
            status['associated'] += 1
        if floating_ip['project_id']:
            status['allocated'] += 1

    return status


def print_values():
    status = get_status()
    for (state, value) in status.items():
        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":
            if not successful_import:
                print('no (failed import nova module)')
                sys.exit(0)
            else:
                print('yes')
    elif successful_import:
        utils.default_flagfile()
        flags.FLAGS(sys.argv)
        print_values()