當前位置: 首頁>>代碼示例>>Java>>正文


Java InfluxDBFactory類代碼示例

本文整理匯總了Java中org.influxdb.InfluxDBFactory的典型用法代碼示例。如果您正苦於以下問題:Java InfluxDBFactory類的具體用法?Java InfluxDBFactory怎麽用?Java InfluxDBFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


InfluxDBFactory類屬於org.influxdb包,在下文中一共展示了InfluxDBFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getConnection

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
public InfluxDB getConnection()
{
  Assert.notNull(getProperties(), "InfluxDBProperties are required");
  if (connection == null)
  {
    final Builder client = new OkHttpClient.Builder()
      .connectTimeout(properties.getConnectTimeout(), TimeUnit.SECONDS)
      .writeTimeout(properties.getWriteTimeout(), TimeUnit.SECONDS)
      .readTimeout(properties.getReadTimeout(), TimeUnit.SECONDS);
    connection = InfluxDBFactory
      .connect(properties.getUrl(), properties.getUsername(), properties.getPassword(), client);
    logger.debug("Using InfluxDB '{}' on '{}'", properties.getDatabase(), properties.getUrl());
    if (properties.isGzip())
    {
      logger.debug("Enabled gzip compression for HTTP requests");
      connection.enableGzip();
    }
  }
  return connection;
}
 
開發者ID:miwurster,項目名稱:spring-data-influxdb,代碼行數:21,代碼來源:InfluxDBConnectionFactory.java

示例2: main

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
public static void main(String[] args) {
    String dbName = "centos_test_db";

    InfluxDB influxDB = InfluxDBFactory.connect("http://192.168.0.71:18086", "influxdbUser", "influxdbPsw");

    // Flush every 2000 Points, at least every 100ms
    influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);

    for (int i = 0; i < 50; i++) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Point point2 = Point.measurement("disk")
                .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
                .addField("used", Math.random() * 80L)
                .addField("free", Math.random() * 30L)
                .build();
        influxDB.write(dbName, "autogen", point2);
    }

    System.out.println();
}
 
開發者ID:ogcs,項目名稱:Okra,代碼行數:25,代碼來源:InfluxLogger.java

示例3: insert

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
@Override
    public void insert() {
        InfluxDB influxDB = null;
        try {
            influxDB = InfluxDBFactory.connect(influxDBUrl);
            if (!influxDB.databaseExists(dbName)) {
                influxDB.createDatabase(dbName);
            }
            for (OffsetInfo offsetInfo : offsetInfoList) {
                String group = offsetInfo.getGroup();
                String topic = offsetInfo.getTopic();
                Long logSize = offsetInfo.getLogSize();
                Long offsets = offsetInfo.getCommittedOffset();
                Long lag = offsetInfo.getLag();
                Long timestamp = offsetInfo.getTimestamp();

                BatchPoints batchPoints = BatchPoints
                        .database(dbName)
                        .tag("group", group)
                        .tag("topic", topic)
                        .build();
                Point point = Point.measurement("offsetsConsumer")
                        .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
//                        .time(timestamp, TimeUnit.MILLISECONDS)
                        .addField("logSize", logSize)
                        .addField("offsets", offsets)
                        .addField("lag", lag)
                        .build();
                batchPoints.point(point);
                influxDB.write(batchPoints);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (influxDB != null) {
                influxDB.close();
            }
        }

    }
 
開發者ID:dubin555,項目名稱:Kafka-Insight,代碼行數:41,代碼來源:OffsetsInfluxDBDaoImpl.java

示例4: InfluxDBReporter

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
/**
 * Creates a new {@link AbstractPollingReporter} instance.
 **/
public InfluxDBReporter(MetricsRegistry metricsRegistry, String address, String database, String retentionPolicy, String username, String password, String consistency, String tags, Clock clock, VirtualMachineMetrics vm) {
    super(metricsRegistry, "influx-reporter");
    this.database = database;
    this.retentionPolicy = retentionPolicy;
    this.consistencyLevel = getConsistencyLevel(consistency);
    this.tags = formatTags(tags);
    this.influxDBclient = InfluxDBFactory.connect(address, username, password);
    this.clock = clock;
    this.vm = vm;
    this.context = new Context() {
        @Override
        public long getTime() {
            return InfluxDBReporter.this.clock.time();
        }
    };
}
 
開發者ID:jasper-zhang,項目名稱:kafka-influxdb,代碼行數:20,代碼來源:InfluxDBReporter.java

示例5: open

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
/**
 * Initializes the connection to InfluxDB by either cluster or sentinels or single server.
 */
@Override
public void open(Configuration parameters) throws Exception {
    super.open(parameters);

    influxDBClient = InfluxDBFactory.connect(influxDBConfig.getUrl(), influxDBConfig.getUsername(), influxDBConfig.getPassword());

    if (!influxDBClient.databaseExists(influxDBConfig.getDatabase())) {
        throw new RuntimeException("This " + influxDBConfig.getDatabase() + " database does not exist!");
    }

    influxDBClient.setDatabase(influxDBConfig.getDatabase());

    if (influxDBConfig.getBatchActions() > 0) {
        influxDBClient.enableBatch(influxDBConfig.getBatchActions(), influxDBConfig.getFlushDuration(), influxDBConfig.getFlushDurationTimeUnit());
    }

    if (influxDBConfig.isEnableGzip()) {

        influxDBClient.enableGzip();
    }
}
 
開發者ID:apache,項目名稱:bahir-flink,代碼行數:25,代碼來源:InfluxDBSink.java

示例6: saveExtData

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
/**
 * Saves the data into InfluxDB via HTTP
 * <p>
 * Pseudo Code<br/>
 * 1. Load the login credentials from the configuration object<br/>
 * 2. Create a client instance and set the HTTP protocol, url and auth details<br/>
 * 3. Send the data
 *
 * @param data - a JSON representation of the data
 * @return boolean
 */

public boolean saveExtData(String data) {
    InfluxDB influxDB = InfluxDBFactory.connect(this.url, this.username, this.password);
    Representation output;
    String[] columns = getColumns(data);
    ArrayList<String[]> points = getPoints(data);
    int meternameIndex = -1;
    int timeIndex = -1;
    int sourceIndex = -1;
    int usageIndex = -1;
    int useridIndex = -1;
    for (int i = 0; i < columns.length; i++) {
        if (columns[i].equals("timestamp"))
            timeIndex = i;
        else if (columns[i].equals("source"))
            sourceIndex = i;
        else if (columns[i].equals("usage"))
            usageIndex = i;
        else if (columns[i].equals("userId"))
            useridIndex = i;
    }
    logger.debug("Obtained indexes from the columns: Metername: " + meternameIndex + " Time: " + timeIndex + " Source: " + sourceIndex);
    for (int i = 0; i < points.size(); i++) {
        //logger.debug("Attempting to build the Point: " + points.get(i)[meternameIndex]);
        String metername = data.split("name\":")[1];
        metername = metername.split("\"")[1];
        Point point = Point.measurement(metername)
                .tag("time", points.get(i)[timeIndex])
                .tag("source", points.get(i)[sourceIndex].substring(1, points.get(i)[sourceIndex].length() - 1))
                .tag("userId", points.get(i)[useridIndex].substring(1, points.get(i)[useridIndex].length() - 1))
                .field("usage", points.get(i)[usageIndex].substring(0, points.get(i)[usageIndex].length() - 2))
                .build();
        //logger.debug("Attempting to write the Point (" + points.get(i)[meternameIndex] + ") in the db:" + dbName);
        influxDB.write(dbName, "default", point);
        logger.debug("Point successfully written.");
    }
    return true;
}
 
開發者ID:icclab,項目名稱:cyclops-udr,代碼行數:50,代碼來源:InfluxDBClient.java

示例7: clear

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
public void clear(String table, String dbname) {
    InfluxDB influxDB = InfluxDBFactory.connect(this.url, this.username, this.password);
    String drop = "DROP MEASUREMENT " + table;
    String create = "CREATE MEASUREMENT " + table;
    Query query1 = new Query(drop, dbname);

    influxDB.query(query1);
}
 
開發者ID:icclab,項目名稱:cyclops-udr,代碼行數:9,代碼來源:InfluxDBClient.java

示例8: build

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
public InfluxDBReporter build() {
    final OkHttpClient.Builder builder = new OkHttpClient.Builder()
        .connectTimeout( connectionTimeout, MILLISECONDS )
        .readTimeout( readTimeout, MILLISECONDS )
        .writeTimeout( writeTimeout, MILLISECONDS );

    InfluxDB influxDB = InfluxDBFactory.connect( "http://" + host + ":" + port, login, password, builder );

    if( logger.isTraceEnabled() )
        influxDB.setLogLevel( InfluxDB.LogLevel.FULL );

    return new InfluxDBReporter(
        influxDB,
        database,
        tags,
        registry,
        "influx-reporter",
        filter,
        aggregates,
        rateUnit,
        durationUnit,
        resetTimersAfterReport );
}
 
開發者ID:oaplatform,項目名稱:oap,代碼行數:24,代碼來源:InfluxDBReporter.java

示例9: InfluxDbHttpSender

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
/**
 * Creates a new http sender given connection details.
 *
 * @param hostname        the influxDb hostname
 * @param port            the influxDb http port
 * @param database        the influxDb database to write to
 * @param username        the influxDb username
 * @param password        the influxDb password
 * @param retentionPolicy Retention policy to use
 * @param timePrecision   the time precision of the metrics
 * @throws Exception exception while creating the influxDb sender(MalformedURLException)
 */
public InfluxDbHttpSender(
        final String hostname,
        final int port,
        final String database,
        final String username,
        final String password,
        final String retentionPolicy,
        final TimeUnit timePrecision) throws Exception {
    this.timePrecision = timePrecision;
    this.influxDB = InfluxDBFactory.connect(
            String.format("http://%s:%d", hostname, port),
            username,
            password
    );
    // Creates the database
    this.influxDB.createDatabase(database);
    // Batch configuration
    batchPoints = BatchPoints
            .database(database)
            .tag("async", "true")
            .retentionPolicy(retentionPolicy)
            .consistency(InfluxDB.ConsistencyLevel.ALL)
            .build();
}
 
開發者ID:nemerosa,項目名稱:ontrack,代碼行數:37,代碼來源:InfluxDbHttpSender.java

示例10: connect

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
/**
 * Connects to the database server.
 *
 */
private void connect() {
    influxDB = (InfluxDB) InfluxDBFactory.connect(DB_URL, USERNAME, PASSWORD);
    try {
        Pong response = influxDB.ping();
        if (!response.getVersion().equalsIgnoreCase("unknown")) {
            connected = true;
            LOG.info("Connected to database server InfluxDB");
        } else {
            LOG.error("Database server InfluxDB not responding. Please check your configuration and/or connection");
            connected = false;
        }
    } catch (FreedomoticRuntimeException e) {
        connected = false;
        LOG.error("Impossible to connect to database server InfluxDB for {}", e.getMessage());
    }
}
 
開發者ID:freedomotic,項目名稱:freedomotic,代碼行數:21,代碼來源:InfluxDBPersistence.java

示例11: createInfluxDB

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
private InfluxDB createInfluxDB() {
    InfluxDB influxDB = InfluxDBFactory.connect(Config.getInfluxUrl(), Config.getInfluxUser(), Config.getInfluxPassword());
    influxDB.setDatabase(Config.getInfluxDatabase());
    influxDB.enableGzip();
    influxDB.enableBatch(BATCH_SIZE, 100, TimeUnit.MILLISECONDS);
    return influxDB;
}
 
開發者ID:Scrin,項目名稱:RuuviCollector,代碼行數:8,代碼來源:InfluxDataMigrator.java

示例12: init

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
@Override
public void init() {
	super.init();
	Properties prop = getProperties();
	URL = prop.getProperty(DB_URL_INFLUXDB_PROPERTY, "http://127.0.0.1:8086");
	DB_NAME = prop.getProperty(DB_NAME_PROPERTY, "influxdb");
	WRITE_URL = URL + WRITE_URL + DB_NAME;
	QUERY_URL = URL + QUERY_URL + DB_NAME;
	createTestDB();
	INFLUXDB=InfluxDBFactory.connect(URL);
	INFLUXDB.setDatabase(DB_NAME);
}
 
開發者ID:dbiir,項目名稱:ts-benchmark,代碼行數:13,代碼來源:InfluxDB2.java

示例13: prepareTestClass

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
@BeforeClass
public static void prepareTestClass() {
    // May be disable the whole test class.
    Assume.assumeTrue(HekateTestProps.is("INFLUXDB_ENABLED"));

    url = HekateTestProps.get("INFLUXDB_URL");
    user = HekateTestProps.get("INFLUXDB_USER");
    password = HekateTestProps.get("INFLUXDB_PASSWORD");

    String now = new SimpleDateFormat("yyyy.MM.dd--HH:mm:SSS").format(new Date());

    database = InfluxDbMetricsPublisher.toSafeName("db__" + now + "__" + UUID.randomUUID().toString());

    influxDb = InfluxDBFactory.connect(url, user, password);
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:16,代碼來源:InfluxDbMetricsTestBase.java

示例14: init

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
@Override
public void init(AbstractConfiguration config) {
    this.influxDB = InfluxDBFactory.connect(config.getString("influxdb.url"), config.getString("influxdb.username"), config.getString("influxdb.password"));
    this.influxDB.createDatabase(config.getString("influxdb.dbname"));
    this.influxDB.enableBatch(config.getInt("influxdb.actions"), config.getInt("influxdb.durations"), TimeUnit.MILLISECONDS);
    this.dbName = config.getString("influxdb.dbname");
}
 
開發者ID:12315jack,項目名稱:j1st-mqtt,代碼行數:8,代碼來源:InfluxDBMetricsService.java

示例15: checkInfluxConnexion

import org.influxdb.InfluxDBFactory; //導入依賴的package包/類
/**
 * Try to connect to the influxDB with Influx factory
 *
 * @return the instance of influx object
 * @throws ConnectException if the connexion has failed
 */
private InfluxDB checkInfluxConnexion() throws ConnectException {
    InfluxDB influxDB = InfluxDBFactory.connect(properties.getHost(), properties.getUser(), properties.getPassword());
    String collection = PROPERTIES_MANAGER.getProperty("database.metrics.datasource");
    influxDB.createDatabase(collection);
    return influxDB;
}
 
開發者ID:IKB4Stream,項目名稱:IKB4Stream,代碼行數:13,代碼來源:MetricsConnector.java


注:本文中的org.influxdb.InfluxDBFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。