OpenTSDB源码分析之TSDB表操作(查询)

本文深入分析OpenTSDB的源码,重点探讨TSDB表的查询操作,特别是涉及行键的复杂性和字段过滤器的运用。通过TsdbQuery.run()方法创建带过滤条件的扫描器,结合监控指标、日期范围和标签进行数据筛选。查询流程可在CliQuery.main()方法中找到。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值