Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.update_query(config)
self.do_query(config['query'], raw)
self.copy(raw, os.path.join(config['metric'], raw))
consumer_error = False
for consumer in [self.jq_upload, self.influx_upload]:
try:
consumer(config, raw)
except (
ValueError,
KeyError,
IOError,
requests.exceptions.ConnectionError,
influxdb.client.InfluxDBClientError,
influxdb.client.InfluxDBServerError,
):
print(traceback.format_exc(), file=sys.stderr)
consumer_error = True
if consumer_error:
raise ValueError('Error(s) were thrown by query result consumers.')
#!/usr/bin/env python
import sys
from influxdb import client as influxdb
username = sys.argv[1]
password = sys.argv[2]
hostname = sys.argv[3]
db = influxdb.InfluxDBClient(hostname, 8086, username, password, 'mon')
hosts = set()
hosts_amplified = {}
total_metrics = 0
metrics_missing_hostname = 0
for series in db.query('list series;')[0]["points"]:
total_metrics += 1
entries = [entry for entry in series[1].split('&')]
series_items = {entry.split('=')[0]: entry.split('=')[1] for entry in entries if entry.find('=') != -1}
if series_items.has_key('hostname'):
hosts.add(series_items['hostname'])
else:
metrics_missing_hostname += 1
if series_items.has_key('amplifier'): # I assume if it has a amplifier it has a hostname also
def __init__(self, db_info=None, db_name=None):
self.db_info = db_info or self.DEFAULT_DB_INFO
self.db_name = db_name or self.DEFAULT_DB_NAME
self.db = influxdb.InfluxDBClient(
host=self.db_info['host'],
port=self.db_info['port'],
username=self.db_info['username'],
password=self.db_info['password']
)
if self.db_name not in self.list_databases():
self.create_database(self.db_name)
self.switch_database(self.db_name)
print('Using InfluxDB datastore with db name {}'.format(self.db_name))
def get_influx_client(self):
self.influx_connection = client.InfluxDBClient(host=self.server, database=self.db_name)
def get_db():
"""Returns an ``InfluxDBClient`` instance."""
return client.InfluxDBClient(
settings.INFLUXDB_HOST,
settings.INFLUXDB_PORT,
settings.INFLUXDB_USER,
settings.INFLUXDB_PASSWORD,
settings.INFLUXDB_DATABASE,
)