本文整理汇总了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;
}
示例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();
}
示例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();
}
}
}
示例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();
}
};
}
示例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();
}
}
示例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;
}
示例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);
}
示例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 );
}
示例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();
}
示例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());
}
}
示例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;
}
示例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);
}
示例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);
}
示例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");
}
示例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;
}