Merge "Adding more labels to Prometheus metrics"
authorlavado <glavado@whitestack.com>
Fri, 29 Nov 2019 16:24:16 +0000 (17:24 +0100)
committerGerrit Code Review <root@osm.etsi.org>
Fri, 29 Nov 2019 16:24:16 +0000 (17:24 +0100)
debian/python3-osm-mon.postinst
osm_mon/collector/infra_collectors/base_osinfra.py
osm_mon/collector/infra_collectors/onos.py
osm_mon/collector/infra_collectors/vmware.py
osm_mon/collector/vnf_collectors/openstack.py
osm_mon/migrations/001_initial.py
requirements.txt
setup.py

index f41b674..ff08172 100644 (file)
@@ -28,7 +28,7 @@ pip3 install requests==2.18.*
 pip3 install python-keystoneclient==3.15.*
 pip3 install six==1.11.*
 pip3 install peewee==3.8.*
-pip3 install pyyaml==3.*
+pip3 install pyyaml>=5.1.2
 pip3 install prometheus_client==0.4.*
 pip3 install gnocchiclient==7.0.*
 pip3 install pyvcloud==19.1.1
index 3541dbd..9c8447c 100644 (file)
@@ -46,12 +46,19 @@ class BaseOpenStackInfraCollector(BaseVimInfraCollector):
     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)
+        vim_project_id = self.vim_account['_admin']['projects_read'][0]
+        vim_tags = {
+            'vim_account_id': self.vim_account['_id'],
+            'project_id': vim_project_id
+        }
+        vim_status_metric = Metric(vim_tags, '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']
+            ns_name = self.common_db.get_nsr(nsr_id)['name']
             vnf_member_index = vnfr['member-vnf-index-ref']
+            vnfr_project_id = vnfr['_admin']['projects_read'][0]
             for vdur in vnfr['vdur']:
                 if 'vim-id' not in vdur:
                     log.debug("Field vim-id is not present in vdur")
@@ -61,8 +68,10 @@ class BaseOpenStackInfraCollector(BaseVimInfraCollector):
                     'vim_account_id': self.vim_account['_id'],
                     'resource_uuid': resource_uuid,
                     'nsr_id': nsr_id,
+                    'ns_name': ns_name,
                     'vnf_member_index': vnf_member_index,
-                    'vdur_name': vdur['name']
+                    'vdur_name': vdur['name'],
+                    'project_id': vnfr_project_id
                 }
                 try:
                     vm = self.nova.servers.get(resource_uuid)
index ea2e505..21ef85d 100644 (file)
@@ -42,7 +42,12 @@ class OnosInfraCollector(BaseSdncInfraCollector):
     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)
+        sdnc_project_id = self.sdnc['_admin']['projects_read'][0]
+        sdnc_tags = {
+            'sdnc_id': self.sdnc['_id'],
+            'project_id': sdnc_project_id
+        }
+        sdnc_status_metric = Metric(sdnc_tags, 'sdnc_status', sdnc_status)
         metrics.append(sdnc_status_metric)
 
         return metrics
index 0f40d48..c5db5ec 100644 (file)
@@ -50,6 +50,7 @@ class VMwareInfraCollector(BaseVimInfraCollector):
         self.admin_password = vim_account['admin_password']
         self.vim_uuid = vim_account['vim_uuid']
         self.org_name = vim_account['orgname']
+        self.vim_project_id = vim_account['project_id']
 
     def connect_vim_as_admin(self):
         """ Method connect as pvdc admin user to vCloud director.
@@ -95,6 +96,7 @@ class VMwareInfraCollector(BaseVimInfraCollector):
                                                                           vim_account_info['schema_version'],
                                                                           vim_account_id)
         vim_account['vim_uuid'] = vim_account_info['_id']
+        vim_account['project_id'] = vim_account_info['_admin']['projects_read'][0]
 
         vim_config = vim_account_info['config']
         vim_account['admin_username'] = vim_config['admin_username']
@@ -171,20 +173,30 @@ class VMwareInfraCollector(BaseVimInfraCollector):
     def collect(self) -> List[Metric]:
         metrics = []
         vim_status = self.check_vim_status()
-        vim_status_metric = Metric({'vim_account_id': self.vim_account_id}, 'vim_status', vim_status)
+        vim_account_id = self.vim_account_id
+        vim_project_id = self.vim_project_id
+        vim_tags = {
+            'vim_account_id': vim_account_id,
+            'project_id': vim_project_id
+        }
+        vim_status_metric = Metric(vim_tags, 'vim_status', vim_status)
         metrics.append(vim_status_metric)
-        vnfrs = self.common_db.get_vnfrs(vim_account_id=self.vim_account_id)
+        vnfrs = self.common_db.get_vnfrs(vim_account_id=vim_account_id)
         for vnfr in vnfrs:
             nsr_id = vnfr['nsr-id-ref']
+            ns_name = self.common_db.get_nsr(nsr_id)['name']
             vnf_member_index = vnfr['member-vnf-index-ref']
+            vnfr_project_id = vnfr['_admin']['projects_read'][0]
             for vdur in vnfr['vdur']:
                 resource_uuid = vdur['vim-id']
                 tags = {
                     'vim_account_id': self.vim_account_id,
                     'resource_uuid': resource_uuid,
                     'nsr_id': nsr_id,
+                    'ns_name': ns_name,
                     'vnf_member_index': vnf_member_index,
-                    'vdur_name': vdur['name']
+                    'vdur_name': vdur['name'],
+                    'project_id': vnfr_project_id
                 }
                 try:
                     vm_list = self.check_vm_status(resource_uuid)
index 122fdd6..a13380a 100644 (file)
@@ -28,6 +28,7 @@ from ceilometerclient import client as ceilometer_client
 from ceilometerclient.exc import HTTPException
 from gnocchiclient.v1 import client as gnocchi_client
 from keystoneclient.v3 import client as keystone_client
+from keystoneauth1.exceptions.catalog import EndpointNotFound
 from neutronclient.v2_0 import client as neutron_client
 
 from osm_mon.collector.metric import Metric
@@ -125,7 +126,7 @@ class OpenstackCollector(BaseVimCollector):
             ceilometer = CeilometerBackend(vim_account)
             ceilometer.client.capabilities.get()
             return ceilometer
-        except HTTPException:
+        except (HTTPException, EndpointNotFound):
             gnocchi = GnocchiBackend(vim_account)
             gnocchi.client.metric.list(limit=1)
             return gnocchi
index cb5fb41..346e9c1 100644 (file)
@@ -1,3 +1,26 @@
+# -*- coding: utf-8 -*-
+
+# 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
+##
 """Peewee migrations -- 001_initial.py.
 
 Some examples (model - class or model name)::
index 6215643..29ee06a 100644 (file)
@@ -23,7 +23,7 @@ requests==2.18.*
 python-keystoneclient==3.15.*
 six==1.11.*
 peewee==3.8.*
-pyyaml==3.*
+pyyaml>=5.1.2
 prometheus_client==0.4.*
 gnocchiclient==7.0.*
 pymysql==0.9.*
index 032ee87..1cee33f 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -56,7 +56,7 @@ setup(
         "python-keystoneclient==3.15.*",
         "six==1.11.*",
         "peewee==3.8.*",
-        "pyyaml==3.*",
+        "pyyaml>=5.1.2",
         "prometheus_client==0.4.*",
         "gnocchiclient==7.0.*",
         "pyvcloud==19.1.1",