import peewee
from osm_mon.collector.backends.prometheus import PrometheusBackend
+from osm_mon.collector.infra_collectors.onos import OnosInfraCollector
from osm_mon.collector.infra_collectors.openstack import OpenstackInfraCollector
from osm_mon.collector.vnf_collectors.juju import VCACollector
from osm_mon.collector.vnf_collectors.openstack import OpenstackCollector
VIM_INFRA_COLLECTORS = {
"openstack": OpenstackInfraCollector
}
+SDN_INFRA_COLLECTORS = {
+ "onos": OnosInfraCollector
+}
METRIC_BACKENDS = [
PrometheusBackend
]
else:
log.debug("vimtype %s is not supported.", vim_type)
+ def _collect_sdnc_infra_metrics(self, sdnc_id: str):
+ common_db = CommonDbClient(self.conf)
+ sdn_type = common_db.get_sdnc(sdnc_id)['type']
+ if sdn_type in SDN_INFRA_COLLECTORS:
+ collector = SDN_INFRA_COLLECTORS[sdn_type](self.conf, sdnc_id)
+ metrics = collector.collect()
+ for metric in metrics:
+ self.queue.put(metric)
+ else:
+ log.debug("sdn_type %s is not supported.", sdn_type)
+
def _collect_vca_metrics(self, vnfr: dict):
log.debug('_collect_vca_metrics')
log.debug('vnfr: %s', vnfr)
args=(vim['_id'],))
processes.append(p)
p.start()
+ sdncs = self.common_db.get_sdncs()
+ for sdnc in sdncs:
+ p = multiprocessing.Process(target=self._collect_sdnc_infra_metrics,
+ args=(sdnc['_id'],))
+ processes.append(p)
+ p.start()
for process in processes:
process.join(timeout=10)
metrics = []
--- /dev/null
+# Copyright 2018 Whitestack, LLC
+# *************************************************************
+
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, 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.
+
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: bdiaz@whitestack.com or glavado@whitestack.com
+##
+from osm_mon.collector.infra_collectors.base import BaseInfraCollector
+
+from osm_mon.core.config import Config
+
+
+class BaseSdncInfraCollector(BaseInfraCollector):
+ def __init__(self, config: Config, sdn_id: str):
+ pass
--- /dev/null
+# Copyright 2018 Whitestack, LLC
+# *************************************************************
+
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, 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.
+
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: bdiaz@whitestack.com or glavado@whitestack.com
+##
+import logging
+from typing import List
+
+import requests
+from requests.auth import HTTPBasicAuth
+
+from osm_mon.collector.infra_collectors.base_sdnc import BaseSdncInfraCollector
+from osm_mon.collector.metric import Metric
+from osm_mon.core.common_db import CommonDbClient
+from osm_mon.core.config import Config
+
+log = logging.getLogger(__name__)
+
+
+class OnosInfraCollector(BaseSdncInfraCollector):
+ def __init__(self, config: Config, sdnc_id: str):
+ super().__init__(config, sdnc_id)
+ self.common_db = CommonDbClient(config)
+ self.sdnc = self.common_db.get_sdnc(sdnc_id)
+
+ def collect(self) -> List[Metric]:
+ metrics = []
+ sdnc_status = self.is_sdnc_ok()
+ sdnc_status_metric = Metric({'sdnc_id': self.sdnc['_id']}, 'sdnc_status', sdnc_status)
+ metrics.append(sdnc_status_metric)
+
+ return metrics
+
+ def is_sdnc_ok(self) -> bool:
+ try:
+ ip = self.sdnc['ip']
+ port = self.sdnc['port']
+ user = self.sdnc['user']
+ password = self.common_db.decrypt_sdnc_password(self.sdnc['password'],
+ self.sdnc['schema_version'],
+ self.sdnc['_id'])
+ # TODO: Add support for https
+ url = 'http://{}:{}/onos/v1/devices'.format(ip, port)
+ requests.get(url, auth=HTTPBasicAuth(user, password))
+ return True
+ except Exception:
+ log.exception("SDNC status is not OK!")
+ return False
def decrypt_vim_password(self, vim_password: str, schema_version: str, vim_id: str):
return self.common_db.decrypt(vim_password, schema_version, vim_id)
+ def decrypt_sdnc_password(self, sdnc_password: str, schema_version: str, sdnc_id: str):
+ return self.common_db.decrypt(sdnc_password, schema_version, sdnc_id)
+
def get_vim_account_id(self, nsr_id: str, vnf_member_index: int) -> str:
vnfr = self.get_vnfr(nsr_id, vnf_member_index)
return vnfr['vim-account-id']
def get_vim_accounts(self):
return self.common_db.get_list('vim_accounts')
+
+ def get_sdncs(self):
+ return self.common_db.get_list('sdns')
+
+ def get_sdnc(self, sdnc_id: str):
+ return self.common_db.get_one('sdns', {'_id': sdnc_id})