当前位置: 首页>>代码示例>>Python>>正文


Python InfluxDBClusterClient.query方法代码示例

本文整理汇总了Python中influxdb.InfluxDBClusterClient.query方法的典型用法代码示例。如果您正苦于以下问题:Python InfluxDBClusterClient.query方法的具体用法?Python InfluxDBClusterClient.query怎么用?Python InfluxDBClusterClient.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在influxdb.InfluxDBClusterClient的用法示例。


在下文中一共展示了InfluxDBClusterClient.query方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_all_fail

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_all_fail(self):
     cluster = InfluxDBClusterClient(
         hosts=self.hosts, database="database", shuffle=True, client_base_class=FakeClient
     )
     with self.assertRaises(InfluxDBServerError):
         cluster.query("Fail")
     self.assertEqual(0, len(cluster.hosts))
     self.assertEqual(3, len(cluster.bad_hosts))
开发者ID:a-sk,项目名称:influxdb-python,代码行数:10,代码来源:client_test.py

示例2: test_recovery

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_recovery(self):
     cluster = InfluxDBClusterClient(
         hosts=self.hosts, database="database", shuffle=True, client_base_class=FakeClient
     )
     with self.assertRaises(InfluxDBServerError):
         cluster.query("Fail")
     self.assertEqual("Success", cluster.query(""))
     self.assertEqual(1, len(cluster.hosts))
     self.assertEqual(2, len(cluster.bad_hosts))
开发者ID:a-sk,项目名称:influxdb-python,代码行数:11,代码来源:client_test.py

示例3: test_recovery

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_recovery(self):
     cluster = InfluxDBClusterClient(hosts=self.hosts,
                                     database='database',
                                     shuffle=True,
                                     client_base_class=FakeClient)
     with self.assertRaises(InfluxDBServerError):
         cluster.query('Fail')
     self.assertEqual('Success', cluster.query(''))
     self.assertEqual(1, len(cluster.clients))
     self.assertEqual(2, len(cluster.bad_clients))
开发者ID:arnimarj,项目名称:influxdb-python,代码行数:12,代码来源:client_test.py

示例4: test_healing

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_healing(self):
     cluster = InfluxDBClusterClient(
         hosts=self.hosts, database="database", shuffle=True, healing_delay=1, client_base_class=FakeClient
     )
     with self.assertRaises(InfluxDBServerError):
         cluster.query("Fail")
     self.assertEqual("Success", cluster.query(""))
     time.sleep(1.1)
     self.assertEqual("Success", cluster.query(""))
     self.assertEqual(2, len(cluster.hosts))
     self.assertEqual(1, len(cluster.bad_hosts))
     time.sleep(1.1)
     self.assertEqual("Success", cluster.query(""))
     self.assertEqual(3, len(cluster.hosts))
     self.assertEqual(0, len(cluster.bad_hosts))
开发者ID:a-sk,项目名称:influxdb-python,代码行数:17,代码来源:client_test.py

示例5: test_all_good

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_all_good(self):
     cluster = InfluxDBClusterClient(
         hosts=self.hosts, database="database", shuffle=True, client_base_class=FakeClient
     )
     self.assertEqual("Success", cluster.query(""))
     self.assertEqual(3, len(cluster.hosts))
     self.assertEqual(0, len(cluster.bad_hosts))
开发者ID:a-sk,项目名称:influxdb-python,代码行数:9,代码来源:client_test.py

示例6: test_two_servers_fail

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_two_servers_fail(self):
     cluster = InfluxDBClusterClient(
         hosts=self.hosts, database="database", shuffle=False, client_base_class=FakeClient
     )
     self.assertEqual("Success", cluster.query("Fail twice"))
     self.assertEqual(1, len(cluster.hosts))
     self.assertEqual(2, len(cluster.bad_hosts))
开发者ID:a-sk,项目名称:influxdb-python,代码行数:9,代码来源:client_test.py

示例7: test_one_server_fails

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_one_server_fails(self):
     cluster = InfluxDBClusterClient(hosts=self.hosts,
                                     database='database',
                                     shuffle=False,
                                     client_base_class=FakeClient)
     self.assertEqual('Success', cluster.query('Fail once'))
     self.assertEqual(2, len(cluster.hosts))
     self.assertEqual(1, len(cluster.bad_hosts))
开发者ID:simudream,项目名称:influxdb-python,代码行数:10,代码来源:client_test.py

示例8: test_all_good

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_all_good(self):
     cluster = InfluxDBClusterClient(hosts=self.hosts,
                                     database='database',
                                     shuffle=True,
                                     client_base_class=FakeClient)
     self.assertEqual('Success', cluster.query(''))
     self.assertEqual(3, len(cluster.clients))
     self.assertEqual(0, len(cluster.bad_clients))
开发者ID:arnimarj,项目名称:influxdb-python,代码行数:10,代码来源:client_test.py

示例9: test_one_server_fails

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_one_server_fails(self):
     cluster = InfluxDBClusterClient(
         hosts=self.hosts, database="database", shuffle=False, client_base_class=FakeClient
     )
     cluster.clients[0].fail = True
     self.assertEqual("Success", cluster.query(""))
     self.assertEqual(2, len(cluster.clients))
     self.assertEqual(1, len(cluster.bad_clients))
开发者ID:krishnazure,项目名称:influxdb-python,代码行数:10,代码来源:client_test.py

示例10: test_two_servers_fail

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
 def test_two_servers_fail(self):
     cluster = InfluxDBClusterClient(hosts=self.hosts,
                                     database='database',
                                     shuffle=False,
                                     client_base_class=FakeClient)
     cluster.clients[0].fail = True
     cluster.clients[1].fail = True
     self.assertEqual('Success', cluster.query(''))
     self.assertEqual(1, len(cluster.clients))
     self.assertEqual(2, len(cluster.bad_clients))
开发者ID:arnimarj,项目名称:influxdb-python,代码行数:12,代码来源:client_test.py

示例11: Influxdb

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
class Influxdb(object):
    def __init__(self):
        self.influxdb_user   = args.influxdb_user
        self.influxdb_passwd = args.influxdb_passwd
        self.influxdb_ssl    = args.influxdb_ssl
        self.influxdb_verify_ssl    = args.influxdb_verify_ssl
        self.databases       = re.compile(args.databases)
        self.hosts           = []

	for host in args.hosts.split(','):
            self.hosts.append(tuple(filter(None, host.split(':'))))
	
        self.is_connected = DISCONNECTED

    def open(self):
       """
       Connect to InfluxDB cluster.
       """
       try:
           self.cc = InfluxDBClusterClient(hosts = self.hosts,
                               username=self.influxdb_user,
                               password=self.influxdb_passwd,
                               ssl=self.influxdb_ssl,
                               verify_ssl=self.influxdb_verify_ssl)

           self.is_connected = CONNECTED

       except InfluxDBClientError as e:
           logging.warning("Connection failed: %s" % e)
           return False

       return True

    def get_ds_list(self):
        dbs = self.cc.get_list_database()
        return [db for db in dbs if self.databases.search(db['name'])]
   
    def get_measurements(self,dbname):
        self.cc.switch_database(dbname)
	m = self.cc.query('SHOW MEASUREMENTS')
        return json.dumps(m.raw['series'][0]['values'])
开发者ID:AWsHABALIN,项目名称:grafana-telegraf-dashboard-generator,代码行数:43,代码来源:generator.py

示例12: InfluxDBWrapper

# 需要导入模块: from influxdb import InfluxDBClusterClient [as 别名]
# 或者: from influxdb.InfluxDBClusterClient import query [as 别名]
class InfluxDBWrapper(object):
    """ Wrapper the influxdb API, Return Data

    Args:
        __status__: the connection status
        __connection__: the connection object of the influxdb database
    """

    status = 0
    __connection__ = None

    def __init__(self, influxdb_hosts=[('101.201.235.144', 8086)], influxdb_user='root', influxdb_passwd='root', influxdb_database='k8s'):
        """Init the wrapper

        Args:
            influxdb_hosts: list of influxdb host tuple, like (ip_address, ip_port)
            influxdb_user: influxdb user 
            influxdb_passwd: influxdb password
            influxdb_database: influxdb database

        Description:
            If the function is compiled with docker, 
            Then we can set the influxdb address as SERVICE/PORT in Kubernetes
        """
       
        if len(influxdb_hosts) == 1:
            try:
                self.__connection__ = InfluxDBClient(influxdb_hosts[0][0], influxdb_hosts[0][1], influxdb_user, influxdb_passwd, influxdb_database)
            except:
                self.__status__ = 1
        else:
            try:
                self.__connection__ = InfluxDBClusterClient(influxdb_hosts, influxdb_user, influxdb_passwd, influxdb_database)
            except:
                self.__status__ = 1

    def show_tables(self):
        """ Influxdb SQL name table as measurement.
            
        Show tables would be necessary
        """

        return self.show_measurements();

    def show_measurements(self):
        """ The same functions as show_tables
        """ 

        sql_string = 'SHOW MEASUREMENTS'
        return self.query(sql_string)

    def list_series(self, json_str=True):
        """ Show the database series

        Args:
            json_str: the switch whether to open it with JSON
        """

        if json_str == True:
            return json.dumps(self.__connection__.get_list_series(database))

    def show_tag_keys(self, measurements='cpu/node_reservation'):
        """ Show the measurements tag keys

        Args:
            measurements: the target measurements
        """

        sql_string = "SHOW TAG KEYS FROM \"" + measurements + "\""
        return self.query(sql_string)

    def show_field_keys(self, measurements='cpu/node_reservation'):
        """ Show the measurements field

        Args:
            measurements: the target measurements
        """

        sql_string = "SHOW FIELD KEYS FROM \"" + measurements + "\""
        return self.query(sql_string)

    def last_records(self, measurements='cpu/usage'):
        """ Get the lastest record 

        Args:
            measurements: the target measurements
        """ 

        sql_string = "SELECT * FROM \"" + measurements + "\" WHERE time > now() - 1h ORDER BY time DESC LIMIT 20 "
        return self.query(sql_string)

    def period_records(self, measurements='cpu/usage_rate', group_by='nodename', time_durations='1h'):
        """ Show the node cpu usage

        Args:
            measurements: the target measurements
            group_by: the group by object
            time_duration: time duration from now
        """

#.........这里部分代码省略.........
开发者ID:rainlight,项目名称:ansible.conf,代码行数:103,代码来源:influxdb_api.py


注:本文中的influxdb.InfluxDBClusterClient.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。