本文整理汇总了Java中org.influxdb.dto.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于org.influxdb.dto包,在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execInfluxdbQuery
import org.influxdb.dto.Query; //导入依赖的package包/类
private Status execInfluxdbQuery(String sql) {
long costTime = 0L;
try {
//TODO 需要完善
long startTime1=System.nanoTime();
QueryResult results = INFLUXDB.query(new Query(sql, DB_NAME));
long endTime1=System.nanoTime();
costTime=endTime1-startTime1;
if(results.hasError()) {
return Status.FAILED(costTime);
}else {
return Status.OK(costTime);
}
} catch (Exception e) {
e.printStackTrace();
return Status.FAILED(0L);
}
}
示例2: metric
import org.influxdb.dto.Query; //导入依赖的package包/类
@Override
public InfluxMetric metric(NodeId nodeId, String metricName) {
String queryString = new StringBuilder()
.append("SELECT m1_rate FROM ")
.append(database)
.append(METRIC_DELIMITER)
.append(quote(DEFAULT_POLICY))
.append(METRIC_DELIMITER)
.append(quote(nodeId + METRIC_DELIMITER + metricName))
.append(" LIMIT 1")
.toString();
Query query = new Query(queryString, database);
List<QueryResult.Result> results = influxDB.query(query).getResults();
if (results != null && results.get(0) != null
&& results.get(0).getSeries() != null) {
return new DefaultInfluxMetric.Builder()
.time((String) results.get(0).getSeries().get(0).getValues().get(0).get(0))
.oneMinRate((Double) results.get(0).getSeries().get(0)
.getValues().get(0).get(1)).build();
}
return null;
}
示例3: allMetricNames
import org.influxdb.dto.Query; //导入依赖的package包/类
/**
* Returns all metric names that bound with node identification.
*
* @return all metric names
*/
protected Map<NodeId, Set<String>> allMetricNames() {
Map<NodeId, Set<String>> metricNameMap = Maps.newHashMap();
Query query = new Query("SHOW MEASUREMENTS", database);
List<QueryResult.Result> results = influxDB.query(query).getResults();
List<List<Object>> rawMetricNames = results.get(0).getSeries().get(0).getValues();
rawMetricNames.forEach(rawMetricName -> {
String nodeIdStr = getNodeId(strip(rawMetricName.toString()));
if (nodeIdStr != null) {
NodeId nodeId = NodeId.nodeId(nodeIdStr);
String metricName = getMetricName(strip(rawMetricName.toString()));
if (!metricNameMap.containsKey(nodeId)) {
metricNameMap.putIfAbsent(nodeId, Sets.newHashSet());
}
if (metricName != null) {
metricNameMap.get(nodeId).add(metricName);
}
}
});
return metricNameMap;
}
示例4: run
import org.influxdb.dto.Query; //导入依赖的package包/类
@Override
public void run(final String... args) throws Exception
{
// Create database...
influxDBTemplate.createDatabase();
// Create some data...
final Point p1 = Point.measurement("cpu")
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.tag("tenant", "default")
.addField("idle", 90L)
.addField("user", 9L)
.addField("system", 1L)
.build();
final Point p2 = Point.measurement("disk")
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
.tag("tenant", "default")
.addField("used", 80L)
.addField("free", 1L)
.build();
influxDBTemplate.write(p1, p2);
// ... and query the latest data
final Query q = new Query("SELECT * FROM cpu GROUP BY tenant", influxDBTemplate.getDatabase());
influxDBTemplate.getConnection().query(q, 2, queryResult -> logger.info(queryResult.toString()));
}
示例5: getFileSize
import org.influxdb.dto.Query; //导入依赖的package包/类
@Override
public long getFileSize() {
final QueryResult result = getInfluxDB().query(new Query(String.format("select sum(\"diskBytes\") as \"diskBytes\" from (select last(\"diskBytes\"::field) as \"diskBytes\" from \"shard\" where \"database\"::tag = '%s' group by * limit 1)", getDatabase().replace("'", "\\'")), "_internal"), TimeUnit.MILLISECONDS);
throwOnResultError(result);
return result.getResults().stream()
.filter(r -> !r.hasError())
.filter(r -> r.getSeries() != null)
.flatMap(r -> r.getSeries().stream())
.map(s -> getColumnFromSeries(s, "diskBytes"))
.filter(Optional::isPresent)
.flatMap(Optional::get)
.map(Number.class::cast)
.mapToLong(Number::longValue)
.findAny()
.orElse(0);
}
示例6: keyedQueriesAnswer
import org.influxdb.dto.Query; //导入依赖的package包/类
private static Answer<QueryResult> keyedQueriesAnswer(Collection<KeyedQuery> queries) {
final Map<String, String> mapping = queries.stream().collect(Collectors.toMap(KeyedQuery::getQuery, KeyedQuery::getBaseFileName));
return new Answer<QueryResult>() {
@Override
public QueryResult answer(InvocationOnMock invocation) throws Throwable {
final String q = invocation.getArgumentAt(0, Query.class).getCommand();
final String file = mapping.get(q);
if (file != null) {
LOG.log(Level.INFO, "mapping to \"{1}\" from query: {0}", new Object[]{q, file});
return new JsonQueryResult(file).getQueryResult();
}
throw new AssertionError("unexpected query: " + q);
}
};
}
示例7: clear
import org.influxdb.dto.Query; //导入依赖的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: getTimestamp
import org.influxdb.dto.Query; //导入依赖的package包/类
/**
* Returns the timestamp at the given series position.
*
* @param seriesPosition desired position
* @return timestamp at given series position
*/
@NotNull
public Instant getTimestamp(int seriesPosition) {
Instant cacheTimestamp = timestampCache.getIfPresent(seriesPosition);
if (cacheTimestamp != null) {
return cacheTimestamp;
} else {
logger.debug("Getting timestamp at position: " + seriesPosition);
}
Instant timestamp = null;
if (seriesList != null) {
timestamp = seriesList.get(seriesPosition);
} else {
QueryResult queryResult = influxDB.query(new Query(String.format(
"SELECT %s FROM \"%s\" LIMIT 1 OFFSET %d",
column, table, seriesPosition), database));
for (QueryResult.Result result : queryResult.getResults()) {
String timeString = (String) result.getSeries().get(0).getValues().get(0).get(0);
timestamp = Instant.parse(timeString);
}
}
if (timestamp != null) {
timestampCache.put(seriesPosition, timestamp);
return timestamp;
} else {
throw new IllegalStateException("Unable to determine timestamp at series position: " + seriesPosition);
}
}
示例9: read
import org.influxdb.dto.Query; //导入依赖的package包/类
/**
* Read the result of a request to read data loaded into influxdb
*
* @param request the specific request
* @throws NullPointerException if request is null
* @see MetricsLogger#metricsConnector
*/
public void read(String request) {
Objects.requireNonNull(request);
if (checkValidInfluxDBConnexion()) {
final Query query = new Query(request, metricsConnector.getProperties().getDbName());
QueryResult fixes = this.metricsConnector.getInfluxDB().query(query);
List<QueryResult.Result> resultsList = fixes.getResults();
resultsList.stream().filter(results -> results.getSeries() != null).forEach(results -> results.getSeries().forEach(series -> LOGGER.info(series.toString())));
}
}
示例10: metricsByName
import org.influxdb.dto.Query; //导入依赖的package包/类
@Override
public Map<NodeId, List<InfluxMetric>> metricsByName(String metricName, int period,
TimeUnit unit) {
Map<NodeId, List<InfluxMetric>> map = Maps.newHashMap();
List<InfluxMetric> metrics = Lists.newArrayList();
String queryPrefix = new StringBuilder()
.append("SELECT m1_rate FROM")
.append(database)
.append(METRIC_DELIMITER)
.append(quote(DEFAULT_POLICY))
.append(METRIC_DELIMITER)
.toString();
String querySuffix = new StringBuilder()
.append(" WHERE time > now() - ")
.append(period)
.append(unitString(unit))
.toString();
allMetricNames().keySet().forEach(nodeId -> {
String queryString = new StringBuilder()
.append(queryPrefix)
.append(quote(nodeId + METRIC_DELIMITER + metricName))
.append(querySuffix)
.toString();
Query query = new Query(queryString, database);
List<QueryResult.Result> results = influxDB.query(query).getResults();
if (results != null && results.get(0) != null
&& results.get(0).getSeries() != null) {
results.get(0).getSeries().get(0).getValues().forEach(value ->
metrics.add(new DefaultInfluxMetric.Builder()
.time((String) value.get(0))
.oneMinRate((Double) value.get(1))
.build()));
map.putIfAbsent(nodeId, metrics);
}
});
return map;
}
示例11: getEnd
import org.influxdb.dto.Query; //导入依赖的package包/类
@Override
public DateTime getEnd() {
final QueryResult result = getInfluxDB().query(new Query("select * from /.*/ order by time desc limit 1", getDatabase()), TimeUnit.MILLISECONDS);
throwOnResultError(result);
return extractTimestamps(result)
.max(Comparator.naturalOrder())
.orElseGet(() -> new DateTime(DateTimeZone.UTC));
}
示例12: execute
import org.influxdb.dto.Query; //导入依赖的package包/类
public Stream<TimeSeriesCollection> execute(DateTime begin, DateTime end) {
return selectHandler.queriesForInterval(begin, end)
.peek(query -> LOG.log(Level.INFO, "{0}", query))
.map(queryStr -> new Query(queryStr, getDatabase()))
.map(query -> getInfluxDB().query(query, TimeUnit.MILLISECONDS))
.peek(InfluxUtil::throwOnResultError)
.map(QueryResult::getResults)
.flatMap(Collection::stream)
.filter(result -> !result.hasError())
.filter(r -> r.getSeries() != null)
.flatMap(r -> r.getSeries().stream())
.collect(SeriesHandler::new, SeriesHandler::addSeries, SeriesHandler::merge)
.build();
}
示例13: doTestResponse
import org.influxdb.dto.Query; //导入依赖的package包/类
protected void doTestResponse(String responseFile, String method, QueryResult.Series expectedSeries) throws Exception {
Client client = this.getClient(this.TEST_TARGET_USERNAME, this.TEST_TARGET_PASSWORD);
// setup a mock driver that always returns responseFile contents as QueryResult object
DriverOnlyStubs mockDriver = Mockito.mock(DriverOnlyStubs.class);
final String expectedResponseJson = this.loadResourceFileDataAsString(responseFile);
Mockito.when(mockDriver.query(any(Query.class))).thenAnswer(new Answer<QueryResult>() {
@Override
public QueryResult answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
Client.setLastQuery(((Query)args[0]).getCommand());
Gson gson = new Gson();
QueryResult qr = gson.fromJson(expectedResponseJson, QueryResult.class);
return qr;
}
});
// specify the client to use the mockDriver we just built to return the expected response
client.setDriver(mockDriver);
Class noParam[] = {};
//Class[] oneStringParam= new Class[1];
//oneStringParam[0] = String.class;
Method callMethod = Client.class.getDeclaredMethod(method, noParam);
QueryResult.Series resultSeries = (QueryResult.Series) callMethod.invoke(client, null);
assertEquals(
resultSeries,
expectedSeries
);
}
示例14: getMockClientThatListsTestDbs
import org.influxdb.dto.Query; //导入依赖的package包/类
protected DriverInterface getMockClientThatListsTestDbs() throws Exception {
Database database = new Database(TEST_TARGET_DATABSENAME, this.getMockClient());
DriverOnlyStubs mockDriver = Mockito.mock(DriverOnlyStubs.class);
// when mockDriver.query() with a query object of SHOW DATABASES target null database
// return a QueryResult deserialzed from databases.example.json
Query query = new Query("SHOW DATABASES", null);
final String databasesJson = this.loadResourceFileDataAsString("/databases.example.json");
Mockito.when(mockDriver.query(eq(query)))
.thenAnswer(new Answer<QueryResult>() {
@Override
public QueryResult answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
if (args[0] != null) {
Query argQuery = (Query)args[0];
Client.setLastQuery(argQuery.getCommand());
}
Gson gson = new Gson();
QueryResult qr = gson.fromJson(databasesJson, QueryResult.class);
return qr;
}
});
return mockDriver;
}
示例15: errorMsg
import org.influxdb.dto.Query; //导入依赖的package包/类
@Test
public void errorMsg() {
String msg = TestUtils.getResource(InFluxJSONTests.class, "test_msg_error.json");
influx.process(msg);
QueryResult result = db.query(new Query("select * from test_oid3", dbName));
assertMeasure(result, 0, 0, 1, 1, "1.1.1.2.1", "127.0.0.1:155", "test target 3", "error", "test_oid3", "value_could_not_be_read");
}