1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd 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 ##############################################################################
9 from __future__ import absolute_import
13 import six.moves.configparser as ConfigParser
14 from six.moves.urllib.parse import urlsplit
15 from influxdb import InfluxDBClient
17 from yardstick.common import constants as consts
19 logger = logging.getLogger(__name__)
22 def get_data_db_client():
23 parser = ConfigParser.ConfigParser()
25 parser.read(consts.CONF_FILE)
27 if parser.get('DEFAULT', 'dispatcher') != 'influxdb':
30 return _get_client(parser)
31 except ConfigParser.NoOptionError:
32 logger.error('can not find the key')
36 def _get_client(parser):
37 ip = _get_ip(parser.get('dispatcher_influxdb', 'target'))
38 user = parser.get('dispatcher_influxdb', 'username')
39 password = parser.get('dispatcher_influxdb', 'password')
40 db_name = parser.get('dispatcher_influxdb', 'db_name')
41 return InfluxDBClient(ip, consts.INFLUXDB_PORT, user, password, db_name)
45 return urlsplit(url).hostname
50 client = get_data_db_client()
51 logger.debug('Start to query: %s', query_sql)
52 return list(client.query(query_sql).get_points())
54 logger.error('dispatcher is not influxdb')