URLGenerate the Pre-Signed URL of Query Data Points
Last Updated:2020-07-20
Pre-signed URLs can be used to query data points on front end pages. Usage: The front end requests the server to generate a pre-signed URL and return it to the front end, which uses the URL to initiate ajax requests to query data points.
String METRIC = "cpu_idle"; // set the metric of tag to get
String FIELD = "temperature";
// build query objects
List<Query> queries = Arrays.asList(new Query() // create Query Objects
.withMetric(METRIC) // set the metric
.withField(FIELD) // set the domain name of the query, and query the default domain if not set
.withFilters(new Filters() // create Filters Objects
.withRelativeStart("5 seconds ago") // set the relative start time, here the setup is 5 seconds ago
.withRelativeEnd("1 second ago")) // set the relative end time, and terminate till the current time by default if not set
.withLimit(100) // set number limits of the return data points
.addAggregator(new Aggregator() // create Aggregator Objects
.withName(TsdbConstants.AGGREGATOR_NAME_SUM) // set the aggregator to Sum
.withSampling("1 second"))); // set the sampling
// get the pre-signed URL
URL url = tsdbClient.generatePresignedUrlForQueryDatapoints(queries, 120); // set the timeout for signature as 120s