def nova_hypervisors_stats(): """Get stats from the nova API and add them as Goldstone metrics.""" from goldstone.models import es_conn, daily_index novaclient = get_client() response = novaclient.hypervisors.statistics()._info region = get_region() metric_prefix = 'nova.hypervisor.' now = arrow.utcnow() conn = es_conn() es_index = daily_index(MetricData.INDEX_PREFIX) es_doc_type = MetricData._doc_type.name # pylint: disable=W0212 for key, value in response.items(): doc = { 'type': es_doc_type, 'name': metric_prefix + key, 'value': value, 'metric_type': 'gauge', '@timestamp': now.isoformat(), 'region': region } if key in ['disk_available_least', 'free_disk_gb', 'local_gb', 'local_gb_used']: doc['unit'] = 'GB' elif key in ['free_ram_mb', 'memory_mb', 'memory_mb_used']: doc['unit'] = 'MB' else: doc['unit'] = 'count' conn.create(es_index, es_doc_type, doc)
def discover_nova_topology(): """Contacts the configured OpenStack API endpoint and gathers Nova resource information. Information is written to the daily goldstone index. :return: None """ nova_client = get_client() reg = get_region() _update_nova_records("agents", reg, AgentsData(), nova_client.agents.list()) _update_nova_records("aggregates", reg, AggregatesData(), nova_client.aggregates.list()) _update_nova_records("availability_zones", reg, AvailZonesData(), nova_client.availability_zones.list()) _update_nova_records("cloudpipes", reg, CloudpipesData(), nova_client.cloudpipe.list()) _update_nova_records("flavors", reg, FlavorsData(), nova_client.flavors.list()) _update_nova_records("floating_ip_pools", reg, FloatingIpPoolsData(), nova_client.floating_ip_pools.list()) _update_nova_records("hosts", reg, HostsData(), nova_client.hosts.list()) _update_nova_records("hypervisors", reg, HypervisorsData(), nova_client.hypervisors.list()) _update_nova_records("networks", reg, NetworksData(), nova_client.networks.list()) _update_nova_records("secgroups", reg, SecGroupsData(), nova_client.security_groups.list()) _update_nova_records( "servers", reg, ServersData(), nova_client.servers.list(search_opts={'all_tenants': 1})) _update_nova_records("services", reg, ServicesData(), nova_client.services.list())
def nova_hypervisors_stats(): """Get stats from the nova API and add them as Goldstone metrics.""" from goldstone.models import es_conn, daily_index novaclient = get_client() response = novaclient.hypervisors.statistics()._info region = get_region() metric_prefix = 'nova.hypervisor.' now = arrow.utcnow() conn = es_conn() es_index = daily_index(METRIC_INDEX_PREFIX) es_doc_type = METRIC_DOCTYPE for key, value in response.items(): doc = { 'type': es_doc_type, 'name': metric_prefix + key, 'value': value, 'metric_type': 'gauge', '@timestamp': now.isoformat(), 'region': region } if key in [ 'disk_available_least', 'free_disk_gb', 'local_gb', 'local_gb_used' ]: doc['unit'] = 'GB' elif key in ['free_ram_mb', 'memory_mb', 'memory_mb_used']: doc['unit'] = 'MB' else: doc['unit'] = 'count' conn.create(es_index, es_doc_type, doc)
def discover_nova_topology(): """Contacts the configured OpenStack API endpoint and gathers Nova resource information. Information is written to the daily goldstone index. :return: None """ nova_client = get_client() reg = get_region() _update_nova_records("agents", reg, AgentsData(), nova_client.agents.list()) _update_nova_records("aggregates", reg, AggregatesData(), nova_client.aggregates.list()) _update_nova_records("availability_zones", reg, AvailZonesData(), nova_client.availability_zones.list()) _update_nova_records("cloudpipes", reg, CloudpipesData(), nova_client.cloudpipe.list()) _update_nova_records("flavors", reg, FlavorsData(), nova_client.flavors.list()) _update_nova_records("floating_ip_pools", reg, FloatingIpPoolsData(), nova_client.floating_ip_pools.list()) _update_nova_records("hosts", reg, HostsData(), nova_client.hosts.list()) _update_nova_records("hypervisors", reg, HypervisorsData(), nova_client.hypervisors.list()) _update_nova_records("networks", reg, NetworksData(), nova_client.networks.list()) _update_nova_records("secgroups", reg, SecGroupsData(), nova_client.security_groups.list()) _update_nova_records("servers", reg, ServersData(), nova_client.servers.list( search_opts={'all_tenants': 1})) _update_nova_records("services", reg, ServicesData(), nova_client.services.list())
def get_nova_host_list(): """Retrieve a list of hosts from nova.""" nova_client = get_client() return nova_client.hosts.list()