def check(args): auth_ref = get_auth_ref() auth_token = auth_ref['auth_token'] tenant_id = auth_ref['project']['id'] COMPUTE_ENDPOINT = ( 'http://{ip}:8774/v2/{tenant_id}'.format(ip=args.ip, tenant_id=tenant_id) ) try: nova = get_nova_client(auth_token=auth_token, bypass_url=COMPUTE_ENDPOINT) except Exception as e: status_err(str(e)) else: # get some cloud stats stats = nova.hypervisor_stats.statistics() cloud_stats = collections.defaultdict(dict) for metric_name, vals in stats_mapping.iteritems(): cloud_stats[metric_name]['value'] = \ getattr(stats, vals['stat_name']) cloud_stats[metric_name]['unit'] = \ vals['unit'] cloud_stats[metric_name]['type'] = \ vals['type'] status_ok() for metric_name in cloud_stats.iterkeys(): metric('cloud_resource_%s' % metric_name, cloud_stats[metric_name]['type'], cloud_stats[metric_name]['value'], cloud_stats[metric_name]['unit'])
def configure_callback(conf): """Receive configuration block""" ip = None host = None interval = 10 graphite_host = None graphite_port = None for node in conf.children: key = node.key val = node.values[0] if key == 'ip': # Cinder API hostname or IP address ip = val elif key == 'interval': interval = val elif key == 'host': # Only return metrics for specified host host == host elif key == 'graphite_host': graphite_host = val elif key == 'graphite_port': graphite_port = val else: collectd.warning( 'cinder_service_check: Unknown config key: {}'.format(key)) continue auth_ref = get_auth_ref() CONFIGS['ip'] = ip CONFIGS['host'] = host CONFIGS['auth_ref'] = auth_ref CONFIGS['interval'] = interval CONFIGS['graphite_host'] = graphite_host CONFIGS['graphite_port'] = graphite_port
def configure_callback(conf): """Receive configuration block""" ip = None interval = 10 graphite_host = None graphite_port = None for node in conf.children: key = node.key val = node.values[0] if key == 'ip': ip = val elif key == 'interval': interval = val elif key == 'graphite_host': graphite_host = val elif key == 'graphite_port': graphite_port = val else: collectd.warning( 'nova_cloud_stats: Unknown config key: {}'.format(key)) continue auth_ref = get_auth_ref() CONFIGS['ip'] = ip CONFIGS['auth_ref'] = auth_ref CONFIGS['interval'] = interval CONFIGS['graphite_host'] = graphite_host CONFIGS['graphite_port'] = graphite_port
def check(args): headers = {'Content-type': 'application/json'} path_options = {} if args.auth: auth_ref = get_auth_ref() keystone = get_keystone_client(auth_ref) auth_token = keystone.auth_token project_id = keystone.project_id headers['auth_token'] = auth_token path_options['project_id'] = project_id scheme = args.ssl and 'https' or 'http' endpoint = '{scheme}://{ip}:{port}'.format(ip=args.ip, port=args.port, scheme=scheme) if args.version is not None: path_options['version'] = args.version path = args.path.format(path_options) s = requests.Session() s.headers.update(headers) short_name = args.name.split('_')[0] if path and not path.startswith('/'): url = '/'.join((endpoint, path)) else: url = ''.join((endpoint, path)) try: r = s.get(url, verify=False, timeout=5) except (exc.ConnectionError, exc.HTTPError, exc.Timeout): up = False metric_bool('client_success', False, m_name='maas_{name}'.format(name=short_name)) else: up = True metric_bool('client_success', True, m_name='maas_{name}'.format(name=short_name)) status_ok(m_name='maas_{name}'.format(name=short_name)) metric_bool('{name}_api_local_status'.format(name=args.name), up) if up and r.ok: milliseconds = r.elapsed.total_seconds() * 1000 metric('{name}_api_local_response_time'.format(name=args.name), 'double', '%.3f' % milliseconds, 'ms')
def check(args): headers = {'Content-type': 'application/json'} path_options = {} if args.auth: auth_ref = get_auth_ref() keystone = get_keystone_client(auth_ref) auth_token = keystone.auth_token project_id = keystone.project_id headers['auth_token'] = auth_token path_options['project_id'] = project_id scheme = args.ssl and 'https' or 'http' endpoint = '{scheme}://{ip}:{port}'.format(ip=args.ip, port=args.port, scheme=scheme) if args.version is not None: path_options['version'] = args.version path = args.path.format(path_options) s = requests.Session() s.headers.update(headers) if path and not path.startswith('/'): url = '/'.join((endpoint, path)) else: url = ''.join((endpoint, path)) try: r = s.get(url, verify=False, timeout=10) except (exc.ConnectionError, exc.HTTPError, exc.Timeout): up = False else: up = True status_ok() metric_bool('{name}_api_local_status'.format(name=args.name), up) if up and r.ok: milliseconds = r.elapsed.total_seconds() * 1000 metric('{name}_api_local_response_time'.format(name=args.name), 'double', '%.3f' % milliseconds, 'ms') metric_values['{name}_api_local_response_time'.format( name=args.name)] = ('%.3f' % milliseconds) metric_influx(INFLUX_MEASUREMENT_NAME, metric_values)
def main(): responses = { 'put_container': 200, 'put_object': 200, 'get_object': 200, 'delete_object': 200, } contents = "TESTCONTENTS" auth_ref = get_auth_ref() keystone = get_keystone_client(auth_ref) endpoint = get_endpoint_url_for_service("object-store", auth_ref) conn = swiftclient.client.Connection( preauthurl=endpoint, preauthtoken=keystone.auth_token, retries=0, ) try: conn.put_container("hummingbird-maas") except swiftclient.client.ClientException as e: responses['put_container'] = e.http_status try: conn.put_object("hummingbird-maas", "test-object", contents) except swiftclient.client.ClientException as e: responses['put_object'] = e.http_status try: headers, body = conn.get_object("hummingbird-maas", "test-object") if body != contents: responses['get_object'] = 400 except swiftclient.client.ClientException as e: responses['get_object'] = e.http_status try: conn.delete_object("hummingbird-maas", "test-object") except swiftclient.client.ClientException as e: responses['delete_object'] = e.http_status maas_common.status_ok(m_name='maas_hummingbird') for k, v in responses.iteritems(): maas_common.metric(k, 'uint32', v)
def check(args): auth_ref = get_auth_ref() auth_token = auth_ref['auth_token'] tenant_id = auth_ref['project']['id'] COMPUTE_ENDPOINT = ( 'http://{ip}:8774/v2/{tenant_id}'.format(ip=args.ip, tenant_id=tenant_id) ) try: nova = get_nova_client(auth_token=auth_token, bypass_url=COMPUTE_ENDPOINT) is_up = True except exc.ClientException: is_up = False # Any other exception presumably isn't an API error except Exception as e: status_err(str(e)) else: # time something arbitrary start = time.time() nova.services.list() end = time.time() milliseconds = (end - start) * 1000 servers = nova.servers.list(search_opts={'all_tenants': 1}) # gather some metrics status_count = collections.Counter([s.status for s in servers]) status_ok() metric_bool('nova_api_local_status', is_up) # 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): auth_ref = get_auth_ref() auth_token = auth_ref['auth_token'] tenant_id = auth_ref['project']['id'] COMPUTE_ENDPOINT = ( 'http://{hostname}:8774/v2/{tenant_id}'.format(hostname=args.hostname, tenant_id=tenant_id) ) try: nova = get_nova_client(auth_token=auth_token, bypass_url=COMPUTE_ENDPOINT) # not gathering api status metric here so catch any exception except Exception as e: status_err(str(e)) # gather nova service states if args.host: services = nova.services.list(host=args.host) else: services = nova.services.list() if len(services) == 0: status_err("No host(s) found in the service list") # return all the things status_ok() for service in services: service_is_up = True if service.status == 'enabled' and service.state == 'down': service_is_up = False if args.host: name = '%s_status' % service.binary else: name = '%s_on_host_%s_status' % (service.binary, service.host) metric_bool(name, service_is_up)
def check(args): auth_ref = get_auth_ref() auth_token = auth_ref['token']['id'] tenant_id = auth_ref['token']['tenant']['id'] COMPUTE_ENDPOINT = 'http://{hostname}:8774/v2/{tenant_id}' \ .format(hostname=args.hostname, tenant_id=tenant_id) try: nova = get_nova_client(auth_token=auth_token, bypass_url=COMPUTE_ENDPOINT) # not gathering api status metric here so catch any exception except Exception as e: status_err(str(e)) # gather nova service states if args.host: services = nova.services.list(host=args.host) else: services = nova.services.list() if len(services) == 0: status_err("No host(s) found in the service list") # return all the things status_ok() for service in services: service_is_up = True if service.status == 'enabled' and service.state == 'down': service_is_up = False if args.host: name = '%s_status' % service.binary else: name = '%s_on_host_%s_status' % (service.binary, service.host) name = name.replace(".", "_") metric_bool(name, service_is_up)
def check(args): auth_ref = get_auth_ref() auth_token = auth_ref['token']['id'] tenant_id = auth_ref['token']['tenant']['id'] COMPUTE_ENDPOINT = 'http://{ip}:8774/v2/{tenant_id}' \ .format(ip=args.ip, tenant_id=tenant_id) try: nova = get_nova_client(auth_token=auth_token, bypass_url=COMPUTE_ENDPOINT) is_up = True except exc.ClientException: is_up = False # Any other exception presumably isn't an API error except Exception as e: status_err(str(e)) else: # time something arbitrary start = time() nova.services.list() end = time() milliseconds = (end - start) * 1000 # gather some metrics status_count = collections.Counter([ s.status for s in nova.servers.list(search_opts={'all_tenants': 1}) ]) status_ok() metric_bool('nova_api_local_status', is_up) # 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): headers = {"Content-type": "application/json"} path_options = {} if args.auth: auth_ref = get_auth_ref() keystone = get_keystone_client(auth_ref) auth_token = keystone.auth_token project_id = keystone.project_id headers["auth_token"] = auth_token path_options["project_id"] = project_id scheme = args.ssl and "https" or "http" endpoint = "{scheme}://{ip}:{port}".format(ip=args.ip, port=args.port, scheme=scheme) if args.version is not None: path_options["version"] = args.version path = args.path.format(path_options) s = requests.Session() s.headers.update(headers) if path and not path.startswith("/"): url = "/".join((endpoint, path)) else: url = "".join((endpoint, path)) try: r = s.get(url, verify=False, timeout=10) except (exc.ConnectionError, exc.HTTPError, exc.Timeout): up = False else: up = True status_ok() metric_bool("{name}_api_local_status".format(name=args.name), up) if up and r.ok: milliseconds = r.elapsed.total_seconds() * 1000 metric("{name}_api_local_response_time".format(name=args.name), "double", "%.3f" % milliseconds, "ms")
def main(args): auth_ref = get_auth_ref() check(auth_ref, args)
def main(args): auth_ref = get_auth_ref() tenant_id = auth_ref['project']['id'] check(args, tenant_id)
def main(args): auth_ref = get_auth_ref() tenant_id = auth_ref['token']['tenant']['id'] check(args, tenant_id)
def main(): auth_ref = get_auth_ref() # **check(auth_ref, args) check(auth_ref)