How to use the influxdb.client.InfluxDBClientError function in influxdb

To help you get started, we’ve selected a few influxdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kubernetes / test-infra / metrics / bigquery.py View on Github external
raw = 'raw-%s.json' % time.strftime('%Y-%m-%d')

        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.')
github nicolargo / glances / glances / exports / glances_influxdb.py View on Github external
# Correct issue #1530
        if self.protocol is not None and (self.protocol.lower() == 'https'):
            ssl = True
        else:
            ssl = False

        try:
            db = InfluxDBClient(host=self.host,
                                port=self.port,
                                ssl=ssl,
                                verify_ssl=False,
                                username=self.user,
                                password=self.password,
                                database=self.db)
            get_all_db = [i['name'] for i in db.get_list_database()]
        except InfluxDBClientError as e:
            logger.critical("Cannot connect to InfluxDB database '%s' (%s)" % (self.db, e))
            sys.exit(2)

        if self.db in get_all_db:
            logger.info(
                "Stats will be exported to InfluxDB server: {}".format(db._baseurl))
        else:
            logger.critical("InfluxDB database '%s' did not exist. Please create it" % self.db)
            sys.exit(2)

        return db
github ansible / galaxy / galaxy / api / serializers / influx.py View on Github external
global influx_insert_buffer
        influx_insert_buffer.append(self.data)
        if len(influx_insert_buffer) >= settings.INFLUX_INSERT_BUFFER_COUNT:
            client = influxdb.InfluxDBClient(
                host=settings.INFLUX_DB_HOST,
                port=settings.INFLUX_DB_PORT,
                username=settings.INFLUX_DB_USERNAME,
                password=settings.INFLUX_DB_PASSWORD
            )

            client.switch_database(settings.INFLUX_DB_UI_EVENTS_DB_NAME)

            try:
                client.write_points(influx_insert_buffer)
            except influxdb.client.InfluxDBClientError:
                client.create_database(settings.INFLUX_DB_UI_EVENTS_DB_NAME)
                client.switch_database(settings.INFLUX_DB_UI_EVENTS_DB_NAME)
                client.write_points(influx_insert_buffer)

            influx_insert_buffer = []
            client.close()
github influxdata / influxdb-python / examples / tutorial_server_data.py View on Github external
"value": value,
            },
            "tags": {
                "hostName": hostName,
            },
        }
        series.append(pointValues)

    print(series)

    client = InfluxDBClient(host, port, USER, PASSWORD, DBNAME)

    print("Create database: " + DBNAME)
    try:
        client.create_database(DBNAME)
    except InfluxDBClientError:
        # Drop and create
        client.drop_database(DBNAME)
        client.create_database(DBNAME)

    print("Create a retention policy")
    retention_policy = 'server_data'
    client.create_retention_policy(retention_policy, '3d', 3, default=True)

    print("Write points #: {0}".format(total_records))
    client.write_points(series, retention_policy=retention_policy)

    time.sleep(2)

    query = "SELECT MEAN(value) FROM {} WHERE \
            time > now() - 10d GROUP BY time(500m)".format(metric)
    result = client.query(query, database=DBNAME)
github Hyperpilotio / be-controller / store.py View on Github external
def __init__(self):
        self.client = InfluxDBClient(
            "influxsrv.hyperpilot", 8086, "root", "root", "be_controller")
        try:
            self.client.create_database("be_controller")
        except InfluxDBClientError:
            pass #Ignore
github fraoustin / flask-monitor / flask_monitor / influxdb.py View on Github external
def action(self, event):
        try:
            data = self._data
            data[0]['tags'] = event.dict
            data[0]['fields'] = {"value": event.timing}
            self.db.write_points(data)
        except InfluxDBClientError as e:
            self.logger.critical("Error InfluxDB '%s'" % str(e))
        except Exception as e:
            self.logger.critical("Error Unknow on InfluxDB '%s'" % str(e))
github ninuxorg / nodeshot / nodeshot / core / metrics / views.py View on Github external
def metric_details(request, pk, format=None):
    """
    Get or write metric values
    """
    metric = get_object_or_404(Metric, pk=pk)
    # get
    if request.method == 'GET':
        try:
            results = metric.select(q=request.query_params.get('q', metric.query))
        except InfluxDBClientError as e:
            return Response({'detail': e.content}, status=e.code)
        return Response(list(results.get_points(metric.name)))
    # post
    else:
        if not request.data:
            return Response({'detail': 'expected values in POST data or JSON payload'},
                            status=400)
        data = request.data.copy()
        # try converting strings to floats when sending form-data
        if request.content_type != 'application/json':
            for key, value in data.items():
                try:
                    data[key] = float(value) if '.' in value else int(value)
                except ValueError:
                    pass
        # write
github voidfiles / incursion / incursion / query.py View on Github external
def get_result(q, conn=None, **kwargs):
    if not conn:
        conn = InfluxDBClient(**kwargs)
    try:
        result = conn.query(q.query())
    except InfluxDBClientError:
        raise

    return parse_influxdb_response(result)