MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / main

Method main

src/examples/QueryExample.java:44–196  ·  view source on GitHub ↗
(final String[] args)

Source from the content-addressed store, hash-verified

42public 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

Callers

nothing calls this directly

Calls 15

setStartMethod · 0.95
setMetricMethod · 0.95
setFiltersMethod · 0.95
setAggregatorMethod · 0.95
setQueriesMethod · 0.95
setMsResolutionMethod · 0.95
validateAndSetQueryMethod · 0.95
buildQueriesMethod · 0.95
nanoTimeMethod · 0.95
msFromNanoDiffMethod · 0.95
hasNextMethod · 0.95
nextMethod · 0.95

Tested by

no test coverage detected