Esempio n. 1
0
    def get(self, vnf_name):
        """
        Calculates the workload for the specified docker container. Requires at least one second, to calculate
        the network traffic and cpu usage over time.

        :param vnf_name: Specifies the docker container via name.
        :type vnf_name: ``str``
        :return: Returns a json response with network, cpu and memory usage over time, and specifies the storage
            access, the number of running processes and the current system time.
        :rtype: :class:`flask.response`
        """
        if len(vnf_name) < 3 or "mn." != vnf_name[:3]:
            vnf_name = "mn." + vnf_name

        found = False
        from emuvim.api.heat.openstack_api_endpoint import OpenstackApiEndpoint

        for api in OpenstackApiEndpoint.dc_apis:
            if vnf_name[3:] in api.compute.dc.net:
                found = True
                break

        if not found:
            return Response(
                u"MonitorAPI: VNF %s does not exist.\n" % (vnf_name[3:]), status=500, mimetype="application/json"
            )
        try:
            docker_id = DockerUtil.docker_container_id(vnf_name)
            out_dict = dict()
            out_dict.update(DockerUtil.monitoring_over_time(docker_id))
            out_dict.update(DockerUtil.docker_mem(docker_id))
            out_dict.update(DockerUtil.docker_PIDS(docker_id))
            out_dict["SYS_time"] = int(time.time() * 1000000000)

            response = Response(json.dumps(out_dict) + "\n", status=200, mimetype="application/json")
            response.headers["Access-Control-Allow-Origin"] = "*"
            return response
        except Exception as e:
            logging.exception(u"%s: Error getting monitoring information.\n %s" % (__name__, e))
            return Response(u"Error getting monitoring information.\n", status=500, mimetype="application/json")
Esempio n. 2
0
    def get(self, dc, stack, vnf_name):
        """
        Calculates the workload for the specified docker container, at this point in time.
        This api call is for the translator to monitor a vnfs of a specific datacenter and stack.

        :param dc: Target datacenter.
        :type dc: ``str``
        :param stack: Target stack
        :type stack: ``str``
        :param vnf_name: Specifies the docker container via name.
        :type vnf_name: ``str``
        :return: Returns a json response with network, cpu, memory usage and storage access, as absolute values from
            startup till this point of time. It also contains the number of running processes and the current
            system time.
        :rtype: :class:`flask.response`
        """
        logging.debug("API CALL: %s GET" % str(self.__class__.__name__))

        # search for real name
        vnf_name = self._findName(dc, stack, vnf_name)

        if type(vnf_name) is not str:
            # something went wrong, vnf_name is a Response object
            return vnf_name

        try:
            docker_id = DockerUtil.docker_container_id(vnf_name)
            out_dict = dict()
            out_dict.update(DockerUtil.monitoring_over_time(docker_id))
            out_dict.update(DockerUtil.docker_mem(docker_id))
            out_dict.update(DockerUtil.docker_PIDS(docker_id))
            out_dict['SYS_time'] = int(time.time() * 1000000000)

            response = Response(json.dumps(out_dict) + '\n', status=200, mimetype="application/json")
            response.headers['Access-Control-Allow-Origin'] = '*'
            return response
        except Exception as e:
            logging.exception(u"%s: Error getting monitoring information.\n %s" % (__name__, e))
            return Response(u"Error getting monitoring information.\n", status=500, mimetype="application/json")