1 # -*- coding: utf-8 -*-
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 from base_topic
import EngineException
21 __author__
= "Vijay R S <vijay.r@tataelxsi.co.in>"
25 def __init__(self
, host
=None, port
=None):
26 self
.url
= 'http://{}:{}'.format(host
, port
)
27 self
.metric_list
= ['cpu_utilization', 'average_memory_utilization', 'disk_read_ops',
28 'disk_write_ops', 'disk_read_bytes', 'disk_write_bytes', 'packets_dropped',
29 'packets_sent', 'packets_received']
31 async def _prom_metric_request(self
, ns_id
):
33 async with aiohttp
.ClientSession() as session
:
35 for metlist
in self
.metric_list
:
36 request_url
= self
.url
+'/api/v1/query?query=osm_'+metlist
+"{ns_id='"+ns_id
+"'}"
37 async with session
.get(request_url
) as resp
:
38 resp
= await resp
.json()
39 resp
= resp
['data']['result']
43 except aiohttp
.client_exceptions
.ClientConnectorError
as e
:
44 raise EngineException("Connection Failure: {}".format(e
))
46 def show(self
, session
, ns_id
):
47 loop
= asyncio
.new_event_loop()
48 asyncio
.set_event_loop(loop
)
49 prom_metric
= loop
.run_until_complete(self
._prom
_metric
_request
(ns_id
))
52 for index_list
in prom_metric
:
53 for index
in index_list
:
54 process_metric
= {'performanceValue': {'performanceValue': {}}}
55 process_metric
['objectInstanceId'] = index
['metric']['ns_id']
56 process_metric
['performanceMetric'] = index
['metric']['__name__']
57 process_metric
['performanceValue']['timestamp'] = index
['value'][0]
58 process_metric
['performanceValue']['performanceValue']['performanceValue'] = index
['value'][1]
59 process_metric
['performanceValue']['performanceValue']['vnfMemberIndex'] \
60 = index
['metric']['vnf_member_index']
61 process_metric
['performanceValue']['performanceValue']['vduName'] = index
['metric']['vdu_name']
62 metric_temp
.append(process_metric
)
63 metric
['entries'] = metric_temp