Esempio n. 1
0
    def _connect(self):
        """
        Connect to the influxdb server
        """

        try:
            # Open Connection
            if influxdb.__version__ > "0.1.6":
                self.influx = InfluxDBClient(self.hostname, self.port,
                                             self.username, self.password,
                                             self.database, self.ssl)
            else:
                self.influx = InfluxDBClient(self.hostname, self.port,
                                             self.username, self.password,
                                             self.database)

            # Log
            self.log.debug("InfluxdbHandler: Established connection to "
                           "%s:%d/%s.",
                           self.hostname, self.port, self.database)
        except Exception, ex:
            # Log Error
            self._throttle_error("InfluxdbHandler: Failed to connect to "
                                 "%s:%d/%s. %s",
                                 self.hostname, self.port, self.database, ex)
            # Close Socket
            self._close()
            return
Esempio n. 2
0
    def __init__(self, settings=None, database=None):

        settings = deepcopy(settings) or {}
        settings.setdefault('host', u'localhost')
        settings.setdefault('port', u'8086')
        settings.setdefault('username', u'root')
        settings.setdefault('password', u'root')
        settings.setdefault('database', database)
        settings.setdefault('pool_size', 10)

        settings.setdefault('use_udp', False)
        settings.setdefault('udp_port', u'4444')

        settings['port'] = int(settings['port'])
        settings['udp_port'] = int(settings['udp_port'])

        self.__dict__.update(**settings)

        # Bookeeping for all databases having been touched already
        self.databases_written_once = Set()

        # Knowledge about all databases to be accessed using UDP
        # TODO: Refactor to configuration setting
        self.udp_databases = [
            {
                'name': 'luftdaten_info',
                'port': u'4445'
            },
        ]
        self.host_uri = u'influxdb://{host}:{port}'.format(**self.__dict__)

        log.info(u'Storage target is {uri}, pool size is {pool_size}',
                 uri=self.host_uri,
                 pool_size=self.pool_size)
        self.influx_client = InfluxDBClient(host=self.host,
                                            port=self.port,
                                            username=self.username,
                                            password=self.password,
                                            database=self.database,
                                            pool_size=self.pool_size,
                                            timeout=10)

        # TODO: Hold references to multiple UDP databases using mapping "self.udp_databases".
        self.influx_client_udp = None
        if settings['use_udp']:
            self.influx_client_udp = InfluxDBClient(
                host=self.host,
                port=self.port,
                username=self.username,
                password=self.password,
                use_udp=settings['use_udp'],
                udp_port=settings['udp_port'],
                timeout=10)
Esempio n. 3
0
def _setup_gzip_client(inst):
    inst.cli = InfluxDBClient('localhost',
                              inst.influxd_inst.http_port,
                              'root',
                              '',
                              database='db',
                              gzip=True)
Esempio n. 4
0
def create_client() -> InfluxDBClient:
    """
    Create a client for the Influx database.
    Includes connection test and database and retention policy creation.

    :return: an instance of InfluxDBClient.
    """
    client = InfluxDBClient(host=INFLUXDB_HOST,
                            port=INFLUXDB_PORT,
                            username=INFLUXDB_USERNAME,
                            password=INFLUXDB_PASSWORD,
                            database=INFLUXDB_DATABASE)

    # Test connection
    try:
        client.ping()
    except requests.exceptions.ConnectionError:
        _logger.error('Connection to InfluxDB was refused!')
        exit(code=1)  # TODO replace with backoff retry

    # Create database (will pass if already exists)
    client.create_database(INFLUXDB_DATABASE)

    # Set retention policy on database
    client.create_retention_policy(name=RETENTION_NAME,
                                   duration=RETENTION_DURATION,
                                   replication=RETENTION_REPLICATION,
                                   database=INFLUXDB_DATABASE,
                                   default=True)

    _logger.info("InfluxDB client created successfully")

    return client
Esempio n. 5
0
    def __init__(self, settings=None, database=None):

        settings = deepcopy(settings) or {}
        settings.setdefault('host', u'localhost')
        settings.setdefault('port', u'8086')
        settings.setdefault('version', u'0.9')
        settings.setdefault('username', u'root')
        settings.setdefault('password', u'root')
        settings.setdefault('database', database)

        settings.setdefault('use_udp', False)
        settings.setdefault('udp_port', u'4444')

        settings['port'] = int(settings['port'])
        settings['udp_port'] = int(settings['udp_port'])

        self.__dict__.update(**settings)

        self.databases_written_once = Set()
        self.udp_databases = [
            {
                'name': 'luftdaten_testdrive',
                'port': u'4445'
            },
        ]
        self.host_uri = u'influxdb://{host}:{port}'.format(**self.__dict__)

        log.info(u'Storage target is {uri}', uri=self.host_uri)
        self.influx_client = InfluxDBClient(host=self.host,
                                            port=self.port,
                                            username=self.username,
                                            password=self.password,
                                            database=self.database,
                                            timeout=10)

        # TODO: Hold references to multiple UDP databases using mapping "self.udp_databases".
        self.influx_client_udp = None
        if settings['use_udp']:
            self.influx_client_udp = InfluxDBClient(
                host=self.host,
                port=self.port,
                username=self.username,
                password=self.password,
                use_udp=settings['use_udp'],
                udp_port=settings['udp_port'],
                timeout=10)
Esempio n. 6
0
def do_influx_request(n_points, host,
                      database):  # type: (int, str, str) -> float
    conn = InfluxDBClient(host=host)
    conn.switch_database('p2')
    points = generate_fake_data(n_points)
    request_start_time = time.time()
    conn.write_points(points, time_precision='u', database=database)
    return time.time() - request_start_time
Esempio n. 7
0
 def __init__(self, context, options):
     super().__init__(context, options)
     self._influxdb = InfluxDBClient(
         host=self.options.host,
         port=self.options.port,
         username=self.options.username,
         password=self.options.password,
         database=self.options.database,
     )
Esempio n. 8
0
def get_client(name: str = "default") -> InfluxDBClient:
    if name not in _clients:
        if not getattr(settings, "INFLUX_DATABASES", None):
            raise ImproperlyConfigured("INFLUX_DATABASES is not configured.")

        if name not in settings.INFLUX_DATABASES:
            raise ValueError("Unknown database: {}".format(name))

        _clients[name] = InfluxDBClient(**settings.INFLUX_DATABASES[name])

    return _clients[name]
def getDataFromDb(slurm_start, slurm_end, user, database):
    """ Connecting to Influx database """
    start_date = encodeTime(slurm_start)
    end_date = encodeTime(slurm_end)

    client = InfluxDBClient(config.db_host, config.db_port, config.db_user,
                            config.db_pass)

    qry_str = 'SELECT "value", "jobid" FROM ' + database + ' WHERE time > \'' + start_date + '\' AND time < \'' + end_date + '\' AND "user"=\'' + user + '\''
    qry_res = client.query(qry_str)

    return qry_res
Esempio n. 10
0
    def configure(self, options, noseconfig):
        """ Call the super and then validate and call the relevant parser for
        the configuration file passed in """
        super(Grafana, self).configure(options, noseconfig)

        self.context = ContextHelper()
        cfgifc = self.context.get_config()
        self.duts = options.get(
            'duts',
            cfgifc.config.get('plugins', {}).get('_default_', {}))
        self.first_time = True
        o = options.influxdb
        if o:
            self.client = InfluxDBClient(o.host, o.port, o.user, o.password,
                                         o.db)
Esempio n. 11
0
def _setup_influxdb_server(inst):
    inst.influxd_inst = InfluxDbInstance(
        inst.influxdb_template_conf,
        udp_enabled=getattr(inst, 'influxdb_udp_enabled', False),
    )

    inst.cli = InfluxDBClient('localhost',
                              inst.influxd_inst.http_port,
                              'root',
                              '',
                              database='db')
    if not using_pypy:
        inst.cliDF = DataFrameClient('localhost',
                                     inst.influxd_inst.http_port,
                                     'root',
                                     '',
                                     database='db')
Esempio n. 12
0
    def init(self, **params):
        self.influx_client = InfluxDBClient(**params)

        supermann.utils.getLogger(self).info(
            "Using InfluxOutput with params %s", str(params))
from config import *

influx_reader = DataFrameClient(
    host="192.168.0.4",
    port=INFLUXDB_PORT,
    username=INFLUXDB_USER,
    password=INFLUXDB_PASS,
    database="rtlamr",
)

# set to test mode. when ready, change to actual destination
# and uncomment influx_writer.write line below
influx_writer = InfluxDBClient(
    host="192.168.0.4",
    port=INFLUXDB_PORT,
    username=INFLUXDB_USER,
    password=INFLUXDB_PASS,
    database="rtlamr_test",
)


def copy_meters_data(meters, format_type, start_time, end_time):
    """copy data for given meters from secondary to primary

    Args:
        meters (list[int]): list of meter ids
        format_type (str): lineformat type to use - must be 'SCM' or 'R900'
        start_time (datetime): start time of data window to copy
        end_time (datetime): end time of data window to copy
    """
Esempio n. 14
0
try:
    from urllib.parse import parse_qs
except ImportError:
    from urlparse import parse_qs


# build the response gif
gif = base64.b64decode("R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==")

# init influxdb client
host = os.environ.get("INFLUXER_INFLUXDB_HOST_IP", "localhost")
port = os.environ.get("INFLUXER_INFLUXDB_PORT", 8086)
user = os.environ.get("INFLUXER_INFLUXDB_USERNAME", "root")
pwd = os.environ.get("INFLUXER_INFLUXDB_PASSWORD", "root")
db = os.environ.get("INFLUXER_INFLUXDB_DB", "influxdb")
influx_client = InfluxDBClient(host, port, user, pwd, db)

# init the gevent queue
events_queue = queue.Queue()
flush_interval = os.environ.get("INFLUXER_FLUSH_INTERVAL", 60)  # seconds

# acceptable site names
site_names = ("onion", "avclub", "clickhole", "onionstudios", "onionads", )

# init the logger
logger = logging.getLogger('influxer')
logger.setLevel(logging.INFO)


# main wait loop
def count_events():
Esempio n. 15
0
 def __init__(self):
     load_dotenv()
     user=os.getenv("INFLUX_DB_USER")
     password=os.getenv("INFLUX_DB_PASSWORD")
     self.client = InfluxDBClient('localhost', 8086, user, password, 'pi_influxdb')
Esempio n. 16
0
hbdata = SingleFigure("heartbeats")
hbshift = None
for row in hbfile:
    if (row[0] != "time"):
        if (hbshift == None):
            hbshift = long(row[0][:-6])
        if (len(hbdata.x) > 0):
            hbdata.add(
                float(long(row[0][:-6]) - hbshift) / 1000.,
                hbdata.y[len(hbdata.y) - 1])
        hbdata.add(float(long(row[0][:-6]) - hbshift) / 1000., int(0))
        hbdata.add(float(long(row[0][:-6]) - hbshift) / 1000., int(row[1]))

# grab the data from influxdb
influxclient = InfluxDBClient(host=influxhost,
                              port=influxport,
                              database=influxdb)
groupings = {"other.other": []}
for iserie in influxclient.get_list_series(influxdb):
    for ilist in iserie["tags"]:
        if (not ilist["key"].startswith("cpu.trace")):
            tags = split(split(ilist["key"], sep=",")[0], sep=".")
            if (len(tags) >= 2):
                if (tags[0] + "." + tags[1]) in groupings:
                    groupings[tags[0] + "." + tags[1]].append(ilist["key"])
                else:
                    groupings[tags[0] + "." + tags[1]] = [ilist["key"]]
            else:
                groupings["other.other"].append(ilist["key"])
for igroupname in groupings:
    figs = []