当前位置: 首页>>代码示例>>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;未经允许,请勿转载。