162a5270b0f99855f0a67114d1cce754a67ce5e0
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 multiprocessing
import Queue
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
.common
.common_db_client
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, queue
: Queue
):
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'])
48 for vdur
in vnfr
['vdur']:
49 nsr
= self
.common_db
.get_nsr(nsr_id
)
51 filter(lambda vdu
: vdu
['id'] == vdur
['vdu-id-ref'], vnfd
['vdu'])
53 if 'vdu-configuration' in vdu
and 'metrics' in vdu
['vdu-configuration']:
54 vnf_name_vca
= self
.n2vc
.FormatApplicationName(nsr
['name'], vnf_member_index
, vdur
['vdu-id-ref'])
55 metrics
= self
.loop
.run_until_complete(self
.n2vc
.GetMetrics(vca_model_name
, vnf_name_vca
))
56 log
.debug('Metrics: %s', metrics
)
57 for metric_list
in metrics
.values():
58 for metric
in metric_list
:
59 log
.debug("Metric: %s", metric
)
60 metric
= Metric(nsr_id
, vnf_member_index
, vdur
['name'], metric
['key'], float(metric
['value']))
62 if 'vnf-configuration' in vnfr
and 'metrics' in vnfr
['vnf-configuration']:
63 vnf_name_vca
= self
.n2vc
.FormatApplicationName(nsr
['name'], vnf_member_index
, vdur
['vdu-id-ref'])
64 metrics
= self
.loop
.run_until_complete(self
.n2vc
.GetMetrics(vca_model_name
, vnf_name_vca
))
65 log
.debug('Metrics: %s', metrics
)
66 for metric_list
in metrics
.values():
67 for metric
in metric_list
:
68 log
.debug("Metric: %s", metric
)
69 metric
= Metric(nsr_id
, vnf_member_index
, vdur
['name'], metric
['key'], float(metric
['value']))
71 # TODO (diazb): Implement vnf-configuration config