本文整理汇总了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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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());
}
示例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()));
}
示例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);
}