def check(args):
    cinder = get_openstack_client('block_storage')

    try:
        local_vol_url = generate_local_endpoint(
            str(cinder.get_endpoint()), args.ip, args.port,
            args.protocol, '/volumes/detail'
        )
        vol = cinder.session.get(local_vol_url, timeout=180)

        local_snap_url = generate_local_endpoint(
            str(cinder.get_endpoint()), args.ip, args.port,
            args.protocol, '/snapshots/detail'
        )
        snap = cinder.session.get(local_snap_url, timeout=180)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_cinder')
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_cinder')
        status_err(str(e), m_name='maas_cinder')
    else:
        is_up = vol.ok and snap.ok
        milliseconds = vol.elapsed.total_seconds() * 1000
        metric_bool('client_success', True, m_name='maas_cinder')
        # gather some metrics
        vol_statuses = [v['status'] for v in vol.json()['volumes']]
        vol_status_count = collections.Counter(vol_statuses)
        total_vols = len(vol.json()['volumes'])

        snap_statuses = [v['status'] for v in snap.json()['snapshots']]
        snap_status_count = collections.Counter(snap_statuses)
        total_snaps = len(snap.json()['snapshots'])

    status_ok(m_name='maas_cinder')
    metric_bool('cinder_api_local_status', is_up, m_name='maas_cinder')
    # only want to send other metrics if api is up
    if is_up:
        metric('cinder_api_local_response_time',
               'double',
               '%.3f' % milliseconds,
               'ms')
        metric('total_cinder_volumes', 'uint32', total_vols, 'volumes')
        for status in VOLUME_STATUSES:
            metric('cinder_%s_volumes' % status,
                   'uint32',
                   vol_status_count[status], 'volumes')
        metric('total_cinder_snapshots', 'uint32', total_snaps, 'snapshots')
        for status in VOLUME_STATUSES:
            metric('cinder_%s_snaps' % status,
                   'uint32',
                   snap_status_count[status], 'snapshots')
def check(args):
    octavia = get_openstack_client('load_balancer')

    try:
        if args.ip:
            octavia_local_endpoint = generate_local_endpoint(
                str(octavia.get_endpoint()), args.ip, args.port, args.protocol,
                '/lbaas/loadbalancers?limit=1')
            resp = octavia.session.get(octavia_local_endpoint, timeout=180)

    except (exc.HTTPError, exc.Timeout, exc.ConnectionError):
        is_up = False
        metric_bool('client_success', False, m_name='maas_octavia')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_octavia')
        status_err(str(e), m_name='maas_octavia')
    else:
        is_up = resp.ok
        metric_bool('client_success', True, m_name='maas_octavia')
        milliseconds = resp.elapsed.total_seconds() * 1000

    status_ok(m_name='maas_octavia')
    metric_bool('octavia_api_local_status', is_up, m_name='maas_octavia')
    if is_up:
        # only want to send other metrics if api is up
        metric('octavia_api_local_response_time', 'double',
               '%.3f' % milliseconds, 'ms')
Example #3
0
def check(args):
    heat = get_openstack_client('orchestration')

    try:
        local_heat_endpoint = generate_local_endpoint(str(heat.get_endpoint()),
                                                      args.ip, args.port,
                                                      args.protocol,
                                                      '/build_info')
        resp = heat.session.get(local_heat_endpoint)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_heat')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_heat')
        status_err(str(e), m_name='maas_heat')
    else:
        is_up = True
        milliseconds = resp.elapsed.total_seconds() * 1000
        metric_bool('client_success', True, m_name='maas_heat')

    status_ok(m_name='maas_heat')
    metric_bool('heat_api_local_status', is_up, m_name='maas_heat')
    if is_up:
        # only want to send other metrics if api is up
        metric('heat_api_local_response_time', 'double', '%.3f' % milliseconds,
               'ms')
Example #4
0
def check(args):
    nova = get_openstack_client('compute')

    try:
        local_endpoint = generate_local_endpoint(
            str(nova.get_endpoint()), args.ip, args.port, args.protocol,
            '/servers/detail?all_tenants=True')
        resp = nova.session.get(local_endpoint, timeout=180)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_nova')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_nova')
        status_err(str(e), m_name='maas_nova')
    else:
        is_up = resp.ok
        metric_bool('client_success', True, m_name='maas_nova')
        milliseconds = resp.elapsed.total_seconds() * 1000
        servers = resp.json()['servers']
        # gather some metrics
        status_count = collections.Counter([s['status'] for s in servers])

    status_ok(m_name='maas_nova')
    metric_bool('nova_api_local_status', is_up, m_name='maas_nova')
    # only want to send other metrics if api is up
    if is_up:
        metric('nova_api_local_response_time', 'double', '%.3f' % milliseconds,
               'ms')
        for status in SERVER_STATUSES:
            metric('nova_instances_in_state_%s' % status, 'uint32',
                   status_count[status], 'instances')
Example #5
0
def check(args):
    designate = get_openstack_client('dns')

    try:
        if args.ip:
            # Arbitrary call to /zones to ensure the local API is up
            designate_local_endpoint = generate_local_endpoint(
                str(designate.get_endpoint()), args.ip, args.port,
                args.protocol, '/zones')
            resp = designate.session.get(designate_local_endpoint, timeout=180)
            milliseconds = resp.elapsed.total_seconds() * 1000
        # NOTE(npawelek): At the time of converting to OpenStack SDK,
        # DNS is not yet fully integrated. Excluding integration with
        # the client directly until a later time.

        api_is_up = resp.ok
    except (exc.HTTPError, exc.Timeout, exc.ConnectionError):
        api_is_up = False
        metric_bool('client_success', False, m_name='maas_designate')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_designate')
        status_err(str(e), m_name='maas_designate')
    else:
        metric_bool('client_success', True, m_name='maas_designate')

    status_ok(m_name='maas_designate')
    metric_bool('designate_api_local_status',
                api_is_up,
                m_name='maas_designate')
    if api_is_up:
        # only want to send other metrics if api is up
        metric('designate_api_local_response_time', 'double',
               '%.3f' % milliseconds, 'ms')
def check(args):
    octavia = get_openstack_client('load_balancer')

    try:
        if args.ip:
            octavia_local_endpoint = generate_local_endpoint(
                str(octavia.get_endpoint()), args.ip, args.port,
                args.protocol, '/lbaas/loadbalancers?limit=1'
            )
            resp = octavia.session.get(octavia_local_endpoint, timeout=180)

    except (exc.HTTPError, exc.Timeout, exc.ConnectionError):
        is_up = False
        metric_bool('client_success', False, m_name='maas_octavia')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_octavia')
        status_err(str(e), m_name='maas_octavia')
    else:
        is_up = resp.ok
        metric_bool('client_success', True, m_name='maas_octavia')
        milliseconds = resp.elapsed.total_seconds() * 1000

    status_ok(m_name='maas_octavia')
    metric_bool('octavia_api_local_status', is_up, m_name='maas_octavia')
    if is_up:
        # only want to send other metrics if api is up
        metric('octavia_api_local_response_time',
               'double',
               '%.3f' % milliseconds,
               'ms')
Example #7
0
def check(args):
    octavia = get_openstack_client('load_balancer')

    try:
        if args.ip:
            octavia_local_endpoint = generate_local_endpoint(
                str(octavia.get_endpoint()), args.ip, args.port, args.protocol,
                '/lbaas/loadbalancers')
            resp = octavia.session.get(octavia_local_endpoint, timeout=180)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_octavia')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_octavia')
        status_err(str(e), m_name='maas_octavia')
    else:
        is_up = resp.ok
        metric_bool('client_success', True, m_name='maas_octavia')

    status_ok(m_name='maas_octavia')
    metric_bool('octavia_api_local_status', is_up, m_name='maas_octavia')
    if is_up:
        loadbalancers = resp.json()['loadbalancers']
        num = len([
            lb for lb in loadbalancers if lb['provisioning_status'] == 'ERROR'
        ])
        # only want to send other metrics if api is up
        metric('octavia_num_lb_in_error_status', 'uint32', num, 'ms')
Example #8
0
def check(args):
    ironic = get_openstack_client('baremetal')

    try:
        ironic_local_endpoint = generate_local_endpoint(
            str(ironic.get_endpoint()), args.ip, args.port, args.protocol,
            '/nodes')
        resp = ironic.session.get(ironic_local_endpoint)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_ironic')
        status_err(str(e), m_name='maas_ironic')
    else:
        is_up = resp.status_code == 200
        milliseconds = resp.elapsed.total_seconds() * 1000
        metric_bool('client_success', True, m_name='maas_ironic')

    status_ok(m_name='maas_ironic')
    metric_bool('ironic_api_local_status', is_up, m_name='maas_ironic')
    if is_up:
        metric('ironic_api_local_response_time', 'double',
               '%.3f' % milliseconds, 'ms')
def check(args):
    glance = get_openstack_client('image')

    try:
        # Remove version from returned endpoint
        glance_endpoint = str(glance.get_endpoint().rsplit('/', 2)[0])
        local_registry_url = generate_local_endpoint(
            glance_endpoint, args.ip, args.port, args.protocol,
            '/images'
        )
        resp = glance.session.get(local_registry_url, timeout=180)
        milliseconds = resp.elapsed.total_seconds() * 1000

        is_up = resp.status_code == 200
    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_glance')
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_glance')
        status_err(str(e), m_name='maas_glance')

    status_ok(m_name='maas_glance')
    metric_bool('client_success', True, m_name='maas_glance')
    metric_bool('glance_registry_local_status', is_up, m_name='maas_glance')
    # Only send remaining metrics if the API is up
    if is_up:
        metric('glance_registry_local_response_time', 'double',
               '%.3f' % milliseconds, 'ms')
Example #10
0
def check(args):
    ironic = get_openstack_client('baremetal')

    try:
        ironic_local_endpoint = generate_local_endpoint(
            str(ironic.get_endpoint()), args.ip, args.port,
            args.protocol, '/nodes'
        )
        resp = ironic.session.get(ironic_local_endpoint)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_ironic')
        status_err(str(e), m_name='maas_ironic')
    else:
        is_up = resp.status_code == 200
        milliseconds = resp.elapsed.total_seconds() * 1000
        metric_bool('client_success', True, m_name='maas_ironic')

    status_ok(m_name='maas_ironic')
    metric_bool('ironic_api_local_status', is_up, m_name='maas_ironic')
    if is_up:
        metric('ironic_api_local_response_time',
               'double',
               '%.3f' % milliseconds,
               'ms')
Example #11
0
def check(args):
    heat = get_openstack_client('orchestration')

    try:
        local_heat_endpoint = generate_local_endpoint(
            str(heat.get_endpoint()), args.ip, args.port,
            args.protocol, '/build_info'
        )
        resp = heat.session.get(local_heat_endpoint)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_heat')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_heat')
        status_err(str(e), m_name='maas_heat')
    else:
        is_up = True
        milliseconds = resp.elapsed.total_seconds() * 1000
        metric_bool('client_success', True, m_name='maas_heat')

    status_ok(m_name='maas_heat')
    metric_bool('heat_api_local_status', is_up, m_name='maas_heat')
    if is_up:
        # only want to send other metrics if api is up
        metric('heat_api_local_response_time',
               'double',
               '%.3f' % milliseconds,
               'ms')
Example #12
0
def check(args):
    octavia = get_openstack_client('load_balancer')

    try:
        if args.ip:
            octavia_local_endpoint = generate_local_endpoint(
                str(octavia.get_endpoint()), args.ip, args.port,
                args.protocol,
                '/lbaas/loadbalancers'
            )
            resp = octavia.session.get(octavia_local_endpoint, timeout=180)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_octavia')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_octavia')
        status_err(str(e), m_name='maas_octavia')
    else:
        is_up = resp.ok
        metric_bool('client_success', True, m_name='maas_octavia')

    status_ok(m_name='maas_octavia')
    metric_bool('octavia_api_local_status', is_up, m_name='maas_octavia')
    if is_up:
        loadbalancers = resp.json()['loadbalancers']
        num = len([lb for lb in loadbalancers
                   if lb['provisioning_status'] == 'ERROR'])
        # only want to send other metrics if api is up
        metric('octavia_num_lb_in_error_status',
               'uint32',
               num,
               'ms')
def check(args):
    neutron = get_openstack_client('network')

    try:
        neutron_local_endpoint = generate_local_endpoint(
            str(neutron.get_endpoint()), args.ip, args.port,
            args.protocol, '/agents'
        )
        resp = neutron.session.get(neutron_local_endpoint, timeout=180)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_neutron')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_neutron')
        status_err(str(e), m_name='maas_neutron')
    else:
        is_up = True
        milliseconds = resp.elapsed.total_seconds() * 1000
        metric_bool('client_success', True, m_name='maas_neutron')

        # Gather a few metrics
        agents = len(resp.json()['agents'])
        networks = len([i for i in neutron.networks()])
        routers = len([i for i in neutron.routers()])
        subnets = len([i for i in neutron.subnets()])

    status_ok(m_name='maas_neutron')
    metric_bool('neutron_api_local_status', is_up, m_name='maas_neutron')
    # Only send metrics if the API is up
    if is_up:
        metric('neutron_api_local_response_time',
               'double',
               '%.3f' % milliseconds,
               'ms')
        metric('neutron_agents', 'uint32', agents, 'agents')
        metric('neutron_networks', 'uint32', networks, 'networks')
        metric('neutron_routers', 'uint32', routers, 'agents')
        metric('neutron_subnets', 'uint32', subnets, 'subnets')
Example #14
0
def check(args):
    nova = get_openstack_client('compute')

    try:
        local_endpoint = generate_local_endpoint(
            str(nova.get_endpoint()), args.ip, args.port, args.protocol,
            '/servers/detail?all_tenants=True'
        )
        resp = nova.session.get(local_endpoint, timeout=180)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_nova')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_nova')
        status_err(str(e), m_name='maas_nova')
    else:
        is_up = resp.ok
        metric_bool('client_success', True, m_name='maas_nova')
        milliseconds = resp.elapsed.total_seconds() * 1000
        servers = resp.json()['servers']
        # gather some metrics
        status_count = collections.Counter(
            [s['status'] for s in servers]
        )

    status_ok(m_name='maas_nova')
    metric_bool('nova_api_local_status', is_up, m_name='maas_nova')
    # only want to send other metrics if api is up
    if is_up:
        metric('nova_api_local_response_time',
               'double',
               '%.3f' % milliseconds,
               'ms')
        for status in SERVER_STATUSES:
            metric('nova_instances_in_state_%s' % status,
                   'uint32',
                   status_count[status], 'instances')
def check(args):
    glance = get_openstack_client('image')

    try:
        local_image_url = generate_local_endpoint(
            str(glance.get_endpoint()), args.ip, args.port,
            args.protocol, '/images'
        )
        resp = glance.session.get(local_image_url, timeout=180)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_glance')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_glance')
        status_err(str(e), m_name='maas_glance')
    else:
        is_up = resp.ok
        milliseconds = resp.elapsed.total_seconds() * 1000
        metric_bool('client_success', True, m_name='maas_glance')

        images = resp.json()['images']
        status_count = collections.Counter([i['status'] for i in images])

    status_ok(m_name='maas_glance')
    metric_bool('glance_api_local_status', is_up, m_name='maas_glance')

    # only want to send other metrics if api is up
    if is_up:
        metric('glance_api_local_response_time',
               'double',
               '%.3f' % milliseconds,
               'ms')
        for status in IMAGE_STATUSES:
            metric('glance_%s_images' % status,
                   'uint32',
                   status_count[status],
                   'images')
Example #16
0
def check(args):
    neutron = get_openstack_client('network')

    try:
        neutron_local_endpoint = generate_local_endpoint(
            str(neutron.get_endpoint()), args.ip, args.port, args.protocol,
            '/agents')
        resp = neutron.session.get(neutron_local_endpoint, timeout=180)

    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        is_up = False
        metric_bool('client_success', False, m_name='maas_neutron')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_neutron')
        status_err(str(e), m_name='maas_neutron')
    else:
        is_up = True
        milliseconds = resp.elapsed.total_seconds() * 1000
        metric_bool('client_success', True, m_name='maas_neutron')

        # Gather a few metrics
        agents = len(resp.json()['agents'])
        networks = len([i for i in neutron.networks()])
        routers = len([i for i in neutron.routers()])
        subnets = len([i for i in neutron.subnets()])

    status_ok(m_name='maas_neutron')
    metric_bool('neutron_api_local_status', is_up, m_name='maas_neutron')
    # Only send metrics if the API is up
    if is_up:
        metric('neutron_api_local_response_time', 'double',
               '%.3f' % milliseconds, 'ms')
        metric('neutron_agents', 'uint32', agents, 'agents')
        metric('neutron_networks', 'uint32', networks, 'networks')
        metric('neutron_routers', 'uint32', routers, 'agents')
        metric('neutron_subnets', 'uint32', subnets, 'subnets')
def check(args):
    designate = get_openstack_client('dns')

    try:
        if args.ip:
            # Arbitrary call to /zones to ensure the local API is up
            designate_local_endpoint = generate_local_endpoint(
                str(designate.get_endpoint()), args.ip, args.port,
                args.protocol, '/zones'
            )
            resp = designate.session.get(designate_local_endpoint, timeout=180)
            milliseconds = resp.elapsed.total_seconds() * 1000
        # NOTE(npawelek): At the time of converting to OpenStack SDK,
        # DNS is not yet fully integrated. Excluding integration with
        # the client directly until a later time.

        api_is_up = resp.ok
    except (exc.HTTPError, exc.Timeout, exc.ConnectionError):
        api_is_up = False
        metric_bool('client_success', False, m_name='maas_designate')
    # Any other exception presumably isn't an API error
    except Exception as e:
        metric_bool('client_success', False, m_name='maas_designate')
        status_err(str(e), m_name='maas_designate')
    else:
        metric_bool('client_success', True, m_name='maas_designate')

    status_ok(m_name='maas_designate')
    metric_bool('designate_api_local_status',
                api_is_up, m_name='maas_designate')
    if api_is_up:
        # only want to send other metrics if api is up
        metric('designate_api_local_response_time',
               'double',
               '%.3f' % milliseconds,
               'ms')