Exemple #1
0
def get_osd_statistics(client=None,
                       keyring=None,
                       osd_ids=None,
                       container_name=None):
    osd_dump = get_ceph_osd_dump(client=client,
                                 keyring=keyring,
                                 container_name=container_name)
    pg_osds_dump = get_ceph_pg_dump_osds(client=client,
                                         keyring=keyring,
                                         container_name=container_name)
    for osd_id in osd_ids:
        osd_ref = 'osd.%s' % osd_id
        for _osd in osd_dump['osds']:
            if _osd['osd'] == osd_id:
                osd = _osd
                break
        else:
            msg = 'The OSD ID %s does not exist.' % osd_id
            raise maas_common.MaaSException(msg)

        key = 'up'
        name = '_'.join((osd_ref, key))
        maas_common.metric_bool(name, osd[key])

        for _osd in pg_osds_dump:
            if _osd['osd'] == osd_id:
                osd = _osd
                break
Exemple #2
0
def get_metrics_lxc_container(container_name):
    # Create lxc container object
    cont = lxc.Container(container_name)
    container_pid = int(cont.init_pid)
    if not (container_pid > 1 and cont.running and cont.state == "RUNNING"):
        raise maas_common.MaaSException('Container %s not in running state' %
                                        cont.name)

    with NsEnter(pid=container_pid, ns_type='net'):
        return get_metrics()
Exemple #3
0
def main():
    try:
        if not args.container:
            metrics = get_metrics()
        else:
            if not lxc_module_active:
                raise maas_common.MaaSException('Container monitoring '
                                                'requested but lxc-python '
                                                'pip module not installed.')
            metrics = get_metrics_lxc_container(args.container)

    except maas_common.MaaSException as e:
        maas_common.status_err(str(e), m_name='maas_conntrack')
    else:
        maas_common.status_ok(m_name='maas_conntrack')
        for name, data in metrics.viewitems():
            maas_common.metric(name, 'uint32', data['value'])
Exemple #4
0
def get_osd_statistics(report=None, osd_ids=None):
    for osd_id in osd_ids:
        osd_ref = 'osd.%s' % osd_id
        for _osd in report['osdmap']['osds']:
            if _osd['osd'] == osd_id:
                osd = _osd
                break
        else:
            msg = 'The OSD ID %s does not exist.' % osd_id
            raise maas_common.MaaSException(msg)
        for key in ('up', 'in'):
            name = '_'.join((osd_ref, key))
            maas_common.metric_bool(name, osd[key])

        for _osd in report['pgmap']['osd_stats']:
            if _osd['osd'] == osd_id:
                osd = _osd
                break
        for key in ('kb', 'kb_used', 'kb_avail'):
            name = '_'.join((osd_ref, key))
            maas_common.metric(name, 'uint64', osd[key])
Exemple #5
0
def get_osd_statistics(client=None, keyring=None, osd_ids=None):
    osd_dump = get_ceph_osd_dump(client=client, keyring=keyring)
    pg_osds_dump = get_ceph_pg_dump_osds(client=client, keyring=keyring)
    for osd_id in osd_ids:
        osd_ref = 'osd.%s' % osd_id
        for _osd in osd_dump['osds']:
            if _osd['osd'] == osd_id:
                osd = _osd
                break
        else:
            msg = 'The OSD ID %s does not exist.' % osd_id
            raise maas_common.MaaSException(msg)
        for key in ('up', 'in'):
            name = '_'.join((osd_ref, key))
            maas_common.metric_bool(name, osd[key])

        for _osd in pg_osds_dump:
            if _osd['osd'] == osd_id:
                osd = _osd
                break
        for key in ('kb', 'kb_used', 'kb_avail'):
            name = '_'.join((osd_ref, key))
            maas_common.metric('ceph_osd', name, osd[key])
Exemple #6
0
def get_metrics_lxc_container(container_name=''):

    # Return 0 values if we can't determine current state
    # from a container
    metrics = {
        'nf_conntrack_count': {
            'value': 0
        },
        'nf_conntrack_max': {
            'value': 0
        }
    }

    # Create lxc container object
    cont = lxc.Container(container_name)

    if not (cont.init_pid > 1 and cont.running and cont.state == "RUNNING"):
        raise maas_common.MaaSException('Container %s not in running state' %
                                        cont.name)

    # Check if container is even running
    try:
        with tempfile.TemporaryFile() as tmpfile:
            # Retrieve root namespace count
            if cont.attach_wait(lxc.attach_run_command, [
                    'cat', '/proc/sys/net/netfilter/nf_conntrack_count',
                    '/proc/sys/net/netfilter/nf_conntrack_max'
            ],
                                stdout=tmpfile,
                                stderr=tempfile.TemporaryFile()) > -1:

                tmpfile.seek(0)
                output = tmpfile.read()
                metrics = {
                    'nf_conntrack_count': {
                        'value': output.split('\n')[0]
                    },
                    'nf_conntrack_max': {
                        'value': output.split('\n')[1]
                    }
                }

        # Retrieve conntrack count per namespace
        # and report the namespace with the highest count.
        # This is necessary to limit the number of metrics to report to MAAS,
        # as we can not report a metric per namespace, which by nature are
        # also volatile.
        with tempfile.TemporaryFile() as nsfile:
            if cont.attach_wait(lxc.attach_run_command,
                                ['ls', '-1', '/var/run/netns'],
                                stdout=nsfile,
                                stderr=tempfile.TemporaryFile()) > -1:
                nsfile.seek(0)

                for line in nsfile.readlines():
                    ns = line.strip(os.linesep)
                    nscountfile = tempfile.TemporaryFile()

                    if cont.attach_wait(lxc.attach_run_command, [
                            'ip', 'netns', 'exec', ns, 'cat',
                            '/proc/sys/net/netfilter/'
                            'nf_conntrack_count'
                    ],
                                        stdout=nscountfile,
                                        stderr=tempfile.TemporaryFile()) > -1:

                        nscountfile.seek(0)
                        nscount = int(nscountfile.read().strip(os.linesep))

                        if nscount > metrics['nf_conntrack_count']['value']:
                            metrics['nf_conntrack_count']['value'] = nscount

        return metrics

    except maas_common.MaaSException as e:
        maas_common.status_err(str(e), m_name='maas_conntrack')