本文整理匯總了Python中influxdb.InfluxDBClient方法的典型用法代碼示例。如果您正苦於以下問題:Python influxdb.InfluxDBClient方法的具體用法?Python influxdb.InfluxDBClient怎麽用?Python influxdb.InfluxDBClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類influxdb
的用法示例。
在下文中一共展示了influxdb.InfluxDBClient方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def __init__(
self,
host='localhost',
port=8086,
user='root',
password='root',
dbname='example',
dbuser='test',
dbuser_pw='test'):
self.host = host
self.port = port
self.user = user
self.password = password
self.dbname = dbname
self.dbuser = dbuser
self.dbuser_pw = dbuser_pw
self.client = InfluxDBClient(host, port, user, password, dbname)
self.client.create_database(dbname)
示例2: connect
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def connect(self, silent=False):
try:
client = influxdb.InfluxDBClient(self.settings.influxdb['host'],
self.settings.influxdb['port'],
self.settings.influxdb['user'],
self.settings.influxdb['password']
)
# dummy request to test connection
client.get_list_database()
except influxdb.client.InfluxDBClientError as e:
self.client, self.valid = None, False
if not silent:
print(" {0} Could not connect to database: {1}".format(Symbol.WARN_YELLOW, e))
except Exception as e:
print("Error: %s" % e)
self.client, self.valid = None, False
else:
self.client, self.valid = client, True
if self.settings.influxdb['database']:
self.client.switch_database(self.settings.influxdb['database'])
return self.valid
示例3: test_multi_fetch_non_existant_series
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def test_multi_fetch_non_existant_series(self):
"""Test single fetch data for a series by name"""
path1, path2 = 'fake_path1', 'fake_path2'
reader1 = influxgraph.InfluxDBReader(InfluxDBClient(
database=self.db_name), path1)
reader2 = influxgraph.InfluxDBReader(InfluxDBClient(
database=self.db_name), path2)
nodes = [influxgraph.classes.leaf.InfluxDBLeafNode(path1, reader1),
influxgraph.classes.leaf.InfluxDBLeafNode(path2, reader2)]
time_info, data = self.finder.fetch_multi(nodes,
int(self.start_time.strftime("%s")),
int(self.end_time.strftime("%s")))
for metric_name in data:
self.assertFalse(data[metric_name],
msg="Expected no data for non-existant series %s - got %s" % (
metric_name, data,))
fake_nodes = list(self.finder.find_nodes(Query('fake_pathy_path')))
time_info, data = self.finder.fetch_multi(fake_nodes,
int(self.start_time.strftime("%s")),
int(self.end_time.strftime("%s")))
self.assertFalse(data)
示例4: __init__
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def __init__(self, config=None):
# Shouldn't be trying imports in __init__.
# It turns what should be a load error into a runtime error
config = normalize_config(config)
self.config = config
self.client = InfluxDBClient(config['host'], config['port'], config['user'], config['passw'], config['db'], config['ssl'])
self.schemas = [(re.compile(patt), step) for (patt, step) in config['schema']]
try:
self.statsd_client = statsd.StatsClient(config['statsd'].get('host'),
config['statsd'].get('port', 8125)) \
if 'statsd' in config and config['statsd'].get('host') else NullStatsd()
except NameError:
logger.warning("Statsd client configuration present but 'statsd' module"
"not installed - ignoring statsd configuration..")
self.statsd_client = NullStatsd()
self._setup_logger(config['log_level'], config['log_file'])
self.es = None
if config['es_enabled']:
try:
from elasticsearch import Elasticsearch
except ImportError:
logger.warning("Elasticsearch configuration present but 'elasticsearch'"
"module not installed - ignoring elasticsearch configuration..")
else:
self.es = Elasticsearch(config['es_hosts'])
示例5: setUp
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def setUp(self):
self.step, self.num_datapoints, self.db_name = 60, 2, 'integration_test'
self.start_time, self.end_time = (datetime.datetime.utcnow() - datetime.timedelta(hours=1)), \
datetime.datetime.utcnow()
self.steps = int(round((int(self.end_time.strftime("%s")) - \
int(self.start_time.strftime("%s"))) * 1.0 / self.step)) + 1
self.client = InfluxDBClient(database=self.db_name)
self.config = { 'influxdb' : { 'host' : 'localhost',
'port' : 8086,
'user' : 'root',
'pass' : 'root',
'db' : self.db_name,
'schema' : [('', 60)],
'log_level' : 'debug',
},}
self.finder = graphite_influxdb.InfluxdbFinder(self.config)
self.metric_prefix = "integration_test"
self.nodes = ["leaf_node1", "leaf_node2"]
self.series1, self.series2 = ".".join([self.metric_prefix, self.nodes[0]]), \
".".join([self.metric_prefix, self.nodes[1]])
self.series = [self.series1, self.series2]
self.setup_db()
示例6: __init__
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def __init__(self, query, host="127.0.0.1", port=8086, database="thingflow",
username="root", password="root",
ssl=False, verify_ssl=False, timeout=None,
use_udp=False, udp_port=4444, proxies=None,
bulk_size=10):
super().__init__()
self.dbname = database
self.client = InfluxDBClient(host=host, port=port,
username=username, password=password,
database=database,
ssl=ssl, verify_ssl=verify_ssl,
timeout=timeout,
use_udp=use_udp, udp_port=udp_port,
proxies=proxies)
self.query = query
self.points = self.client.query(query).get_points()
示例7: get_influxdb_client
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def get_influxdb_client(self):
influx_args = {}
if not self._influxdb_config:
return None
use_udp = bool(self._influxdb_config.get('use_udp', False))
port = self._influxdb_config.get('port')
if use_udp:
influx_args['use_udp'] = True
if 'port' in self._influxdb_config:
if use_udp:
influx_args['udp_port'] = port
else:
influx_args['port'] = port
for key in ['host', 'username', 'password', 'database', 'timeout']:
if key in self._influxdb_config:
influx_args[key] = self._influxdb_config[key]
if influxdb and influx_args:
try:
return influxdb.InfluxDBClient(**influx_args)
except Exception:
self.log.warning('Cannot establish connection to InfluxDB')
else:
self.log.warning('InfluxDB configuration is present, '
'but no client library is found.')
return None
示例8: init_influx
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def init_influx():
""" Initializes influx database. """
from listenbrainz import config
print("Connecting to Influx...")
influx_client = InfluxDBClient(
host=config.INFLUX_HOST,
port=config.INFLUX_PORT,
database=config.INFLUX_DB_NAME,
)
print("Connected to Influx!")
print("Creating influx database...")
influx_client.create_database(config.INFLUX_DB_NAME)
influx_client.create_retention_policy("one_week", "1w", 1, "listenbrainz")
print("Done!")
# Add other commands here
示例9: connect
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def connect(self):
"""
Override from BaseDB.
Create the connection to the influxdb database with the current
configuration (hostname/port/db_name), then check if the connection has
been created without failure.
"""
# close connection if reload
if self.client is not None:
self.client.close()
self.client = InfluxDBClient(host=self.uri, port=self.port, database=self.db_name)
try:
self.client.ping()
except ConnectionError:
raise CantConnectToInfluxDBException('connexion error')
for db in self.client.get_list_database():
if db['name'] == self.db_name:
return
self.client.create_database(self.db_name)
示例10: connect
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def connect() -> influxdb.InfluxDBClient:
"""
Connect to InfluxDB using configuration parameters
:return: InfluxDBClient object
"""
return influxdb.InfluxDBClient(
host=current_app.config["INFLUXDB_HOST"],
port=current_app.config["INFLUXDB_PORT"],
username=current_app.config["INFLUXDB_USER"],
password=current_app.config["INFLUXDB_PASSWORD"],
database=current_app.config["INFLUXDB_DATABASE"],
ssl=current_app.config["INFLUXDB_SSL"],
verify_ssl=current_app.config["INFLUXDB_VERIFY_SSL"],
timeout=current_app.config["INFLUXDB_TIMEOUT"],
retries=current_app.config["INFLUXDB_RETRIES"],
use_udp=current_app.config["INFLUXDB_USE_UDP"],
udp_port=current_app.config["INFLUXDB_UDP_PORT"],
proxies=current_app.config["INFLUXDB_PROXIES"],
pool_size=current_app.config["INFLUXDB_POOL_SIZE"],
)
示例11: connection
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def connection(self) -> influxdb.InfluxDBClient:
"""
InfluxDBClient object
:return:
"""
ctx = _app_ctx_stack.top
if ctx is None:
raise RuntimeError(_app_ctx_err_msg)
if not hasattr(ctx, "influxdb_db"):
ctx.influxdb_db = self.connect()
if ctx.influxdb_db is None:
raise RuntimeError(_no_influx_msg)
return ctx.influxdb_db
示例12: _get_influx_client
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def _get_influx_client():
verify = CONF.storage_influxdb.use_ssl and not \
CONF.storage_influxdb.insecure
if verify and CONF.storage_influxdb.cafile:
verify = CONF.storage_influxdb.cafile
return influxdb.InfluxDBClient(
username=CONF.storage_influxdb.username,
password=CONF.storage_influxdb.password,
host=CONF.storage_influxdb.host,
port=CONF.storage_influxdb.port,
database=CONF.storage_influxdb.database,
ssl=CONF.storage_influxdb.use_ssl,
verify_ssl=verify,
)
示例13: ship_points
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def ship_points(self, points):
"""Make a connection to InfluxDB and ship points."""
if self.conf is not None:
try:
client = InfluxDBClient(
host=self.conf.influx_host,
port=self.conf.influx_port,
username=self.conf.influx_user,
password=self.conf.influx_pwd,
database=self.conf.influx_db,
timeout=self.conf.influx_timeout)
if client:
if client.write_points(points=points, time_precision='s'):
return True
self.logger.warning(
'%s failed to update InfluxDB' % self.ship_error_prefix)
else:
self.logger.warning(
'%s error connecting to InfluxDB' % self.ship_error_prefix)
except (requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout,
InfluxDBClientError, InfluxDBServerError) as err:
self.logger.warning('%s %s' % (self.ship_error_prefix, err))
return False
示例14: connect_db
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def connect_db():
'''
Connects to Infludb.
'''
# returning InfluxDBClient object.
try:
conn = InfluxDBClient(var.db_host,
var.db_port,
var.db_user,
var.db_password,
var.db_name)
except Exception as err:
log("[ERROR] " + str(err), 0)
sys.exit(1)
return conn
示例15: ship_points_to_influxdb
# 需要導入模塊: import influxdb [as 別名]
# 或者: from influxdb import InfluxDBClient [as 別名]
def ship_points_to_influxdb(points):
client = InfluxDBClient(
host=INFLUXDB_HOST, port=INFLUXDB_PORT,
username=INFLUXDB_USER, password=INFLUXDB_PASS,
database=INFLUXDB_DB, timeout=10)
return client.write_points(points=points, time_precision='s')