(final String[] args)
| 42 | public class QueryExample { |
| 43 | |
| 44 | public static void main(final String[] args) throws IOException { |
| 45 | |
| 46 | // Set these as arguments so you don't have to keep path information in |
| 47 | // source files |
| 48 | String pathToConfigFile = (args != null && args.length > 0 ? args[0] : null); |
| 49 | |
| 50 | // Create a config object with a path to the file for parsing. Or manually |
| 51 | // override settings. |
| 52 | // e.g. config.overrideConfig("tsd.storage.hbase.zk_quorum", "localhost"); |
| 53 | final Config config; |
| 54 | if (pathToConfigFile != null && !pathToConfigFile.isEmpty()) { |
| 55 | config = new Config(pathToConfigFile); |
| 56 | } else { |
| 57 | // Search for a default config from /etc/opentsdb/opentsdb.conf, etc. |
| 58 | config = new Config(true); |
| 59 | } |
| 60 | final TSDB tsdb = new TSDB(config); |
| 61 | |
| 62 | // main query |
| 63 | final TSQuery query = new TSQuery(); |
| 64 | |
| 65 | // use any string format from |
| 66 | // http://opentsdb.net/docs/build/html/user_guide/query/dates.html |
| 67 | query.setStart("1h-ago"); |
| 68 | // Optional: set other global query params |
| 69 | |
| 70 | // at least one sub query required. This is where you specify the metric and |
| 71 | // tags |
| 72 | final TSSubQuery subQuery = new TSSubQuery(); |
| 73 | subQuery.setMetric("my.tsdb.test.metric"); |
| 74 | |
| 75 | // filters are optional but useful. |
| 76 | final List<TagVFilter> filters = new ArrayList<TagVFilter>(1); |
| 77 | filters.add(new TagVFilter.Builder() |
| 78 | .setType("literal_or") |
| 79 | .setFilter("example1") |
| 80 | .setTagk("script") |
| 81 | .setGroupBy(true) |
| 82 | .build()); |
| 83 | subQuery.setFilters(filters); |
| 84 | |
| 85 | // you do have to set an aggregator. Just provide the name as a string |
| 86 | subQuery.setAggregator("sum"); |
| 87 | |
| 88 | // IMPORTANT: don't forget to add the subQuery |
| 89 | final ArrayList<TSSubQuery> subQueries = new ArrayList<TSSubQuery>(1); |
| 90 | subQueries.add(subQuery); |
| 91 | query.setQueries(subQueries); |
| 92 | query.setMsResolution(true); // otherwise we aggregate on the second. |
| 93 | |
| 94 | // make sure the query is valid. This will throw exceptions if something |
| 95 | // is missing |
| 96 | query.validateAndSetQuery(); |
| 97 | |
| 98 | // compile the queries into TsdbQuery objects behind the scenes |
| 99 | Query[] tsdbqueries = query.buildQueries(tsdb); |
| 100 | |
| 101 | // create some arrays for storing the results and the async calls |
nothing calls this directly
no test coverage detected