2 ##############################################################################
3 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 from elasticsearch import Elasticsearch
14 import utils.logger as log
15 from utils.parser import Parser as conf_parser
17 LOG = log.Logger(__name__).getLogger()
18 config = ConfigParser.ConfigParser()
20 dashboard_dir = os.path.join(conf_parser.test_dir,
25 def dashboard_send_data(runner_config, test_data):
27 es_ip = runner_config['dashboard_ip'].split(':')
28 es = Elasticsearch([{'host': es_ip[0]}])
29 res = es.index(index="bottlenecks",
30 doc_type=test_data["testcase"],
31 body=test_data["data_body"])
32 if res['created'] == "False":
33 LOG.error("date send to kibana have errors ", test_data["data_body"])
36 def dashboard_system_bandwidth(runner_config):
38 es_ip = runner_config['dashboard_ip'].split(':')
39 es = Elasticsearch([{'host': es_ip[0]}])
40 # Create bottlenecks index
41 with open(dashboard_dir + 'posca_system_bandwidth_index_pattern.json')\
43 doc = json.load(index_pattern)
46 doc_type="index-pattern",
49 if res['created'] == "True":
50 LOG.info("bottlenecks index-pattern has created")
52 LOG.info("bottlenecks index-pattern has existed")
54 with open(dashboard_dir + 'posca_system_bandwidth_config.json')\
56 doc = json.load(index_config)
57 res = es.index(index=".kibana", doc_type="config", id="4.6.1", body=doc)
58 if res['created'] == "True":
59 LOG.info("bottlenecks config has created")
61 LOG.info("bottlenecks config has existed")
63 # Configure discover panel
64 with open(dashboard_dir + 'posca_system_bandwidth_discover.json')\
66 doc = json.load(index_discover)
70 id="system_bandwidth",
72 if res['created'] == "True":
73 LOG.info("system_bandwidth search has created")
75 LOG.info("system_bandwidth search has existed")
77 # Create testing data in line graph
78 # Create testing data in line graph
79 with open(dashboard_dir + 'posca_system_bandwidth_line_data.json')\
81 doc = json.load(line_data)
84 doc_type="visualization",
85 id="system_bandwidth_line-date",
87 if res['created'] == "True":
88 LOG.info("system_bandwidth_line-date visualization has created")
90 LOG.info("system_bandwidth_line-date visualization has existed")
92 # Create comparison results in line chart
93 with open(dashboard_dir + 'posca_system_bandwidth_line_char.json')\
95 doc = json.load(line_char)
98 doc_type="visualization",
99 id="system_bandwidth_line-char",
101 if res['created'] == "True":
102 LOG.info("system_bandwidth_line-char visualization has created")
104 LOG.info("system_bandwidth_line-char visualization has existed")
106 # Create monitoring data in table
107 with open(dashboard_dir + 'posca_system_bandwidth_terms_data.json')\
109 doc = json.load(terms_char)
110 res = es.index(index=".kibana", doc_type="visualization",
111 id="system_bandwidth_terms_data", body=doc)
112 if res['created'] == "True":
113 LOG.info("system_bandwidth_terms_data visualization has created")
115 LOG.info("system_bandwidth_terms_data visualization has existed")
118 with open(dashboard_dir + 'posca_system_bandwidth_dashboard.json')\
120 doc = json.load(dashboard)
123 doc_type="dashboard",
124 id="system_bandwidth_dashboard",
126 if res['created'] == "True":
127 LOG.info("system_bandwidth dashboard has created")
129 LOG.info("system_bandwidth dashboard has existed")