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_path = os.path.join(conf_parser.test_dir,
23 dashboard_dir = dashboard_path + "/"
26 def dashboard_send_data(runner_config, test_data):
28 es_ip = runner_config['dashboard_ip'].split(':')
29 es = Elasticsearch([{'host': es_ip[0]}])
30 res = es.index(index="bottlenecks",
31 doc_type=test_data["testcase"],
32 body=test_data["data_body"])
33 if res['created'] == "False":
34 LOG.error("date send to kibana have errors ", test_data["data_body"])
37 def dashboard_system_bandwidth(runner_config):
39 es_ip = runner_config['dashboard_ip'].split(':')
40 es = Elasticsearch([{'host': es_ip[0]}])
41 # Create bottlenecks index
42 with open(dashboard_dir + 'posca_system_bandwidth_index_pattern.json')\
44 doc = json.load(index_pattern)
47 doc_type="index-pattern",
50 if res['created'] == "True":
51 LOG.info("bottlenecks index-pattern has created")
53 LOG.info("bottlenecks index-pattern has existed")
55 with open(dashboard_dir + 'posca_system_bandwidth_config.json')\
57 doc = json.load(index_config)
58 res = es.index(index=".kibana", doc_type="config", id="4.6.1", body=doc)
59 if res['created'] == "True":
60 LOG.info("bottlenecks config has created")
62 LOG.info("bottlenecks config has existed")
64 # Configure discover panel
65 with open(dashboard_dir + 'posca_system_bandwidth_discover.json')\
67 doc = json.load(index_discover)
71 id="system_bandwidth",
73 if res['created'] == "True":
74 LOG.info("system_bandwidth search has created")
76 LOG.info("system_bandwidth search has existed")
78 # Create testing data in line graph
79 # Create testing data in line graph
80 with open(dashboard_dir + 'posca_system_bandwidth_line_data.json')\
82 doc = json.load(line_data)
85 doc_type="visualization",
86 id="system_bandwidth_line-date",
88 if res['created'] == "True":
89 LOG.info("system_bandwidth_line-date visualization has created")
91 LOG.info("system_bandwidth_line-date visualization has existed")
93 # Create comparison results in line chart
94 with open(dashboard_dir + 'posca_system_bandwidth_line_char.json')\
96 doc = json.load(line_char)
99 doc_type="visualization",
100 id="system_bandwidth_line-char",
102 if res['created'] == "True":
103 LOG.info("system_bandwidth_line-char visualization has created")
105 LOG.info("system_bandwidth_line-char visualization has existed")
107 # Create monitoring data in table
108 with open(dashboard_dir + 'posca_system_bandwidth_terms_data.json')\
110 doc = json.load(terms_char)
111 res = es.index(index=".kibana", doc_type="visualization",
112 id="system_bandwidth_terms_data", body=doc)
113 if res['created'] == "True":
114 LOG.info("system_bandwidth_terms_data visualization has created")
116 LOG.info("system_bandwidth_terms_data visualization has existed")
119 with open(dashboard_dir + 'posca_system_bandwidth_dashboard.json')\
121 doc = json.load(dashboard)
124 doc_type="dashboard",
125 id="system_bandwidth_dashboard",
127 if res['created'] == "True":
128 LOG.info("system_bandwidth dashboard has created")
130 LOG.info("system_bandwidth dashboard has existed")