1 ##############################################################################
2 # Copyright (c) 2017 Huawei Tech and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from oslo_serialization import jsonutils
16 logger = logging.getLogger(__name__)
17 MONITOR_DASHBOARD = "/home/opnfv/bottlenecks/monitor/dashboard/"
20 def _create_dashboard(ip, port, path):
21 url = 'http://admin:admin@{}:{}/api/dashboards/db'.format(ip, port)
22 logger.info("Fetched IP for dashboard creation!")
24 data = jsonutils.load(f)
26 post(url, {"dashboard": data})
27 logger.info("Trying to post dashboard json!")
29 logger.info("Create dashboard failed")
33 def _create_data_source(ip, port):
34 url = 'http://admin:admin@{}:{}/api/datasources'.format(ip, port)
35 logger.info("Fetched URL for datasource")
37 "name": "automated-ds",
40 "url": "http://{}:9090".format(ip),
44 logger.info("Trying to post datasource")
47 logger.info("Create Datasources failed")
52 data = jsonutils.dump_as_bytes(data)
53 logger.info("In post method for dumping data")
54 headers = {'Content-Type': 'application/json'}
56 response = requests.post(url, data=data, headers=headers)
57 result = response.json()
58 logger.debug('The result is: %s', result)
59 logger.info("Trying to post")
61 except Exception as e:
62 logger.info("Failed post" + str(e))
66 ip_address = socket.gethostbyname(socket.gethostname())
67 _create_data_source(ip_address, 3000)
68 _create_dashboard(ip_address, 3000, MONITOR_DASHBOARD + 'stats_overview.json')
69 _create_dashboard(ip_address, 3000,
70 MONITOR_DASHBOARD + 'jump_server_status.json')
71 _create_dashboard(ip_address, 3000, MONITOR_DASHBOARD + 'openstack_stats.json')