1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from yardstick.network_services.nfvi.resource import ResourceProfile
18 from yardstick.network_services.utils import get_nsb_option
21 LOG = logging.getLogger(__name__)
24 class Collector(object):
25 """Class that handles dictionary of results in yardstick-plot format."""
27 def __init__(self, vnfs, contexts_nodes, timeout=3600):
28 super(Collector, self).__init__()
30 self.nodes = contexts_nodes
31 self.bin_path = get_nsb_option('bin_path', '')
32 self.resource_profiles = {}
34 for ctx_name, nodes in ((ctx_name, nodes) for (ctx_name, nodes)
35 in contexts_nodes.items() if nodes):
36 for node in (node for node in nodes
37 if node and node.get('collectd')):
38 name = ".".join([node['name'], ctx_name])
39 self.resource_profiles.update(
40 {name: ResourceProfile.make_from_node(node, timeout)})
43 for resource in self.resource_profiles.values():
44 resource.initiate_systemagent(self.bin_path)
46 resource.amqp_process_for_nfvi_kpi()
55 for resource in self.resource_profiles.values():
59 """Returns dictionary of results in yardstick-plot format
61 :return: (dict) dictionary of kpis collected from the VNFs;
62 the keys are the names of the VNFs.
67 # {"VNF1: { "tput" : [1000, 999] }, "VNF2": { "latency": 100 }}
68 LOG.debug("collect KPI for vnf %s", vnf.name)
69 results[vnf.name] = vnf.collect_kpi()
71 for node_name, resource in self.resource_profiles.items():
72 LOG.debug("collect KPI for nfvi_node %s", node_name)
73 results[node_name] = {"core": resource.amqp_collect_nfvi_kpi()}
74 LOG.debug("%s collect KPIs %s", node_name, results[node_name]['core'])