Search in sources :

Example 6 with MetricTagValue

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());
    }
}
Also used : MetricTagValue(io.cdap.cdap.proto.MetricTagValue)

Example 7 with MetricTagValue

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();
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) TypeToken(com.google.common.reflect.TypeToken) MetricTagValue(io.cdap.cdap.proto.MetricTagValue) HttpResponse(io.cdap.common.http.HttpResponse) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) URL(java.net.URL)

Aggregations

MetricTagValue (io.cdap.cdap.proto.MetricTagValue)7 HttpResponse (io.cdap.common.http.HttpResponse)2 URL (java.net.URL)2 ImmutableList (com.google.common.collect.ImmutableList)1 TypeToken (com.google.common.reflect.TypeToken)1 TagValue (io.cdap.cdap.api.metrics.TagValue)1 FakeApp (io.cdap.cdap.client.app.FakeApp)1 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)1 MetricQueryResult (io.cdap.cdap.proto.MetricQueryResult)1 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)1 ServiceId (io.cdap.cdap.proto.id.ServiceId)1 HttpRequest (io.cdap.common.http.HttpRequest)1 List (java.util.List)1 Test (org.junit.Test)1