TSDB表的行键比tsdb-uid表复杂,查询也要复杂一些,这种复杂性体现在字段过滤器,在该过滤器中监控指标、日期范围和标签都要考虑到。
所有的过滤器都通过TsdbQuery.run()方法实现,创建带过滤器的扫描器,遍历返回的行和收集数据供显示使用,使用辅助方法TsdbQuery.getScanner()和TsdbQuery.findSpans()。
Tsdb表的查询可以具体查看CliQuery.main()方法。
public static void main(String[] args) throws Exception {
/**
* 将查询结果打印输出
*/
// args = new String[] { "2013/09/08-12:57", "2013/10/20-16:57", "sum",
// "t22", "host=foo"};
/**
* 查询输出写入到gnuplot加载文件中 w l lt 3 lw 2(with line linetype 3 linewidth 2)为plot绘图参数不可缺少
*/
args = new String[] { "--graph=e:/a", "2013/09/08-12:57", "2013/10/20-16:57", /*"+format x=\"%a %d %H:%M\"",*/ "sum", "t22", "host=foo", "w l lt 3 lw 2" };
ArgP argp = new ArgP();
CliOptions.addCommon(argp);
CliOptions.addVerbose(argp);
argp.addOption("--graph", "BASEPATH", "Output data points to a set of files for gnuplot." + " The path of the output files will start with"
+ " BASEPATH.");
args = CliOptions.parse(argp, args);
if (args == null) {
usage(argp, "Invalid usage.", 1);
} else if (args.length < 3) {
usage(argp, "Not enough arguments.", 2);
}
// get a config object
Config config = CliOptions.getConfig(argp);
final TSDB tsdb = new TSDB(config);
tsdb.checkNecessaryTablesExist().joinUninterruptibly();
final String basepath = argp.ge