X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fnetwork_services%2Fcollector%2Fsubscriber.py;h=937c266a6c23b2b67b775accba3de38361559e6e;hb=42e3f88b07624d0ff9f4c43f9200fc928eed2a1e;hp=3bcb20876e67b1f38f6095614f0238470cc054c5;hpb=b409268138132bdb1d275d4fb5d31f2a61180198;p=yardstick.git diff --git a/yardstick/network_services/collector/subscriber.py b/yardstick/network_services/collector/subscriber.py index 3bcb20876..937c266a6 100644 --- a/yardstick/network_services/collector/subscriber.py +++ b/yardstick/network_services/collector/subscriber.py @@ -12,28 +12,64 @@ # See the License for the specific language governing permissions and # limitations under the License. """This module implements stub for publishing results in yardstick format.""" +import logging + +from yardstick.network_services.nfvi.resource import ResourceProfile +from yardstick.network_services.utils import get_nsb_option + + +LOG = logging.getLogger(__name__) class Collector(object): """Class that handles dictionary of results in yardstick-plot format.""" - def __init__(self, traffic_profile, vnfs): + def __init__(self, vnfs, contexts_nodes, timeout=3600): super(Collector, self).__init__() - self.traffic_profile = traffic_profile - self.service = vnfs + self.vnfs = vnfs + self.nodes = contexts_nodes + self.bin_path = get_nsb_option('bin_path', '') + self.resource_profiles = {} + + for ctx_name, nodes in contexts_nodes.items(): + for node in (node for node in nodes if node.get('collectd')): + name = ".".join([node['name'], ctx_name]) + self.resource_profiles.update( + {name: ResourceProfile.make_from_node(node, timeout)} + ) def start(self): - """Nothing to do, yet""" - pass + for resource in self.resource_profiles.values(): + resource.initiate_systemagent(self.bin_path) + resource.start() + resource.amqp_process_for_nfvi_kpi() + + for vnf in self.vnfs: + vnf.start_collect() def stop(self): - """Nothing to do, yet""" - pass + for vnf in self.vnfs: + vnf.stop_collect() + + for resource in self.resource_profiles.values(): + resource.stop() - @classmethod - def get_kpi(cls, vnf): + def get_kpi(self): """Returns dictionary of results in yardstick-plot format - :return: + :return: (dict) dictionary of kpis collected from the VNFs; + the keys are the names of the VNFs. """ - return {vnf.name: vnf.collect_kpi()} + results = {} + for vnf in self.vnfs: + # Result example: + # {"VNF1: { "tput" : [1000, 999] }, "VNF2": { "latency": 100 }} + LOG.debug("collect KPI for vnf %s", vnf.name) + results[vnf.name] = vnf.collect_kpi() + + for node_name, resource in self.resource_profiles.items(): + LOG.debug("collect KPI for nfvi_node %s", node_name) + results[node_name] = {"core": resource.amqp_collect_nfvi_kpi()} + LOG.debug("%s collect KPIs %s", node_name, results[node_name]['core']) + + return results