Search in sources :

Example 1 with MetricTagValue

use of co.cask.cdap.proto.MetricTagValue in project cdap by caskdata.

the class MetricsQueryHelper method tagValuesToHuman.

private List<MetricTagValue> tagValuesToHuman(Collection<TagValue> tagValues) {
    List<MetricTagValue> result = Lists.newArrayList();
    for (TagValue tagValue : tagValues) {
        String human = tagNameToHuman.get(tagValue.getName());
        human = human != null ? human : tagValue.getName();
        String value = tagValue.getValue() == null ? ANY_TAG_VALUE : tagValue.getValue();
        result.add(new MetricTagValue(human, value));
    }
    return result;
}
Also used : MetricTagValue(co.cask.cdap.proto.MetricTagValue) MetricTagValue(co.cask.cdap.proto.MetricTagValue) TagValue(co.cask.cdap.api.metrics.TagValue)

Example 2 with MetricTagValue

use of co.cask.cdap.proto.MetricTagValue in project cdap by caskdata.

the class MetricsQueryHelper method humanToTagNames.

private List<MetricTagValue> humanToTagNames(List<MetricTagValue> tagValues) {
    List<MetricTagValue> result = Lists.newArrayList();
    for (MetricTagValue tagValue : tagValues) {
        String tagName = humanToTagName(tagValue.getName());
        result.add(new MetricTagValue(tagName, tagValue.getValue()));
    }
    return result;
}
Also used : MetricTagValue(co.cask.cdap.proto.MetricTagValue)

Example 3 with MetricTagValue

use of co.cask.cdap.proto.MetricTagValue in project cdap by caskdata.

the class MetricsClientTestRun method testAll.

@Test
public void testAll() throws Exception {
    appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class));
    ApplicationId app = NamespaceId.DEFAULT.app(FakeApp.NAME);
    ProgramId flow = app.flow(FakeFlow.NAME);
    StreamId stream = NamespaceId.DEFAULT.stream(FakeApp.STREAM_NAME);
    try {
        programClient.start(flow);
        streamClient.sendEvent(stream, "hello world");
        // TODO: remove arbitrary sleep
        TimeUnit.SECONDS.sleep(5);
        FlowletId flowletId = flow.flowlet(FakeFlow.FLOWLET_NAME);
        MetricQueryResult result = metricsClient.query(MetricsTags.flowlet(flowletId), Constants.Metrics.Name.Flow.FLOWLET_INPUT);
        Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
        result = metricsClient.query(MetricsTags.flowlet(flowletId), ImmutableList.of(Constants.Metrics.Name.Flow.FLOWLET_INPUT), ImmutableList.<String>of(), ImmutableMap.of("aggregate", "true"));
        Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
        result = metricsClient.query(MetricsTags.flowlet(flowletId), ImmutableList.of(Constants.Metrics.Name.Flow.FLOWLET_INPUT), ImmutableList.<String>of(), ImmutableMap.of("start", "now-20s", "end", "now"));
        Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
        List<MetricTagValue> tags = metricsClient.searchTags(MetricsTags.flowlet(flowletId));
        Assert.assertEquals(1, tags.size());
        Assert.assertEquals("run", tags.get(0).getName());
        List<String> metrics = metricsClient.searchMetrics(MetricsTags.flowlet(flowletId));
        Assert.assertTrue(metrics.contains(Constants.Metrics.Name.Flow.FLOWLET_INPUT));
    } finally {
        programClient.stop(flow);
        assertProgramRuns(programClient, flow, ProgramRunStatus.KILLED, 1, 10);
        appClient.delete(app);
    }
}
Also used : FakeApp(co.cask.cdap.client.app.FakeApp) StreamId(co.cask.cdap.proto.id.StreamId) FlowletId(co.cask.cdap.proto.id.FlowletId) MetricTagValue(co.cask.cdap.proto.MetricTagValue) MetricQueryResult(co.cask.cdap.proto.MetricQueryResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 4 with MetricTagValue

use of co.cask.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(co.cask.cdap.proto.MetricTagValue)

Example 5 with MetricTagValue

use of co.cask.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)));
    HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken());
    ObjectResponse<List<MetricTagValue>> result = ObjectResponse.fromJsonBody(response, new TypeToken<List<MetricTagValue>>() {
    }.getType());
    return result.getResponseObject();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) MetricTagValue(co.cask.cdap.proto.MetricTagValue) HttpResponse(co.cask.common.http.HttpResponse) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) URL(java.net.URL)

Aggregations

MetricTagValue (co.cask.cdap.proto.MetricTagValue)7 TagValue (co.cask.cdap.api.metrics.TagValue)1 FakeApp (co.cask.cdap.client.app.FakeApp)1 MetricQueryResult (co.cask.cdap.proto.MetricQueryResult)1 ApplicationId (co.cask.cdap.proto.id.ApplicationId)1 FlowletId (co.cask.cdap.proto.id.FlowletId)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 StreamId (co.cask.cdap.proto.id.StreamId)1 HttpResponse (co.cask.common.http.HttpResponse)1 ImmutableList (com.google.common.collect.ImmutableList)1 TypeToken (com.google.common.reflect.TypeToken)1 URL (java.net.URL)1 List (java.util.List)1 Test (org.junit.Test)1