def nova_hypervisors_stats(): """Get stats from the nova API and add them as Goldstone metrics.""" from goldstone.utils import get_nova_client from goldstone.models import es_conn, daily_index novaclient = get_nova_client()['client'] response = \ novaclient.hypervisors.statistics()._info # pylint: disable=W0212 region = get_region_for_nova_client(novaclient) 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 """ from goldstone.utils import get_nova_client nova_access = get_nova_client() nova_client = nova_access['client'] nova_client.client.authenticate() reg = get_region_for_nova_client(nova_client) _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.utils import get_nova_client from goldstone.models import es_conn, daily_index novaclient = get_nova_client()['client'] response = \ novaclient.hypervisors.statistics()._info # pylint: disable=W0212 region = get_region_for_nova_client(novaclient) 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 """ from goldstone.utils import get_nova_client nova_access = get_nova_client() nova_client = nova_access['client'] nova_client.client.authenticate() reg = get_region_for_nova_client(nova_client) _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())