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


Java QueryResult.Result方法代码示例

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


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

示例1: metric

import org.influxdb.dto.QueryResult; //导入方法依赖的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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:DefaultInfluxDbMetricsRetriever.java

示例2: allMetricNames

import org.influxdb.dto.QueryResult; //导入方法依赖的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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:31,代码来源:DefaultInfluxDbMetricsRetriever.java

示例3: getTimestamp

import org.influxdb.dto.QueryResult; //导入方法依赖的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);
    }
}
 
开发者ID:BFergerson,项目名称:Chronetic,代码行数:37,代码来源:ChronoSeries.java

示例4: read

import org.influxdb.dto.QueryResult; //导入方法依赖的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())));
    }
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:17,代码来源:MetricsLogger.java

示例5: listDatabases

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * List all the databases
 */
public QueryResult.Series listDatabases() throws InflowException {
  QueryResult queryResult = this.query(null, "SHOW DATABASES");
  QueryResult.Result result = queryResult.getResults().get(0);
  QueryResult.Series series = result.getSeries().get(0);
  return series;
  // callers can use series.getValuesAsStringArray();
}
 
开发者ID:nkiraly,项目名称:influxdb-inflow,代码行数:11,代码来源:Client.java

示例6: listUsers

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * List all the users
 *
 */
public QueryResult.Series listUsers() throws InflowException {
  QueryResult queryResult = this.query(null, "SHOW USERS");
  QueryResult.Result result = queryResult.getResults().get(0);
  QueryResult.Series series = result.getSeries().get(0);
  return series;
  // calle1s can use series.getValuesAsStringArray();
}
 
开发者ID:nkiraly,项目名称:influxdb-inflow,代码行数:12,代码来源:Client.java

示例7: retrieveMeterList

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * Ask for meterList from database
 *
 * @return MeterList object
 */
protected StandardMeter[] retrieveMeterList() {
    String query = new MeterList().createDBQuery();
    // run query
    QueryResult result = dbClient.runQuery(query);
    ArrayList<String> columns = new ArrayList<String>();
    ArrayList<List<String>> points = new ArrayList<List<String>>();
    Boolean onlyOnce = true;
    int nameIndex, sourceIndex;
    ArrayList<StandardMeter> meters = new ArrayList<StandardMeter>();
    try {
        // go over all results
        for (QueryResult.Result data : result.getResults()) {
            // every series
            for (QueryResult.Series serie : data.getSeries()) {
                Map<String, String> tags = serie.getTags();
                // add all column names
                if (onlyOnce) {
                    if (tags != null) {
                        columns.addAll(tags.keySet());
                    }
                    columns.addAll(serie.getColumns());
                    onlyOnce = false;
                }
                // iterate over values
                for (List<Object> values : serie.getValues()) {
                    List<String> line = new ArrayList<String>();
                    // don't forget to manually add tags here
                    if (tags != null) {
                        line.addAll(tags.values());
                    }
                    // cast them to String
                    for (Object value : values) {
                        if (value == null) {
                            line.add("");
                        } else {
                            line.add(String.valueOf(value));
                        }
                    }
                    // and lastly, add them
                    points.add(line);
                }
            }
        }
        nameIndex = columns.indexOf("metername");
        sourceIndex = columns.indexOf("metersource");
        for(List<String> point : points){
            meters.add(new StandardMeter(point.get(nameIndex), point.get(sourceIndex)));
        }
    } catch (Exception ignored) {
        // in case of empty QueryResult body do nothing
    }
    StandardMeter[] ret = new StandardMeter[meters.size()];
    ret = meters.toArray(ret);
    return ret;
}
 
开发者ID:icclab,项目名称:cyclops-udr,代码行数:61,代码来源:CloudStackMeterV2.java

示例8: assertMeasure

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
private void assertMeasure(QueryResult result, int serieIndex, int measureIndex, int valueCount, int serieCount, String oid, String address,
                             String tom, String type, String expectedName, Object expectedValue) {
    List<QueryResult.Result> items = result.getResults();
    assertEquals(items.size(), 1, "Number of results");
    QueryResult.Result item1 = items.get(0);
    List<QueryResult.Series> series = item1.getSeries();
    assertNotNull(series, "Series should not be null in "+item1);
    assertEquals(series.size(), serieCount, "Number of series");
    QueryResult.Series series1 = series.get(serieIndex);
    List<List<Object>> valuesList = series1.getValues();
    assertEquals(valuesList.size(), valueCount, "Number of values");
//    Map<String, String> tags = series1.getTags();
//    assertEquals(tags.size(), 4, "Number of tags created");
//    assertEquals(tags.get("oid"), oid);
//    assertEquals(tags.get("address"), address);
//    assertEquals(tags.get("tom"), tom);
    //fourth tag is influxdb internal
    List<String> columns = series1.getColumns();
    assertEquals(columns.toString(), "[time, "+type+", oid, target, tom]", "Columns created");
    List<Object> measures = valuesList.get(measureIndex);
    assertEquals(measures.size(), 5, "Number of measures"); //this is "time", "value", oid, address, tom
    Object value = measures.get(columns.indexOf(type));
    assertEquals(value, expectedValue, "Value for measure "+measureIndex+" in series "+serieIndex);
    assertEquals(measures.get(columns.indexOf("oid")), oid);
    assertEquals(measures.get(columns.indexOf("target")), address);
    assertEquals(measures.get(columns.indexOf("tom")), tom);
    String name = series1.getName();
    assertEquals(name, expectedName);
  }
 
开发者ID:mukatee,项目名称:kafka-consumer,代码行数:30,代码来源:InFluxJSONTests.java

示例9: assertMeasure

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
private void assertMeasure(QueryResult result, int serieIndex, int measureIndex, int valueCount, int serieCount, String oid, String address,
                             String tom, String type, String expectedName, Object expectedValue) {
    List<QueryResult.Result> items = result.getResults();
    assertEquals(items.size(), 1, "Number of results");
    QueryResult.Result item1 = items.get(0);
    List<QueryResult.Series> series = item1.getSeries();
    assertNotNull(series, "Series should not be null in "+item1);
    assertEquals(series.size(), serieCount, "Number of series");
    QueryResult.Series series1 = series.get(serieIndex);
    List<List<Object>> valuesList = series1.getValues();
    assertEquals(valuesList.size(), valueCount, "Number of values");
//    Map<String, String> tags = series1.getTags();
//    assertEquals(tags.size(), 4, "Number of tags created");
//    assertEquals(tags.get("oid"), oid);
//    assertEquals(tags.get("address"), address);
//    assertEquals(tags.get("tom"), tom);
    //fourth tag is influxdb internal
    List<String> columns = series1.getColumns();
    assertEquals(columns.toString(), "[time, address, oid, tom, "+type+"]", "Columns created");
    List<Object> measures = valuesList.get(measureIndex);
    assertEquals(measures.size(), 5, "Number of measures"); //this is "time", "value", oid, address, tom
    Object value = measures.get(columns.indexOf(type));
    assertEquals(value, expectedValue, "Value for measure "+measureIndex+" in series "+serieIndex);
    assertEquals(measures.get(columns.indexOf("oid")), oid);
    assertEquals(measures.get(columns.indexOf("address")), address);
    assertEquals(measures.get(columns.indexOf("tom")), tom);
    String name = series1.getName();
    assertEquals(name, expectedName);
  }
 
开发者ID:mukatee,项目名称:kafka-consumer,代码行数:30,代码来源:InFluxAvroTests.java

示例10: countEventsBetween

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * Counts the number of time events that occur during the given ChronoRange.
 *
 * @param chronoRange desired ChronoRange
 * @return amount of time events that occur during the given ChronoRange
 */
public int countEventsBetween(@NotNull ChronoRange chronoRange) {
    Integer cacheCount = cachePatternCount.getIfPresent(requireNonNull(chronoRange));
    if (cacheCount != null) {
        return cacheCount;
    } else if (chronoRange.getTimestampRanges().isEmpty()) {
        return 0;
    } else {
        logger.debug("Counting events between: " + chronoRange);
    }

    int count = 0;
    if (seriesList != null) {
        for (Instant timestamp : seriesList) {
            if (chronoRange.containsTime(timestamp)) {
                count++;
            }
        }
    } else {
        List<Instant[]> timestampRanges = chronoRange.getTimestampRanges();
        StringBuilder whereClause = new StringBuilder();
        boolean first = true;
        for (Instant[] timestampRange : timestampRanges) {
            if (first) {
                whereClause = whereClause.append("(");
                first = false;
            } else {
                whereClause = whereClause.append("OR (");
            }

            long startTime = timestampRange[0].getEpochSecond();
            startTime *= 1000000000L; //convert to nanoseconds
            startTime += timestampRange[0].getNano();

            long endTime = timestampRange[1].getEpochSecond();
            endTime *= 1000000000L; //convert to nanoseconds
            endTime += timestampRange[1].getNano();

            whereClause = whereClause.append("time >= ").append(startTime);
            whereClause = whereClause.append(" AND ");
            whereClause = whereClause.append("time <= ").append(endTime);
            whereClause = whereClause.append(") ");
        }

        QueryResult queryResult = influxDB.query(new Query(String.format(
                "SELECT COUNT(%s) FROM \"%s\" WHERE %s",
                column, table, whereClause.toString()), database));

        for (QueryResult.Result result : queryResult.getResults()) {
            if (result.getSeries() != null) {
                Double dbCount = (Double) result.getSeries().get(0).getValues().get(0).get(1);
                count += dbCount.intValue();
            }
        }
    }

    cachePatternCount.put(chronoRange, count);
    return count;
}
 
开发者ID:BFergerson,项目名称:Chronetic,代码行数:65,代码来源:ChronoSeries.java

示例11: loadLatestValue

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
protected Long loadLatestValue(String metric) {
    Query query = new Query("SELECT " + METRIC_VALUE_FIELD + " FROM \"" + metric + "\" ORDER BY time DESC LIMIT 1", database);

    QueryResult result = influxDb.query(query);

    assertNull(result.getError());
    assertFalse(result.hasError());

    QueryResult.Result row = result.getResults().get(0);

    say("Loaded InfluxDB results: " + row);

    Number number = null;

    if (row.getSeries() != null && !row.getSeries().isEmpty()) {
        QueryResult.Series series = row.getSeries().get(0);

        int valueIdx = series.getColumns().indexOf(METRIC_VALUE_FIELD);

        assertTrue("Real index=" + valueIdx, valueIdx >= 0);

        number = (Number)series.getValues().get(0).get(valueIdx);
    }

    return number != null ? number.longValue() : null;
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:27,代码来源:InfluxDbMetricsTestBase.java

示例12: DTOList

import org.influxdb.dto.QueryResult; //导入方法依赖的package包/类
/**
 * This constructor will parse influxDB QueryResult and represent it as an object
 *
 * @param data
 */
public DTOList(QueryResult data) {
    columns = new ArrayList<String>();
    points = new ArrayList<List<String>>();

    Boolean onlyOnce = true;

    try {
        // go over all results
        for (QueryResult.Result result : data.getResults()) {
            // every series
            for (QueryResult.Series serie : result.getSeries()) {
                name = serie.getName();

                Map<String, String> tags = serie.getTags();

                // add all column names
                if (onlyOnce) {

                    if (tags != null) {
                        columns.addAll(tags.keySet());
                    }

                    columns.addAll(serie.getColumns());
                    onlyOnce = false;
                }

                // iterate over values
                for (List<Object> values : serie.getValues()) {
                    List<String> line = new ArrayList<String>();

                    // don't forget to manually add tags here
                    if (tags != null) {
                        line.addAll(tags.values());
                    }

                    // cast them to String
                    for (Object value : values) {
                        if (value == null) {
                            line.add("");
                        } else {
                            line.add(String.valueOf(value));//TODO: Martin Manu, changed to String.valueOf from (String).
                        }
                    }

                    // and lastly, add them
                    points.add(line);
                }
            }
        }
    } catch (Exception ignored) {
        // in case of empty QueryResult body do nothing
    }
}
 
开发者ID:icclab,项目名称:cyclops-udr,代码行数:59,代码来源:DTOList.java


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