Esempio n. 1
0
def get_hyper_list(request):
    try:
        hyperv_list = []
        instance_count = 0
        vcpu_percent = 0.0
        ram_percent = 0.0
        disk_percent = 0.0
        instance_max = 100
        container_max = 500
        zun_error = False
        zn_client = zun_client.Client()
        container_list = []
        try:
            # 获取所有容器
            container_list = zn_client.container_list()
        except Exception, e:
            zun_error = True

        nv_client = nova_client.Client(project_name="admin")
        hypers = nv_client.hypervisor_list()
        for hyper in hypers:
            container_count = 0
            local_containers_count = 0
            instance_count += hyper.running_vms
            hyper.vcpus = hyper.vcpus * cpu_allocation_ratio
            hyper.vcpus_percent = float(hyper.vcpus_used) / float(hyper.vcpus)
            vcpu_percent += hyper.vcpus_percent
            hyper.memory_mb = hyper.memory_mb * ram_allocation_ratio
            hyper.ram_percent = float(hyper.memory_mb_used) / float(hyper.memory_mb)
            ram_percent += hyper.ram_percent
            hyper.local_gb = hyper.local_gb * disk_allocation_ratio
            hyper.disk_percent = float(hyper.local_gb_used) / float(hyper.local_gb)
            disk_percent += hyper.disk_percent

            for container in container_list:
                if container.host == hyper.hypervisor_hostname:
                    container_count += 1

            if hyper.hypervisor_hostname.startswith("controller"):
                from common_scene.cms.views import get_local_dockers
                local_containers_count = len(get_local_dockers())

            hyper_dict = Hypervisor(hyper).to_dict()
            hyper_dict['container_count'] = container_count + local_containers_count
            hyper_dict['vcpus_percent'] = round(hyper.vcpus_percent * 100)
            hyper_dict['ram_percent'] = round(hyper.ram_percent * 100)
            hyper_dict['disk_percent'] = round(hyper.disk_percent * 100)
            hyperv_list.append(hyper_dict)
        hyper_count = len(hypers)
Esempio n. 2
0
def hyperv_stats(request):
    # openstack hypervisor
    hyperv_list = []
    try:
        instance_count = 0
        vcpu_percent = 0.0
        ram_percent = 0.0
        disk_percent = 0.0
        instance_max = 100
        nv_client = nova_client.Client(project_name="admin")
        hypers = nv_client.hypervisor_list()

        for hyper in hypers:
            hyperv_list.append(Hypervisor(hyper).to_dict())
            instance_count += hyper.running_vms
            vcpu_percent += float(hyper.vcpus_used) / float(hyper.vcpus)
            ram_percent += float(hyper.memory_mb_used) / float(hyper.memory_mb)
            disk_percent += float(hyper.local_gb_used) / float(hyper.local_gb)

        hyper_count = len(hypers)
    except Exception, e:
        return JsonResponse({})
Esempio n. 3
0
def get_service_alarm_list():
    try:
        service_list = []
        # 获取 httpd服务端口
        httpd_port = api_settings.defaults.get('CONTROLLER_HTTPD_PORT', 80)
        # 判断服务端口是否打开
        memcache_hosts = api_settings.COMPLEX_MISC.get("memcache_host")
        memcached_bool = True
        for host in memcache_hosts:
            if ":" in host:
                ip, port = host.split(":")
                if not is_port_open(ip, port):
                    memcached_bool = False
                    break
        rabbitmq_bool = is_port_open('controller', 5672)
        glance_api_bool = is_port_open('controller', 9292)
        glance_registry_bool = is_port_open('controller', 9191)
        keystone_bool = is_port_open('controller', 35357)
        httpd_bool = is_port_open('controller', httpd_port)

        if memcached_bool is not True:
            service_list.append({'service': 'Memcached', 'state': 'down'})

        if rabbitmq_bool is not True:
            service_list.append({'service': 'Rabbitmq', 'state': 'down'})

        if glance_api_bool is not True:
            service_list.append({'service': 'Glance', 'state': 'down'})

        if glance_registry_bool is not True:
            service_list.append({'service': 'Glance', 'state': 'down'})

        if keystone_bool is not True:
            service_list.append({'service': 'Keystone', 'state': 'down'})

        if httpd_bool is not True:
            service_list.append({'service': 'Openstack Dashboard', 'state': 'down'})

        # 获取 nova 服务告警,先判断nova-api
        nova_api_bool = is_port_open('controller', 8775)
        if nova_api_bool is True:
            nv_client = nova_client.Client(project_name="admin")
            nova_list = list(nv_client.service_list())
            for item in nova_list:
                if item.state != 'up':
                    # if item.binary == 'nova-compute':
                    #     service = '计算'
                    # elif item.binary == 'nova-scheduler':
                    #     service = '调度'
                    # elif item.binary == 'nova-conductor':
                    #     service = 'nova数据库操作'
                    # elif item.binary == 'nova-consoleauth':
                    #     service = 'nova实例控制台'
                    service = 'Host:'+item.host+' Nova'
                    nova_dict = {
                        'service': service,
                        'state': item.state,
                    }
                    service_list.append(nova_dict)
                    break
        else:
            service_list.append({'service': 'Nova', 'state': 'down'})

        # 获取 neutron 服务告警
        network_client = neutron_client.Client(project_name="admin")
        network_list = network_client.agent_list()['agents']

        for item in network_list:
            if item['alive'] is not True:
                # if item['binary'] == 'neutron-dhcp-agent':
                #     service = 'dhcp'
                # elif item['binary'] == 'neutron-metadata-agent':
                #     service = 'metadata-agent'
                # elif item['binary'] == 'neutron-l3-agent':
                #     service = 'l3-agent'
                # elif item['binary'] == 'neutron-linuxbridge-agent':
                #     service = 'linuxbridge'
                service = 'Host:' + item['host']+' Neutron'
                network_dict = {
                    'service': service,
                    'state': str(item['alive']),
                }
                service_list.append(network_dict)
                break

        # 获取cinder服务告警
        # cin_client = cinder_client.Client(project_name="admin")
        # cinder_list = cin_client.service_list()

        # service_list.append({'service': 'nova_test', 'state': 'DOWN'})
        # 获取zun 服务告警,先判断zun-api

        zun_api_bool = is_port_open('controller', 9517)
        if zun_api_bool is True:

            zn_client = zun_client.Client(project_name="admin")
            zun_list = zn_client.service_list()
            for item in zun_list:
                if item.state != 'up':
                    service = 'Host:' + item.host+'Container'
                    zun_dict = {
                        'service': service,
                        'state': str(item.state),
                    }
                    service_list.append(zun_dict)
                    break

        else:
            service_list.append({'service': 'zun', 'state': 'down'})
    except Exception, e:
        pass
Esempio n. 4
0
def operation_services(request):
    context = {}
    # 添加虚拟比例
    cpu_allocation_ratio = common_scene_api_settings.COMPLEX_MISC.get(
        "cpu_allocation_ratio", 16.0)
    ram_allocation_ratio = common_scene_api_settings.COMPLEX_MISC.get(
        "ram_allocation_ratio", 1.5)
    disk_allocation_ratio = common_scene_api_settings.COMPLEX_MISC.get(
        "disk_allocation_ratio", 1.0)
    context['cpu_allocation_ratio'] = cpu_allocation_ratio
    context['ram_allocation_ratio'] = ram_allocation_ratio
    context['disk_allocation_ratio'] = disk_allocation_ratio
    zn_client = zun_client.Client()
    # 获取所有容器
    container_list = zn_client.container_list()
    # openstack hypervisor
    hyperv_list = []
    try:
        instance_count = 0
        vcpu_percent = 0.0
        ram_percent = 0.0
        disk_percent = 0.0
        instance_max = 100
        nv_client = nova_client.Client(project_name="admin")
        hypers = nv_client.hypervisor_list()
        for hyper in hypers:
            container_count = 0
            local_containers_count = 0
            instance_count += hyper.running_vms
            hyper.vcpus = hyper.vcpus * cpu_allocation_ratio
            vcpu_percent += float(hyper.vcpus_used) / float(hyper.vcpus)
            hyper.memory_mb = hyper.memory_mb * ram_allocation_ratio
            ram_percent += float(hyper.memory_mb_used) / float(hyper.memory_mb)
            hyper.local_gb = hyper.local_gb * disk_allocation_ratio
            disk_percent += float(hyper.local_gb_used) / float(hyper.local_gb)

            for container in container_list:
                if container.host == hyper.hypervisor_hostname:
                    container_count = container_count + 1
            if hyper.hypervisor_hostname.startswith("controller"):
                from common_scene.cms.views import get_local_dockers
                local_containers_count = len(get_local_dockers())

            hyper_dict = Hypervisor(hyper).to_dict()
            hyper_dict[
                'container_count'] = container_count + local_containers_count
            hyperv_list.append(hyper_dict)

        hyper_count = len(hypers)
        context.update({
            "cluster_state": {
                "vms": instance_count,
                "vm_max": instance_max,
                "vcpu": vcpu_percent / hyper_count * 100,
                "ram": ram_percent / hyper_count * 100,
                "disk": disk_percent / hyper_count * 100,
            }
        })

    except Exception as e:
        pass
    context.update({"hypervisors": hyperv_list})
    return render(request, 'dashboard_services.html', context=context)
Esempio n. 5
0
 def setUp(self):
     super(ComputeApiTests, self).setUp()
     self.nv_cli = nova_client.Client()