當前位置: 首頁>>代碼示例>>Java>>正文


Java Timer.update方法代碼示例

本文整理匯總了Java中com.codahale.metrics.Timer.update方法的典型用法代碼示例。如果您正苦於以下問題:Java Timer.update方法的具體用法?Java Timer.update怎麽用?Java Timer.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.codahale.metrics.Timer的用法示例。


在下文中一共展示了Timer.update方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMetricEncode

import com.codahale.metrics.Timer; //導入方法依賴的package包/類
/**
 * Tests encoding of a Metric object.
 */
@Test
public void testMetricEncode() {
    Counter counter = new Counter();
    Meter meter = new Meter();
    Timer timer = new Timer();

    counter.inc();
    meter.mark();
    timer.update(1, TimeUnit.MILLISECONDS);

    ObjectNode counterJson = metricCodec.encode(counter, context);
    assertThat(counterJson.get("counter"), matchesMetric(counter));

    ObjectNode meterJson = metricCodec.encode(meter, context);
    assertThat(meterJson.get("meter"), matchesMetric(meter));

    ObjectNode timerJson = metricCodec.encode(timer, context);
    assertThat(timerJson.get("timer"), matchesMetric(timer));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:23,代碼來源:MetricCodecTest.java

示例2: onCallbackComplete

import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public void onCallbackComplete(Operation operation) {
  Long startTime = removeObjectProperty(operation, OPERATION_PROPERTY_NAME);
  if (startTime == null) {
    return;//re-entrant
  }

  String op = Operations.getOperationName(operation);

  long t = clock.getTick() - startTime;
  Timer timer = opVsTimer.computeIfAbsent(op, s -> {
    String metricName = ROOT_NAME.withTags("command", op).toString();
    return RegistryService.getMetricRegistry().timer(metricName);
  });
  timer.update(t, TimeUnit.NANOSECONDS);

}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:17,代碼來源:SpymemcachedRuleHelper.java

示例3: onResponseReceived

import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public void onResponseReceived(HttpRequest request, HttpResponse response) {
  Long startTime = removeObjectProperty(request, START_TIME_PROPERTY_NAME);
  if (startTime == null) {
    return;
  }

  long t = Clock.defaultClock().getTick() - startTime;

  String method = request.getRequestLine().getMethod();
  int statusCode = response.getStatusLine().getStatusCode();

  String metricName = ROOT_NAME.withTags(
      "method", method,
      "status", "" + statusCode).toString();
  Timer timer = RegistryService.getMetricRegistry().timer(metricName);
  timer.update(t, TimeUnit.NANOSECONDS);

}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:19,代碼來源:HttpAsyncClientRuleHelper.java

示例4: onGetInputStream

import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public void onGetInputStream(HttpURLConnection urlConnection, int statusCode) {
  Long startTime = removeObjectProperty(urlConnection, START_TIME_PROPERTY_NAME);
  if (startTime == null) {
    return;
  }

  long t = Clock.defaultClock().getTick() - startTime;
  String method = urlConnection.getRequestMethod();
  String status = "" + statusCode;
  Timer timer = timers.computeIfAbsent(status + method, s -> {
    TagEncodedMetricName metricName = ROOT_NAME.withTags(
        "method", method,
        "status", status);
    return getTimer(metricName);
  });

  timer.update(t, TimeUnit.NANOSECONDS);
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:19,代碼來源:UrlConnectionRuleHelper.java

示例5: stop

import com.codahale.metrics.Timer; //導入方法依賴的package包/類
public static void stop(OperationId id, Supplier<Timer> timerSupplier) {
  OperationId lastId = lastId();
  if (lastId != id) {
    //TODO better error handling
    LOGGER.error("Operation Context Mismatch. Expected: " + id + " got " + lastId);
    return;
  }

  OperationContext context = CONTEXT_STACK.get().pop();
  if (context == RENTRANT) {
    return;
  }

  Timer timer = timerSupplier.get();
  if (timer != null) {
    long t = clock.getTick() - context.getStartTime();
    timer.update(t, TimeUnit.NANOSECONDS);
  }
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:20,代碼來源:RuleHelper.java

示例6: testFromTimer

import com.codahale.metrics.Timer; //導入方法依賴的package包/類
@Test
public void testFromTimer() {
  final Set<String> fieldKeys = ImmutableSet.of(
    "count",
    "min",
    "max",
    "mean",
    "std-dev",
    "50-percentile",
    "75-percentile",
    "95-percentile",
    "99-percentile",
    "999-percentile",
    "one-minute",
    "five-minute",
    "fifteen-minute",
    "mean-minute",
    "run-count"
  );
  
  final DropwizardMeasurementParser parser = mock(DropwizardMeasurementParser.class);
  final DropwizardTransformer transformer = transformerWithParser(parser, true);

  when(parser.parse("some.metric.name")).thenReturn(
    DropwizardMeasurement.create("Measurement", MEASUREMENT_TAGS, Optional.empty())
  );

  final Timer timer = new Timer();
  timer.update(50, TimeUnit.MILLISECONDS);
  timer.update(70, TimeUnit.MILLISECONDS);
  timer.update(100, TimeUnit.MILLISECONDS);
  
  final InfluxDbMeasurement measurement = transformer.fromTimer("some.metric.name", timer, 90210L);
  assertEquals("should parse name from full metric key", "Measurement", measurement.name());
  assertEquals("should add global and measurement tags", ALL_TAGS, measurement.tags());
  assertEquals("should timestamp measurement", 90210L, measurement.timestamp());
  assertEquals("should add all timer fields", fieldKeys, measurement.fields().keySet());
}
 
開發者ID:kickstarter,項目名稱:dropwizard-influxdb-reporter,代碼行數:39,代碼來源:DropwizardTransformerTest.java

示例7: testGetAllMetrics

import com.codahale.metrics.Timer; //導入方法依賴的package包/類
/**
 * Tests GetAllMetrics method.
 */
@Test
public void testGetAllMetrics() {
    Counter onosCounter = new Counter();
    onosCounter.inc();

    Meter onosMeter = new Meter();
    onosMeter.mark();

    Timer onosTimer = new Timer();
    onosTimer.update(1, TimeUnit.MILLISECONDS);

    ImmutableMap<String, Metric> metrics =
            new ImmutableMap.Builder<String, Metric>()
                    .put("onosCounter", onosCounter)
                    .put("onosMeter", onosMeter)
                    .put("onosTimer", onosTimer)
                    .build();

    expect(mockMetricsService.getMetrics())
            .andReturn(metrics)
            .anyTimes();

    replay(mockMetricsService);

    WebTarget wt = target();
    String response = wt.path("metrics").request().get(String.class);
    assertThat(response, containsString("{\"metrics\":["));

    JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    JsonArray jsonMetrics = result.get("metrics").asArray();
    assertThat(jsonMetrics, notNullValue());
    assertThat(jsonMetrics.size(), is(3));

    assertTrue(matchesMetric(metrics.get("onosCounter")).matchesSafely(jsonMetrics.get(0).asObject()));
    assertTrue(matchesMetric(metrics.get("onosMeter")).matchesSafely(jsonMetrics.get(1).asObject()));
    assertTrue(matchesMetric(metrics.get("onosTimer")).matchesSafely(jsonMetrics.get(2).asObject()));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:43,代碼來源:MetricsResourceTest.java

示例8: testTimerUpdate

import com.codahale.metrics.Timer; //導入方法依賴的package包/類
@Test
public void testTimerUpdate() throws Exception {
  Timer a = registry.timer("A");
  a.update(1, TimeUnit.MILLISECONDS);
  assertEquals(a, updatedMetric);
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:7,代碼來源:TracingMetricRegistryTest.java


注:本文中的com.codahale.metrics.Timer.update方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。