当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.InfluxDBClientError方法代码示例

本文整理汇总了Python中influxdb.exceptions.InfluxDBClientError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.InfluxDBClientError方法的具体用法?Python exceptions.InfluxDBClientError怎么用?Python exceptions.InfluxDBClientError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在influxdb.exceptions的用法示例。


在下文中一共展示了exceptions.InfluxDBClientError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [as 别名]
def open(self):
       """
       Connect to InfluxDB cluster.
       """
       try:
           self.cc = InfluxDBClusterClient(hosts = self.hosts,
                               username=self.influxdb_user,
                               password=self.influxdb_passwd,
                               ssl=self.influxdb_ssl,
                               verify_ssl=self.influxdb_verify_ssl)

           self.is_connected = CONNECTED

       except InfluxDBClientError as e:
           logging.warning("Connection failed: %s" % e)
           return False

       return True 
开发者ID:descrepes,项目名称:grafana-telegraf-dashboard-generator,代码行数:20,代码来源:generator.py

示例2: write_dataframe_to_idb

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [as 别名]
def write_dataframe_to_idb(self, ticker):
        """Write Pandas Dataframe to InfluxDB database"""
        cachepath = self._cache
        cachefile = ('%s/%s-1M.csv.gz' % (cachepath, ticker))

        if not os.path.exists(cachefile):
            log.warn('Import file does not exist: %s' %
                     (cachefile))
            return

        df = pd.read_csv(cachefile, compression='infer', header=0,
                         infer_datetime_format=True)

        df['Datetime'] = pd.to_datetime(df['Date'] + ' ' + df['Time'])
        df = df.set_index('Datetime')
        df = df.drop(['Date', 'Time'], axis=1)

        try:
            self.dfdb.write_points(df, ticker)
        except InfluxDBClientError as err:
            log.error('Write to database failed: %s' % err) 
开发者ID:mementum,项目名称:backtrader,代码行数:23,代码来源:influxdb-import.py

示例3: send_metrics

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [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') 
开发者ID:linkedin,项目名称:iris,代码行数:24,代码来源:influx.py

示例4: _create_influxdb_writer

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [as 别名]
def _create_influxdb_writer(influxdb_client, tags):
    """ Returns function which writes to influxdb

    Parameters
    ----------
    influxdb_client:
    """

    def to_influxdf(data_list, retries=5, pause=5):
        logger = _logger()
        logger.debug(data_list)
        for i in range(retries):
            try:
                if influxdb_client.write_points(data_list, tags=tags):
                    logger.debug("Success")
                    break
                else:
                    sleep(pause)
            except InfluxDBClientError:
                logger.debug('Failed {} out of {}'.format(i, retries))
        else:
            logger.warning("Failed to write to Database")

    return to_influxdf 
开发者ID:msalvaris,项目名称:gpu_monitor,代码行数:26,代码来源:gpu_logger.py

示例5: init_database

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [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) 
开发者ID:mre,项目名称:kafka-influxdb,代码行数:18,代码来源:worker.py

示例6: flush

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [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 = [] 
开发者ID:mre,项目名称:kafka-influxdb,代码行数:18,代码来源:worker.py

示例7: initDb

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [as 别名]
def initDb(self, client):
        try:
            client.create_database(influx_config.influx_db)
        except InfluxDBClientError:
            return

    # We have to rewrite the packet structure since
    # for influxdb, the tags and fields in a packet must be in the form of:

    # packet = {
    #    tags : {
    #        tagname1: tagValue,
    #        tagname2: tagValue,
    #        .
    #        .
    #    },
    #    time: ..... ,
    #    fields : {
    #        ssid: ...,
    #        mac_addr_src:....,
    #        .
    #        .
    #        value: .....
    #    }
    # } 
开发者ID:probr,项目名称:probr-core,代码行数:27,代码来源:handlers.py

示例8: execute_influxdb

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [as 别名]
def execute_influxdb(self, query):
        """
        Execute an InfluxDB query for the corpus

        Parameters
        ----------
        query : str
            Query to run

        Returns
        -------
        :class:`influxdb.resultset.ResultSet`
            Results of the query
        """
        client = self.acoustic_client()
        try:
            result = client.query(query)
        except InfluxDBClientError:
            print('There was an issue with the following query:')
            print(query)
            raise
        return result 
开发者ID:MontrealCorpusTools,项目名称:PolyglotDB,代码行数:24,代码来源:audio.py

示例9: make_reset_measurement

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [as 别名]
def make_reset_measurement(self):

        @pytest.fixture(scope="function")
        def reset_measurement():
            logger.info('InfluxDB: Resetting database')
            # Clear out the database.
            influx = InfluxWrapper(database=self.database, measurement=self.measurement)
            influx.client.delete_series(self.database, measurement=self.measurement)
            #try:
            #except InfluxDBClientError as ex:
            #    if 'database not found: mqttkit_1_itest' not in ex.message:
            #        raise

        return reset_measurement 
开发者ID:daq-tools,项目名称:kotori,代码行数:16,代码来源:util.py

示例10: get_historical_minute_data

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [as 别名]
def get_historical_minute_data(self, ticker: str):
        """Request historical 5 minute data from DTN."""
        start = self._start
        stop = self._stop

        if len(stop) > 4:
            stop = stop[:4]

        if len(start) > 4:
            start = start[:4]

        for year in range(int(start), int(stop) + 1):
            beg_time = ('%s0101000000' % year)
            end_time = ('%s1231235959' % year)
            msg = "HIT,%s,60,%s,%s,,,,1,,,s\r\n" % (ticker,
                                                    beg_time,
                                                    end_time)
            try:
                data = iq.iq_query(message=msg)
                iq.add_data_to_df(data=data)
            except Exception as err:
                log.error('No data returned because %s', err)

        try:
            self.dfdb.write_points(self._ndf, ticker)
        except InfluxDBClientError as err:
            log.error('Write to database failed: %s' % err) 
开发者ID:mementum,项目名称:backtrader,代码行数:29,代码来源:iqfeed-to-influxdb.py

示例11: _write_points

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [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 
开发者ID:Isilon,项目名称:isilon_data_insights_connector,代码行数:37,代码来源:influxdb_plugin.py

示例12: get_listen_count_for_user

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [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) 
开发者ID:metabrainz,项目名称:listenbrainz-server,代码行数:38,代码来源:influx_listenstore.py

示例13: delete

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [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) 
开发者ID:metabrainz,项目名称:listenbrainz-server,代码行数:32,代码来源:influx_listenstore.py

示例14: query

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [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) 
开发者ID:metabrainz,项目名称:listenbrainz-server,代码行数:15,代码来源:influx_listenstore.py

示例15: demo_user_replay

# 需要导入模块: from influxdb import exceptions [as 别名]
# 或者: from influxdb.exceptions import InfluxDBClientError [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 
开发者ID:metabrainz,项目名称:listenbrainz-server,代码行数:12,代码来源:cli.py


注:本文中的influxdb.exceptions.InfluxDBClientError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。