X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fnetwork_services%2Fcollector%2Fsubscriber.py;h=0c6d9777157242bd39810f3122185055105659d5;hb=acc0f9cffaa84553bd2b5d86dabd82d907a281da;hp=db52e0b4539e9241c1298060896ec5295e82cd4e;hpb=dd57115618caa299f6dd1eb350b55ecf062ca92e;p=yardstick.git diff --git a/yardstick/network_services/collector/subscriber.py b/yardstick/network_services/collector/subscriber.py index db52e0b45..0c6d97771 100644 --- a/yardstick/network_services/collector/subscriber.py +++ b/yardstick/network_services/collector/subscriber.py @@ -11,74 +11,66 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 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.""" - @staticmethod - def make_resource_profile(node, timeout): - # node dict works as mgmt dict - # don't need port names, there is no way we can - # tell what port is used on the compute node - collectd_options = node["collectd"] - plugins = collectd_options.get("plugins", {}) - interval = collectd_options.get("interval") - - # use default cores = None to MatchAllCores - return ResourceProfile(node, plugins=plugins, interval=interval, timeout=timeout) - - def __init__(self, vnfs, nodes, traffic_profile, timeout=3600): + def __init__(self, vnfs, contexts_nodes, timeout=3600): super(Collector, self).__init__() - self.traffic_profile = traffic_profile self.vnfs = vnfs - self.nodes = nodes - self.timeout = timeout + self.nodes = contexts_nodes self.bin_path = get_nsb_option('bin_path', '') - self.resource_profiles = {node_name: self.make_resource_profile(node, self.timeout) - for node_name, node in self.nodes.items() - if node.get("collectd")} + self.resource_profiles = {} + + for ctx_name, nodes in ((ctx_name, nodes) for (ctx_name, nodes) + in contexts_nodes.items() if nodes): + for node in (node for node in nodes + if node and 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""" 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""" + for vnf in self.vnfs: + vnf.stop_collect() + for resource in self.resource_profiles.values(): resource.stop() 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. """ results = {} for vnf in self.vnfs: # Result example: # {"VNF1: { "tput" : [1000, 999] }, "VNF2": { "latency": 100 }} - LOG.debug("collect KPI for %s", vnf.name) + LOG.debug("collect KPI for vnf %s", vnf.name) results[vnf.name] = vnf.collect_kpi() for node_name, resource in self.resource_profiles.items(): - # Result example: - # {"VNF1: { "tput" : [1000, 999] }, "VNF2": { "latency": 100 }} - LOG.debug("collect KPI for %s", node_name) - if not resource.check_if_sa_running("collectd")[0]: - continue - - try: - results[node_name] = {"core": resource.amqp_collect_nfvi_kpi()} - except Exception: - LOG.exception("") + 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