InfluxDB计算series的数量,Java实现

谢谢围观 

public class Main {

	private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);

	public static void main(String[] args)
			throws InvalidFormatException, IOException, InstantiationException, IllegalAccessException {
		// importData();
		countSeries();
	}

	public static void countSeries() {
		InfluxDB influxDB = Influx.connect();
		Query query = null;
		QueryResult queryResult = null;
		String sql = null;

		List databases = influxDB.describeDatabases();
		databases.remove("_internal");

		LOGGER.info("数据库的数量为:{},列表如下:{}", databases.size(), databases);

		for (String databaseName : databases) {
			influxDB.setDatabase(databaseName);

			sql = "show measurements";
			query = new Query(sql, databaseName);
			queryResult = influxDB.query(query);

			List measurements = getMeasurements(queryResult);
			for (String measurementName : measurements) {
				sql = String.format("SHOW SERIES ON \"%s\" FROM \"%s\"", databaseName, measurementName);
				query = new Query(sql, databaseName);
				queryResult = influxDB.query(query);
				long num = queryResult.getResults().get(0).getSeries().get(0).getValues().size();
				LOGGER.info("{}.{}.seriesCount = {}", databaseName, measurementName, num);
			}
		}

	}

	private static List getMeasurements(QueryResult queryResult) {
		List collect = queryResult.getResults().get(0).getSeries().get(0).getValues().stream()
				.map(x -> (String) x.get(0)).collect(Collectors.toList());
		return collect;
	}

}

 

你可能感兴趣的:(java)