use of io.cdap.cdap.proto.MetricTagValue in project cdap by caskdata.
the class SearchMetricTagsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
Map<String, String> tags = ArgumentParser.parseMap(arguments.getOptional("tags", ""), "<tags>");
List<MetricTagValue> results = client.searchTags(tags);
for (MetricTagValue result : results) {
output.printf("%s=%s\n", result.getName(), result.getValue());
}
}
use of io.cdap.cdap.proto.MetricTagValue in project cdap by caskdata.
the class MetricsClient method searchTags.
/**
* Searches for metrics tags matching the given tags.
*
* @param tags the tags to match
* @return the metrics matching the given tags
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<MetricTagValue> searchTags(Map<String, String> tags) throws IOException, UnauthenticatedException, UnauthorizedException {
List<String> queryParts = Lists.newArrayList();
queryParts.add("target=tag");
addTags(tags, queryParts);
URL url = config.resolveURLV3(String.format("metrics/search?%s", Joiner.on("&").join(queryParts)));
// Required to add body even if runtimeArgs is null to avoid 411 error for Http POST
HttpRequest.Builder request = HttpRequest.post(url).withBody("");
HttpResponse response = restClient.execute(request.build(), config.getAccessToken());
ObjectResponse<List<MetricTagValue>> result = ObjectResponse.fromJsonBody(response, new TypeToken<List<MetricTagValue>>() {
}.getType());
return result.getResponseObject();
}
Aggregations