本文整理汇总了Python中influxdb.exceptions.InfluxDBServerError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.InfluxDBServerError方法的具体用法?Python exceptions.InfluxDBServerError怎么用?Python exceptions.InfluxDBServerError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类influxdb.exceptions
的用法示例。
在下文中一共展示了exceptions.InfluxDBServerError方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_metrics
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def send_metrics(self, metrics):
if not self.enable_metrics:
return
now = str(datetime.now())
payload = []
for metric, value in metrics.items():
data = {
'measurement': self.appname,
'tags': {},
'time': now,
'fields': {
metric: value
}
}
if self.extra_tags:
data['tags'].update(self.extra_tags)
payload.append(data)
try:
self.client.write_points(payload)
except (RequestException, InfluxDBClientError, InfluxDBServerError):
logger.exception('Failed to send metrics to influxdb')
示例2: ship_points
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [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
示例3: init_database
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def init_database(self):
"""
Initialize the InfluxDB database if it is not already there
"""
try:
logging.info("Creating InfluxDB database if not exists: %s",
self.config.influxdb_dbname)
self.writer.create_database(self.config.influxdb_dbname)
except ConnectionError as error:
logging.error(
"Connection error while trying to create InfluxDB database: %s. Waiting for retry...", error)
time.sleep(self.db_create_delay)
self.init_database()
except (InfluxDBServerError, InfluxDBClientError) as error:
logging.warning(
"Could not create InfluxDB database. Assuming it already exists: %s", error)
示例4: flush
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def flush(self):
"""
Flush values with writer
"""
if not self.buffer:
# Don't do anything when buffer empty
return
try:
self.last_flush_time = time.time()
self.writer.write(self.buffer)
if self.config.statistics:
self.show_statistics()
except (InfluxDBServerError, InfluxDBClientError) as influx_error:
logging.error("Error while writing to InfluxDB: %s", influx_error)
finally:
self.buffer = []
示例5: write_points
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def write_points(self, data):
d = data
self.logger.debug('Writing Data to InfluxDB %s', d)
try:
self.influx.write_points(d)
except (InfluxDBServerError, ConnectionError) as e:
self.logger.error('Error writing data to influxdb. Dropping this set of data. '
'Check your database! Error: %s', e)
示例6: _write_points
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def _write_points(points, num_points):
"""
Write the points to the InfluxDB in groups that are MAX_POINTS_PER_WRITE in
size.
"""
LOG.debug("Writing points %d", num_points)
write_index = 0
points_written = 0
while write_index < num_points:
max_write_index = write_index + MAX_POINTS_PER_WRITE
write_points = points[write_index:max_write_index]
try:
g_client.write_points(write_points)
points_written += len(write_points)
except InfluxDBServerError as svr_exc:
LOG.error(
"InfluxDBServerError: %s\nFailed to write points: %s",
str(svr_exc),
_get_point_names(write_points),
)
except InfluxDBClientError as client_exc:
LOG.error(
"InfluxDBClientError writing points: %s\n" "Error: %s",
_get_point_names(write_points),
str(client_exc),
)
except requests.exceptions.ConnectionError as req_exc:
LOG.error(
"ConnectionError exception caught writing points: %s\n" "Error: %s",
_get_point_names(write_points),
str(req_exc),
)
write_index += MAX_POINTS_PER_WRITE
return points_written
示例7: v2_playbook_on_stats
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def v2_playbook_on_stats(self, stats):
"""Connect to InfluxDB and commit events"""
# Get external tags if any
enos_tags = self.vm.get_vars().get('enos_tags', '')
fields = {
'tags': 'playbook {} {}'.format(
self.playbook_name, enos_tags),
'text': 'playbook finished',
'type': 'playbook',
'title': self.playbook_name
}
self.report_event(fields)
# Set InfluxDB host from an environment variable if provided
_host = os.getenv('INFLUX_VIP') or self.vm.get_vars().get('influx_vip')
if not _host:
return
_port = "8086"
_user = "None"
_pass = "None"
_dbname = "events"
influxdb = InfluxDBClient(_host, _port, _user, _pass, _dbname)
try:
version = influxdb.ping()
except (InfluxDBServerError,
exceptions.HTTPError,
exceptions.ConnectionError,
exceptions.Timeout,
exceptions.RequestException) as error:
return
try:
influxdb.write_points(self.events, time_precision='u')
except Exception:
# Disable the plugin if writes fail
self.disabled = True
self._display.warning(
"Cannot write to InfluxDB, check the service state "
"on %s." % _host)
return
示例8: get_listen_count_for_user
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def get_listen_count_for_user(self, user_name, need_exact=False):
"""Get the total number of listens for a user. The number of listens comes from
brainzutils cache unless an exact number is asked for.
Args:
user_name: the user to get listens for
need_exact: if True, get an exact number of listens directly from the ListenStore
"""
if not need_exact:
# check if the user's listen count is already in cache
# if already present return it directly instead of calculating it again
# decode is set to False as we have not encoded the value when we set it
# in brainzutils cache as we need to call increment operation which requires
# an integer value
user_key = '{}{}'.format(REDIS_INFLUX_USER_LISTEN_COUNT, user_name)
count = cache.get(user_key, decode=False)
if count:
return int(count)
try:
results = self.influx.query('SELECT count(*) FROM ' + get_escaped_measurement_name(user_name))
except (InfluxDBServerError, InfluxDBClientError) as e:
self.log.error("Cannot query influx: %s" % str(e), exc_info=True)
raise
# get the number of listens from the json
try:
count = results.get_points(measurement = get_measurement_name(user_name)).__next__()['count_recording_msid']
except (KeyError, StopIteration):
count = 0
# put this value into brainzutils cache with an expiry time
user_key = "{}{}".format(REDIS_INFLUX_USER_LISTEN_COUNT, user_name)
cache.set(user_key, int(count), InfluxListenStore.USER_LISTEN_COUNT_CACHE_TIME, encode=False)
return int(count)
示例9: delete
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def delete(self, musicbrainz_id):
""" Delete all listens for user with specified MusicBrainz ID.
Note: this method tries to delete the user 5 times before giving up.
Args:
musicbrainz_id (str): the MusicBrainz ID of the user
Raises: Exception if unable to delete the user in 5 retries
"""
for _ in range(5):
try:
self.influx.drop_measurement(get_measurement_name(musicbrainz_id))
break
except InfluxDBClientError as e:
# influxdb-python raises client error if measurement isn't found
# so we have to handle that case.
if 'measurement not found' in e.content:
return
else:
self.log.error('Error in influx client while dropping user %s: %s', musicbrainz_id, str(e), exc_info=True)
time.sleep(3)
except InfluxDBServerError as e:
self.log.error('Error in influx server while dropping user %s: %s', musicbrainz_id, str(e), exc_info=True)
time.sleep(3)
except Exception as e:
self.log.error('Error while trying to drop user %s: %s', musicbrainz_id, str(e), exc_info=True)
time.sleep(3)
else:
raise InfluxListenStoreException("Couldn't delete user with MusicBrainz ID: %s" % musicbrainz_id)
示例10: query
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def query(self, query):
while True:
try:
return self.influx.query(query)
except InfluxDBClientError as e:
self.log.error("Client error while querying influx: %s", str(e), exc_info=True)
time.sleep(1)
except InfluxDBServerError as e:
self.log.error("Server error while querying influx: %s", str(e), exc_info=True)
time.sleep(1)
except Exception as e:
self.log.error("Error while querying influx: %s", str(e), exc_info=True)
time.sleep(1)
示例11: demo_user_replay
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def demo_user_replay(user_name):
replayer = DemoUserReplayer(user_name)
try:
replayer.start()
except (InfluxDBClientError, InfluxDBServerError) as e:
replayer.app.logger.error("Influx error while replaying listens: %s", str(e), exc_info=True)
raise
except Exception as e:
replayer.app.logger.error("Error while replaying listens: %s", str(e), exc_info=True)
raise
示例12: import_dump
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def import_dump(private_archive, public_archive, listen_archive, threads):
""" Import a ListenBrainz dump into the database.
Note: This method tries to import the private db dump first, followed by the public db
dump. However, in absence of a private dump, it imports sanitized versions of the
user table in the public dump in order to satisfy foreign key constraints.
Then it imports the listen dump.
Args:
private_archive (str): the path to the ListenBrainz private dump to be imported
public_archive (str): the path to the ListenBrainz public dump to be imported
listen_archive (str): the path to the ListenBrainz listen dump archive to be imported
threads (int): the number of threads to use during decompression, defaults to 1
"""
if not private_archive and not public_archive and not listen_archive:
print('You need to enter a path to the archive(s) to import!')
sys.exit(1)
app = create_app()
with app.app_context():
db_dump.import_postgres_dump(private_archive, public_archive, threads)
from listenbrainz.webserver.influx_connection import _influx as ls
try:
ls.import_listens_dump(listen_archive, threads)
except IOError as e:
current_app.logger.critical('IOError while trying to import data into Influx: %s', str(e), exc_info=True)
raise
except InfluxDBClientError as e:
current_app.logger.critical('Error while sending data to Influx: %s', str(e), exc_info=True)
raise
except InfluxDBServerError as e:
current_app.logger.critical('InfluxDB Server Error while importing data: %s', str(e), exc_info=True)
raise
except Exception as e:
current_app.logger.critical('Unexpected error while importing data: %s', str(e), exc_info=True)
raise
示例13: get_total_listen_count
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def get_total_listen_count(self, cache_value=True):
""" Returns the total number of listens stored in the ListenStore.
First checks the brainzutils cache for the value, if not present there
makes a query to the db and caches it in brainzutils cache.
"""
if cache_value:
count = cache.get(InfluxListenStore.REDIS_INFLUX_TOTAL_LISTEN_COUNT, decode=False)
if count:
return int(count)
try:
result = self.influx.query("""SELECT %s
FROM "%s"
ORDER BY time DESC
LIMIT 1""" % (COUNT_MEASUREMENT_NAME, TIMELINE_COUNT_MEASUREMENT))
except (InfluxDBServerError, InfluxDBClientError) as err:
self.log.error("Cannot query influx: %s" % str(err), exc_info=True)
raise
try:
item = result.get_points(measurement=TIMELINE_COUNT_MEASUREMENT).__next__()
count = int(item[COUNT_MEASUREMENT_NAME])
timestamp = convert_to_unix_timestamp(item['time'])
except (KeyError, ValueError, StopIteration):
timestamp = 0
count = 0
# Now sum counts that have been added in the interval we're interested in
try:
result = self.influx.query("""SELECT sum(%s) as total
FROM "%s"
WHERE time > %s""" % (COUNT_MEASUREMENT_NAME, TEMP_COUNT_MEASUREMENT, get_influx_query_timestamp(timestamp)))
except (InfluxDBServerError, InfluxDBClientError) as err:
self.log.error("Cannot query influx: %s" % str(err), exc_info=True)
raise
try:
data = result.get_points(measurement=TEMP_COUNT_MEASUREMENT).__next__()
count += int(data['total'])
except StopIteration:
pass
if cache_value:
cache.set(
InfluxListenStore.REDIS_INFLUX_TOTAL_LISTEN_COUNT,
int(count),
InfluxListenStore.TOTAL_LISTEN_COUNT_CACHE_TIME,
encode=False,
)
return count
示例14: insert
# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBServerError [as 别名]
def insert(self, listens):
""" Insert a batch of listens.
"""
submit = []
user_names = {}
for listen in listens:
user_names[listen.user_name] = 1
submit.append(listen.to_influx(quote(listen.user_name)))
if not self.influx.write_points(submit, time_precision='s'):
self.log.error("Cannot write data to influx. (write_points returned False), data=%s", json.dumps(submit, indent=3))
# If we reach this point, we were able to write the listens to the InfluxListenStore.
# So update the listen counts of the users cached in brainzutils cache.
for data in submit:
user_key = "{}{}".format(REDIS_INFLUX_USER_LISTEN_COUNT, data['fields']['user_name'])
cached_count = cache.get(user_key, decode=False)
if cached_count:
cache.increment(user_key)
# Invalidate cached data for user
for user_name in user_names.keys():
cache.delete(REDIS_USER_TIMESTAMPS % user_name)
if len(listens):
# Enter a measurement to count items inserted
submit = [{
'measurement': TEMP_COUNT_MEASUREMENT,
'tags': {
COUNT_MEASUREMENT_NAME: len(listens)
},
'fields': {
COUNT_MEASUREMENT_NAME: len(listens)
}
}]
try:
if not self.influx.write_points(submit):
self.log.error("Cannot write listen cound to influx. (write_points returned False)")
except (InfluxDBServerError, InfluxDBClientError, ValueError) as err:
self.log.error("Cannot write data to influx: %s, data: %s", str(err), json.dumps(submit, indent=3), exc_info=True)
raise