(final String[] args)
| 41 | } |
| 42 | |
| 43 | public static void main(final String[] args) throws Exception { |
| 44 | processArgs(args); |
| 45 | |
| 46 | // Create a config object with a path to the file for parsing. Or manually |
| 47 | // override settings. |
| 48 | // e.g. config.overrideConfig("tsd.storage.hbase.zk_quorum", "localhost"); |
| 49 | final Config config; |
| 50 | if (pathToConfigFile != null && !pathToConfigFile.isEmpty()) { |
| 51 | config = new Config(pathToConfigFile); |
| 52 | } else { |
| 53 | // Search for a default config from /etc/opentsdb/opentsdb.conf, etc. |
| 54 | config = new Config(true); |
| 55 | } |
| 56 | final TSDB tsdb = new TSDB(config); |
| 57 | |
| 58 | // Declare new metric |
| 59 | String metricName = "my.tsdb.test.metric"; |
| 60 | // First check to see it doesn't already exist |
| 61 | byte[] byteMetricUID; // we don't actually need this for the first |
| 62 | // .addPoint() call below. |
| 63 | // TODO: Ideally we could just call a not-yet-implemented tsdb.uIdExists() |
| 64 | // function. |
| 65 | // Note, however, that this is optional. If auto metric is enabled |
| 66 | // (tsd.core.auto_create_metrics), the UID will be assigned in call to |
| 67 | // addPoint(). |
| 68 | try { |
| 69 | byteMetricUID = tsdb.getUID(UniqueIdType.METRIC, metricName); |
| 70 | } catch (IllegalArgumentException iae) { |
| 71 | System.out.println("Metric name not valid."); |
| 72 | iae.printStackTrace(); |
| 73 | System.exit(1); |
| 74 | } catch (NoSuchUniqueName nsune) { |
| 75 | // If not, great. Create it. |
| 76 | byteMetricUID = tsdb.assignUid("metric", metricName); |
| 77 | } |
| 78 | |
| 79 | // Make a single datum |
| 80 | long timestamp = System.currentTimeMillis() / 1000; |
| 81 | long value = 314159; |
| 82 | // Make key-val |
| 83 | Map<String, String> tags = new HashMap<String, String>(1); |
| 84 | tags.put("script", "example1"); |
| 85 | |
| 86 | // Start timer |
| 87 | long startTime1 = System.currentTimeMillis(); |
| 88 | |
| 89 | // Write a number of data points at 30 second intervals. Each write will |
| 90 | // return a deferred (similar to a Java Future or JS Promise) that will |
| 91 | // be called on completion with either a "null" value on success or an |
| 92 | // exception. |
| 93 | int n = 100; |
| 94 | ArrayList<Deferred<Object>> deferreds = new ArrayList<Deferred<Object>>(n); |
| 95 | for (int i = 0; i < n; i++) { |
| 96 | Deferred<Object> deferred = tsdb.addPoint(metricName, timestamp, value + i, tags); |
| 97 | deferreds.add(deferred); |
| 98 | timestamp += 30; |
| 99 | } |
| 100 |
nothing calls this directly
no test coverage detected