org.influxdb.InfluxDB.createDatabase()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(227)

本文整理了Java中org.influxdb.InfluxDB.createDatabase()方法的一些代码示例,展示了InfluxDB.createDatabase()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。InfluxDB.createDatabase()方法的具体详情如下:
包路径:org.influxdb.InfluxDB
类名称:InfluxDB
方法名:createDatabase

InfluxDB.createDatabase介绍

[英]Create a new Database.
[中]创建一个新的数据库。

代码示例

代码示例来源:origin: jmxtrans/jmxtrans

public void doWrite(Server server, Query query, Iterable<Result> results) throws Exception {
  if (createDatabase) influxDB.createDatabase(database);
  BatchPoints.Builder batchPointsBuilder = BatchPoints.database(database).retentionPolicy(retentionPolicy)
      .tag(TAG_HOSTNAME, server.getSource());

代码示例来源:origin: inspectIT/inspectIT

/**
 * Creates a database.
 * 
 * @param database
 *            database
 * @return Returns true if the creation was successful
 */
private boolean createDatabase(String database) {
  try {
    influxDB.createDatabase(database);
  } catch (Exception ex) {
    if (log.isDebugEnabled()) {
      log.debug("Creating database failed with the following message: " + ex.getMessage());
    }
    return false;
  }
  return true;
}

代码示例来源:origin: tzolov/geode-dashboard

@Override
protected void doCreateEmptyDatabase() {
  LOG.info("(Re)create influxDB [" + influxDatabaseName + "]");
  influxDB.deleteDatabase(influxDatabaseName);
  influxDB.createDatabase(influxDatabaseName);
}

代码示例来源:origin: tzolov/geode-dashboard

@Autowired
public JmxInfluxLoader(InfluxDB influxDB,
    MBeanServerConnection jmxConnection,
    @Value("${cleanDatabaseOnStart}") boolean cleanDatabaseOnStart,
    @Value("${influxRetentionPolicy}") String influxRetentionPolicy,
    @Value("${mbeanHostName}") String mbeanHostName,
    @Value("${mbeanPort}") String mbeanPort,
    @Value("${influxDatabaseName}") String influxDatabaseName,
    @Value("${cronExpression}") String cronExpression) {
  this.influxDB = influxDB;
  this.jmxConnection = jmxConnection;
  this.cleanDatabaseOnStart = cleanDatabaseOnStart;
  this.influxRetentionPolicy = influxRetentionPolicy;
  this.mbeanHostName = mbeanHostName;
  this.mbeanPort = mbeanPort;
  this.influxDatabaseName = influxDatabaseName;
  this.cronExpression = cronExpression;
  log.info("cronExpression: " + cronExpression);
  if (this.cleanDatabaseOnStart) {
    influxDB.deleteDatabase(influxDatabaseName);
    influxDB.createDatabase(this.influxDatabaseName);
  }
}

代码示例来源:origin: miwurster/spring-data-influxdb

@Override
public void createDatabase()
{
 final String database = getDatabase();
 getConnection().createDatabase(database);
}

代码示例来源:origin: NovatecConsulting/JMeter-InfluxDB-Writer

/**
 * Creates the configured database in influx if it does not exist yet.
 */
private void createDatabaseIfNotExistent() {
  List<String> dbNames = influxDB.describeDatabases();
  if (!dbNames.contains(influxDBConfig.getInfluxDatabase())) {
    influxDB.createDatabase(influxDBConfig.getInfluxDatabase());
  }
}

代码示例来源:origin: dataArtisans/oscon

@Override
public void open(Configuration parameters) throws Exception {
 super.open(parameters);
 influxDB = InfluxDBFactory.connect("http://localhost:8086", "admin", "admin");
 influxDB.createDatabase(dataBaseName);
 influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: PerfCake/PerfCake

@Override
public void open() {
 Arrays.stream(tags.split(",")).map(StringUtil::trim).forEach(tagsArray::add);
 try {
   if ((keyStore != null && !"".equals(keyStore)) || (trustStore != null && !"".equals(trustStore))) {
    sslFactory = SslSocketFactoryFactory.newSslSocketFactory(keyStore, keyStorePassword, trustStore, trustStorePassword);
   }
 } catch (PerfCakeException e) {
   log.warn("Unable to initialize SSL socket factory: ", e);
 }
 try {
   if (sslFactory != null) {
    final OkHttpClient client = new OkHttpClient();
    client.setSslSocketFactory(sslFactory);
    client.setHostnameVerifier((hostname, session) -> true);
    influxDb = InfluxDBFactory.connect(serverUrl, userName, password, new OkClient(client));
   } else {
    influxDb = InfluxDBFactory.connect(serverUrl, userName, password);
   }
   if (createDatabase) {
    influxDb.createDatabase(database);
   }
   influxDb.enableBatch(100, 500, TimeUnit.MILLISECONDS);
 } catch (RuntimeException rte) {
   influxDb = null;
   log.error("Unable to connect to InfluxDb: ", rte);
 }
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void writeTestFailsDatabaseCreationFails() {
  influxDao.active = true;
  Mockito.doThrow(new RuntimeException()).when(influxDb).write(any(String.class), any(String.class), any(Point.class));
  Mockito.doThrow(new RuntimeException()).when(influxDb).describeDatabases();
  Mockito.doThrow(new RuntimeException()).when(influxDb).createDatabase(any(String.class));
  influxDao.propertiesUpdated();
  assertThat(influxDao.isConnected(), is(false));
  verify(executor, times(1)).submit(any(Runnable.class));
  verify(clientFactory).createClient();
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(influxDb).describeDatabases();
  verify(influxDb).createDatabase(any(String.class));
  verifyNoMoreInteractions(future, influxDb, executor, clientFactory);
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void reconnectedBatchEnabled() {
  influxDao.active = true;
  when(influxDb.isBatchEnabled()).thenReturn(true);
  influxDao.onReconnection();
  verify(influxDb).isBatchEnabled();
  verify(influxDb).describeDatabases();
  verify(influxDb).createDatabase(influxDao.database);
  verifyNoMoreInteractions(influxDb);
  verifyZeroInteractions(future, executor, availabilityChecker, clientFactory);
}

代码示例来源:origin: org.apereo.cas/cas-server-support-influxdb-core

public InfluxDbConnectionFactory(final String url, final String uid,
                 final String psw, final String dbName,
                 final boolean dropDatabase) {
  if (StringUtils.isBlank(dbName) || StringUtils.isBlank(url)) {
    throw new IllegalArgumentException("Database name/url cannot be blank and must be specified");
  }
  val builder = new OkHttpClient.Builder();
  this.influxDb = InfluxDBFactory.connect(url, uid, psw, builder);
  this.influxDb.enableGzip();
  if (dropDatabase) {
    this.influxDb.deleteDatabase(dbName);
  }
  if (!this.influxDb.databaseExists(dbName)) {
    this.influxDb.createDatabase(dbName);
  }
  this.influxDb.setLogLevel(InfluxDB.LogLevel.NONE);
  if (LOGGER.isDebugEnabled()) {
    this.influxDb.setLogLevel(InfluxDB.LogLevel.FULL);
  } else if (LOGGER.isInfoEnabled()) {
    this.influxDb.setLogLevel(InfluxDB.LogLevel.BASIC);
  } else if (LOGGER.isWarnEnabled()) {
    this.influxDb.setLogLevel(InfluxDB.LogLevel.HEADERS);
  } else if (LOGGER.isErrorEnabled()) {
    this.influxDb.setLogLevel(InfluxDB.LogLevel.NONE);
  }
}

代码示例来源:origin: inspectIT/inspectIT

@Test
public void reconnected() {
  influxDao.active = true;
  when(influxDb.isBatchEnabled()).thenReturn(false);
  influxDao.onReconnection();
  assertThat(influxDao.isConnected(), is(true));
  assertThat(influxDao.getServiceStatus(), is(ExternalServiceStatus.CONNECTED));
  verify(influxDb).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(influxDb).describeDatabases();
  verify(influxDb).createDatabase(influxDao.database);
  verifyNoMoreInteractions(influxDb);
  verifyZeroInteractions(future, executor, availabilityChecker, clientFactory);
}

代码示例来源:origin: org.wso2.testgrid/org.wso2.testgrid.common

/**
 * This method will create a DB in influxDB and add a new Data source to grafana
 */
public void initDashboard() {
  // create influxDB database according to tp_id
  InfluxDB influxDB = null;
  try {
    influxDB = InfluxDBFactory.connect(TestGridConstants.HTTP + restUrl, username, password);
    String dbName = testplanID;
    influxDB.createDatabase(dbName);
    logger.info(StringUtil.concatStrings("database created for testplan: ", testplanID,
        "and DB name: ", dbName));
  } catch (AssertionError e) {
    logger.error(StringUtil.concatStrings("Cannot create a new Database: \n", e));
  } catch (IllegalArgumentException e) {
    logger.error(StringUtil.concatStrings("INFLUXDB_USER and INFLUXDB_PASS cannot be empty: \n", e));
  } finally {
    if (influxDB != null) {
      try {
        influxDB.close();
      } catch (Exception e) {
        logger.error("Couldn't close the influxDB connection");
      }
    }
  }
  // add a new data source to grafana
  addGrafanaDataSource();
  configureTelegrafHost();
}

代码示例来源:origin: smartcat-labs/cassandra-diagnostics

influx.createDatabase(dbName);

代码示例来源:origin: inspectIT/inspectIT

@Test
public void writeTestFailsDatabaseCreationSucceeds() {
  influxDao.active = true;
  Mockito.doThrow(new RuntimeException()).when(influxDb).write(any(String.class), any(String.class), any(Point.class));
  influxDao.propertiesUpdated();
  assertThat(influxDao.isConnected(), is(true));
  verify(executor, times(1)).submit(any(Runnable.class));
  verify(influxDb).write(any(String.class), any(String.class), any(Point.class));
  verify(clientFactory).createClient();
  verify(influxDb).describeDatabases();
  verify(influxDb).createDatabase(any(String.class));
  verify(influxDb, times(1)).isBatchEnabled();
  verify(influxDb).enableBatch(InfluxDBDao.BATCH_BUFFER_SIZE, InfluxDBDao.BATCH_FLUSH_TIMER, TimeUnit.SECONDS);
  verify(influxDb).ping();
  verify(availabilityChecker, times(1)).deactivate();
  verify(availabilityChecker).setInflux(influxDb);
  verify(availabilityChecker).activate();
  verifyNoMoreInteractions(future, influxDb, executor, clientFactory);
}

代码示例来源:origin: org.apache.camel/camel-influxdb

private void doInsert(Exchange exchange, String dataBaseName, String retentionPolicy) throws InvalidPayloadException {
  if (!endpoint.isBatch()) {
    Point p = exchange.getIn().getMandatoryBody(Point.class);
    try {
      LOG.debug("Writing point {}", p.lineProtocol());
      
      if (!connection.databaseExists(dataBaseName)) {
        LOG.debug("Database {} doesn't exist. Creating it...", dataBaseName);
        connection.createDatabase(dataBaseName);
      }
      connection.write(dataBaseName, retentionPolicy, p);
    } catch (Exception ex) {
      exchange.setException(new CamelInfluxDbException(ex));
    }
  } else {
    BatchPoints batchPoints = exchange.getIn().getMandatoryBody(BatchPoints.class);
    try {
      LOG.debug("Writing BatchPoints {}", batchPoints.lineProtocol());
      connection.write(batchPoints);
    } catch (Exception ex) {
      exchange.setException(new CamelInfluxDbException(ex));
    }
  }
}

代码示例来源:origin: dataArtisans/flink-training-exercises

@Override
public void open(Configuration unused) throws Exception {
  super.open(unused);
  influxDB = InfluxDBFactory.connect(parameters.get("url", "http://localhost:8086"),
      parameters.get("user", "admin"),
      parameters.get("password", "admin"));
  influxDB.createDatabase(parameters.get("db", DEFAULT_DATABASE_NAME));
  influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS);
  this.fieldName = parameters.get("field", DEFAULT_FIELD_NAME);
}

代码示例来源:origin: org.jmxtrans/jmxtrans-output-influxdb

public void doWrite(Server server, Query query, Iterable<Result> results) throws Exception {
  if (createDatabase) influxDB.createDatabase(database);
  BatchPoints.Builder batchPointsBuilder = BatchPoints.database(database).retentionPolicy(retentionPolicy)
      .tag(TAG_HOSTNAME, server.getSource());

代码示例来源:origin: apache/bahir-flink

/**
 * 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())) {
    if(influxDBConfig.isCreateDatabase()) {
      influxDBClient.createDatabase(influxDBConfig.getDatabase());
    }
    else {
      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();
  }
}

代码示例来源:origin: sitewhere/sitewhere

@Override
public void initialize(ILifecycleProgressMonitor monitor) throws SiteWhereException {
super.start(monitor);
String connectionUrl = "http://" + getHostname().getValue() + ":" + getConfiguration().getPort();
this.influx = InfluxDBFactory.connect(connectionUrl, getConfiguration().getUsername(),
  getConfiguration().getPassword());
influx.createDatabase(getDatabase().getValue());
if (getConfiguration().isEnableBatch()) {
  influx.enableBatch(getConfiguration().getBatchChunkSize(), getConfiguration().getBatchIntervalMs(),
    TimeUnit.MILLISECONDS);
}
influx.setLogLevel(convertLogLevel(getConfiguration().getLogLevel()));
}

相关文章