from osm_mon.collector.backends.prometheus import PrometheusBackend
from osm_mon.collector.infra_collectors.openstack import OpenstackInfraCollector
-from osm_mon.collector.metric import Metric
from osm_mon.collector.vnf_collectors.juju import VCACollector
from osm_mon.collector.vnf_collectors.openstack import OpenstackCollector
from osm_mon.collector.vnf_collectors.vmware import VMwareCollector
vim_type = database_manager.get_vim_type(vim_account_id)
if vim_type in VIM_INFRA_COLLECTORS:
collector = VIM_INFRA_COLLECTORS[vim_type](self.conf, vim_account_id)
- status = collector.is_vim_ok()
- status_metric = Metric({'vim_id': vim_account_id}, 'vim_status', status)
- self.queue.put(status_metric)
+ metrics = collector.collect()
+ for metric in metrics:
+ self.queue.put(metric)
else:
log.debug("vimtype %s is not supported.", vim_type)
# contact: bdiaz@whitestack.com or glavado@whitestack.com
##
import logging
+from typing import List
from keystoneauth1 import session
from keystoneauth1.identity import v3
-from keystoneclient.v3 import client
+from keystoneclient.v3 import client as keystone_client
+from novaclient import client as nova_client
+from novaclient import v2 as nova_client_v2
from osm_mon.collector.infra_collectors.base_vim import BaseVimInfraCollector
+from osm_mon.collector.metric import Metric
from osm_mon.core.auth import AuthManager
+from osm_mon.core.common_db import CommonDbClient
from osm_mon.core.config import Config
log = logging.getLogger(__name__)
def __init__(self, config: Config, vim_account_id: str):
super().__init__(config, vim_account_id)
self.auth_manager = AuthManager(config)
- self.keystone_client = self._build_keystone_client(vim_account_id)
+ self.keystone = self._build_keystone_client(vim_account_id)
+ self.nova = self._build_nova_client(vim_account_id)
+ self.vim_account_id = vim_account_id
+ self.common_db = CommonDbClient(config)
+
+ def collect(self) -> List[Metric]:
+ metrics = []
+ vim_status = self.is_vim_ok()
+ vim_status_metric = Metric({'vim_account_id': self.vim_account_id}, 'vim_status', vim_status)
+ metrics.append(vim_status_metric)
+ vnfrs = self.common_db.get_vnfrs(vim_account_id=self.vim_account_id)
+ for vnfr in vnfrs:
+ nsr_id = vnfr['nsr-id-ref']
+ vnf_member_index = vnfr['member-vnf-index-ref']
+ for vdur in vnfr['vdur']:
+ resource_uuid = vdur['vim-id']
+ vm = self.nova.servers.get(resource_uuid)
+ vm_status = (1 if vm.status == 'ACTIVE' else 0)
+ tags = {
+ 'vim_account_id': self.vim_account_id,
+ 'resource_uuid': resource_uuid,
+ 'nsr_id': nsr_id,
+ 'vnf_member_index': vnf_member_index,
+ 'vdur_name': vdur['name']
+ }
+ vm_status_metric = Metric(tags, 'vm_status', vm_status)
+ metrics.append(vm_status_metric)
+
+ return metrics
def is_vim_ok(self) -> bool:
try:
- self.keystone_client.projects.list()
+ self.keystone.projects.list()
return True
except Exception:
log.exception("VIM status is not OK!")
return False
- def _build_keystone_client(self, vim_account_id):
+ def _build_keystone_client(self, vim_account_id) -> keystone_client.Client:
+ sess = self._get_session(vim_account_id)
+ return keystone_client.Client(session=sess)
+
+ def _build_nova_client(self, vim_account_id) -> nova_client_v2.Client:
+ sess = self._get_session(vim_account_id)
+ return nova_client.Client("2", session=sess)
+
+ def _get_session(self, vim_account_id):
creds = self.auth_manager.get_credentials(vim_account_id)
verify_ssl = self.auth_manager.is_verify_ssl(vim_account_id)
auth = v3.Password(auth_url=creds.url,
project_name=creds.tenant_name,
project_domain_id='default',
user_domain_id='default')
- sess = session.Session(auth=auth, verify=verify_ssl)
- return client.Client(session=sess)
+ return session.Session(auth=auth, verify=verify_ssl)
{"nsr-id-ref": nsr_id, "member-vnf-index-ref": str(member_index)})
return vnfr
- def get_vnfrs(self, nsr_id: str = None):
+ def get_vnfrs(self, nsr_id: str = None, vim_account_id: str = None):
+ if nsr_id and vim_account_id:
+ raise NotImplementedError("Only one filter is currently supported")
if nsr_id:
- return [self.get_vnfr(nsr_id, member['member-vnf-index']) for member in
- self.get_nsr(nsr_id)['nsd']['constituent-vnfd']]
+ vnfrs = [self.get_vnfr(nsr_id, member['member-vnf-index']) for member in
+ self.get_nsr(nsr_id)['nsd']['constituent-vnfd']]
+ elif vim_account_id:
+ vnfrs = self.common_db.get_list("vnfrs",
+ {"vim-account-id": vim_account_id})
else:
- return self.common_db.get_list('vnfrs')
+ vnfrs = self.common_db.get_list('vnfrs')
+ return vnfrs
def get_vnfd(self, vnfd_id: str):
vnfr = self.common_db.get_one("vnfds",