1 # Copyright 2018 Whitestack, LLC
2 # *************************************************************
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Whitestack, LLC
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
19 # For those usages not covered by the Apache License, Version 2.0 please
20 # contact: bdiaz@whitestack.com or glavado@whitestack.com
24 from typing
import List
26 from n2vc
.vnf
import N2VC
28 from osm_mon
.collector
.collectors
.base
import BaseCollector
29 from osm_mon
.collector
.metric
import Metric
30 from osm_mon
.core
.common_db
import CommonDbClient
31 from osm_mon
.core
.settings
import Config
33 log
= logging
.getLogger(__name__
)
36 class VCACollector(BaseCollector
):
38 cfg
= Config
.instance()
39 self
.common_db
= CommonDbClient()
40 self
.loop
= asyncio
.get_event_loop()
41 self
.n2vc
= N2VC(server
=cfg
.OSMMON_VCA_HOST
, user
=cfg
.OSMMON_VCA_USER
, secret
=cfg
.OSMMON_VCA_SECRET
)
43 def collect(self
, vnfr
: dict) -> List
[Metric
]:
44 vca_model_name
= 'default'
45 nsr_id
= vnfr
['nsr-id-ref']
46 vnf_member_index
= vnfr
['member-vnf-index-ref']
47 vnfd
= self
.common_db
.get_vnfd(vnfr
['vnfd-id'])
49 nsr
= self
.common_db
.get_nsr(nsr_id
)
50 for vdur
in vnfr
['vdur']:
52 filter(lambda vdu
: vdu
['id'] == vdur
['vdu-id-ref'], vnfd
['vdu'])
54 if 'vdu-configuration' in vdu
and 'metrics' in vdu
['vdu-configuration']:
55 vnf_name_vca
= self
.n2vc
.FormatApplicationName(nsr
['name'], vnf_member_index
, vdur
['vdu-id-ref'])
56 measures
= self
.loop
.run_until_complete(self
.n2vc
.GetMetrics(vca_model_name
, vnf_name_vca
))
57 log
.debug('Metrics: %s', metrics
)
58 for measure_list
in measures
.values():
59 for measure
in measure_list
:
60 log
.debug("Metric: %s", measure
)
61 metric
= Metric(nsr_id
, vnf_member_index
, vdur
['name'], measure
['key'], float(measure
['value']))
62 metrics
.append(metric
)
63 if 'vnf-configuration' in vnfd
and 'metrics' in vnfd
['vnf-configuration']:
64 vnf_name_vca
= self
.n2vc
.FormatApplicationName(nsr
['name'], vnf_member_index
, 'vnfd')
65 measures
= self
.loop
.run_until_complete(self
.n2vc
.GetMetrics(vca_model_name
, vnf_name_vca
))
66 log
.debug('Metrics: %s', metrics
)
67 for measure_list
in measures
.values():
68 for measure
in measure_list
:
69 log
.debug("Metric: %s", measure
)
70 metric
= Metric(nsr_id
, vnf_member_index
, '', measure
['key'], float(measure
['value']))
71 metrics
.append(metric
)