All Products
Search
Document Center

Quick start guide

Last Updated: May 25, 2020

Rollup example

1. Make preparations for service verification

Create a rollup rule for an instance in the TSDB console.

2. Write data for service verification

This example uses a stress testing application to continuously write a data point every second.

  1. public static void main(String[] args) throws InterruptedException, IOException {
  2. //Create a TSDB instance in the staging environment.
  3. HiTSDBConfig config = HiTSDBConfig.address("{TSDB instance ID}.hitsdb.rds.aliyuncs.com", 3242)
  4. .listenBatchPut(new BatchPutCallback()
  5. {
  6. @Override
  7. public void response(String s, List<Point> list, Result result) {
  8. Point p = Iterables.getFirst(list, null);
  9. System.out.println("Put datapoint in second:" + (p == null ? null : p.getTimestamp()));
  10. }
  11. @Override
  12. public void failed(String address, List<Point> request, Exception ex) {
  13. System.err.println(ex);
  14. }
  15. })
  16. .config();
  17. HiTSDB tsdb = HiTSDBClientFactory.connect(config);
  18. //Create data and write the data to TSDB.
  19. for (int i = 0; i < 3600 * 2; i++) {
  20. int second = Math.toIntExact(System.currentTimeMillis() / 1000);
  21. List<Point> points = new ArrayList<Point>();
  22. points.add(Point
  23. .metric("test.rollup.t5")
  24. .tag("tagk1", "tagv1")
  25. .value(second, Math.random())
  26. .build()
  27. );
  28. points.add(Point
  29. .metric("test.rollup.t5")
  30. .tag("tagk1", "tagv1")
  31. .tag("tagk2", "tagv2")
  32. .value(second, Math.random())
  33. .build()
  34. );
  35. points.add(Point
  36. .metric("test.rollup.t5")
  37. .tag("tagk1", "tagv1")
  38. .tag("tagk2", "tagv2")
  39. .tag("tagk3", "tagv3")
  40. .value(second, Math.random())
  41. .build()
  42. );
  43. tsdb.put(points);
  44. System.out.println(i);
  45. Thread.sleep(1000); //Submit data every second.
  46. }
  47. //Use a secure method to close the client to prevent data loss.
  48. System.out.println("Close");
  49. tsdb.close();
  50. }

3. Verify the task status

The task status is continuously updated during the data writing process.

The following three performance metrics are used to check the task status:

  • Data points that match the rule within five minutes
  • Data points that are to be processed
  • Data points in the rollup output within five minutes

4. Verify queries

4.1 Verify queries that are based on raw data

Request (stored as the query.json file)

  1. {
  2. "start":1560742264,
  3. "end":1560742564,
  4. "queries":[
  5. {
  6. "aggregator":"sum",
  7. "downsample":"1m-sum",
  8. "metric":"test.rollup.t5",
  9. "tags":{
  10. "tagk1":"tagv1",
  11. "tagk2":"tagv2",
  12. "tagk3":"tagv3"
  13. }
  14. }
  15. ]
  16. }

Command

  1. curl -H "Accept: application/json" -H "Content-type: application/json" -X POST --data @query.json http://Instance IP address:3242/api/query

Result ([raw data])

Step 3: Rollup

4.2 Verify queries that are based on rollups

Request (stored as the query_rollup.json file)

  1. {
  2. "start":1560742264,
  3. "end":1560742564,
  4. "queries":[
  5. {
  6. "aggregator":"avg",
  7. "downsample":"1m-sum",
  8. "metric":"test.rollup.t5",
  9. "tags":{
  10. "tagk1":"tagv1",
  11. "tagk2":"tagv2",
  12. "tagk3":"tagv3",
  13. "__granularity__":"1m.sum"
  14. }
  15. }
  16. ]
  17. }

Command

  1. curl -H "Accept: application/json" -H "Content-type: application/json" -X POST --data @query_rollup.json http://Instance IP address:3242/api/query

Result ([rollups])

Step 4: Rollup

Note that the query result contains the rollupGranularity tag. This indicates that rollups are used for this query. In the query result, you can also find the operator that is used for scanning data points.