本文整理匯總了Java中com.yammer.metrics.core.Timer類的典型用法代碼示例。如果您正苦於以下問題:Java Timer類的具體用法?Java Timer怎麽用?Java Timer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Timer類屬於com.yammer.metrics.core包,在下文中一共展示了Timer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getProperty
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
public static Property getProperty(final Property propertyOrNull, final Metric metric) {
if (propertyOrNull != null) {
return propertyOrNull;
} else {
// is null, find a default
if (metric instanceof Counter) {
return CounterProperty.COUNT;
} else if (metric instanceof Gauge) {
return GaugeProperty.VALUE_GAUGE;
} else if (metric instanceof Timer) {
return TimerProperty.MEDIAN;
} else if (metric instanceof Meter) {
return MeterProperty.FIVE_MINUTE_RATE;
} else if (metric instanceof Histogram) {
return HistogramProperty.MEDIAN;
} else {
throw new RuntimeException("Unexpected metric type: " + metric.getClass());
}
}
}
示例2: testFetchTimer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
@Test
public void testFetchTimer() throws Exception {
final MetricName name = new MetricName("gr", "t1", "h1");
Timer timer = metricsRegistry.newTimer(name, TimeUnit.SECONDS, TimeUnit.SECONDS);
timer.update(1, TimeUnit.SECONDS);
timer.update(1, TimeUnit.SECONDS);
timer.update(1, TimeUnit.SECONDS);
final MuninDataSourceFactory dataSourceFactory = new MuninDataSourceFactory();
Map<String, MuninGraph> graphs = new HashMap<String, MuninGraph>() {{
put("foo", new MuninGraph("foo", "gr", "t", asList(
dataSourceFactory.forMetric(name, null, null, new MuninDataSourceConfig()))));
}};
MetricsCommandProcessor sut = new MetricsCommandProcessor(metricsRegistry, new StaticMuninGraphProvider(graphs), hostname);
assertEquals(asList(
"h1__median.value 1",
"."
)
, sut.processCommand("fetch", asList("foo")));
}
示例3: processTimer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void processTimer(final MetricName name, final Timer timer, final Map context) throws Exception {
final Snapshot snapshot = timer.getSnapshot();
final Map subMetrics =
ImmutableMap
.builder()
.put("count", timer.count())
.put("median", snapshot.getMedian())
.put("75percentile", snapshot.get75thPercentile())
.put("95percentile", snapshot.get95thPercentile())
.put("99percentile", snapshot.get99thPercentile())
.build();
context.put(toString(name), subMetrics);
}
示例4: processTimer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
@Override
public void processTimer(MetricName name, Timer timer,
ConcurrentMap<String, org.apache.blur.thrift.generated.Metric> context) throws Exception {
org.apache.blur.thrift.generated.Metric metric = getMetric(name, context);
addMeter(metric, timer, context);
metric.putToStrMap("unit", timer.durationUnit().toString());
metric.putToDoubleMap("min", timer.min());
metric.putToDoubleMap("max", timer.max());
metric.putToDoubleMap("mean", timer.mean());
metric.putToDoubleMap("stdDev", timer.stdDev());
Snapshot snapshot = timer.getSnapshot();
metric.putToDoubleMap("median", snapshot.getMedian());
metric.putToDoubleMap("75%", snapshot.get75thPercentile());
metric.putToDoubleMap("95%", snapshot.get95thPercentile());
metric.putToDoubleMap("98%", snapshot.get98thPercentile());
metric.putToDoubleMap("99%", snapshot.get99thPercentile());
metric.putToDoubleMap("99.9%", snapshot.get999thPercentile());
}
示例5: processTimer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
@Override
public void processTimer(MetricName name, Timer timer, Context context) throws Exception {
MetricInfo info = context.getMetricInfo(name);
long time = context.getTime();
addMeterInfo(time, timer, info);
info.setMetaData("unit", timer.durationUnit().toString());
info.addNumber("min", timer.min());
info.addNumber("max", timer.max());
info.addNumber("mean", timer.mean());
info.addNumber("stdDev", timer.stdDev());
Snapshot snapshot = timer.getSnapshot();
info.addNumber("median", snapshot.getMedian());
info.addNumber("75%", snapshot.get75thPercentile());
info.addNumber("95%", snapshot.get95thPercentile());
info.addNumber("98%", snapshot.get98thPercentile());
info.addNumber("99%", snapshot.get99thPercentile());
info.addNumber("99.9%", snapshot.get999thPercentile());
}
示例6: processAll
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
/**
* @param metrics The metrics you want to process
* @return A string of table rows.
*/
public String processAll(Map<MetricName, Metric> metrics) {
StringBuilder sb = new StringBuilder();
for (Entry<MetricName, Metric> metric : metrics.entrySet()) {
if (metric.getValue() instanceof Metered) {
if (metric.getValue() instanceof Timer) {
processTimer(metric.getKey(), (Timer) metric.getValue(), sb);
} else {
processMeter(metric.getKey(), (Metered) metric.getValue(), sb);
}
} else if (metric.getValue() instanceof Counter) {
processCounter(metric.getKey(), (Counter) metric.getValue(), sb);
} else if (metric.getValue() instanceof Histogram) {
processHistogram(metric.getKey(), (Histogram) metric.getValue(), sb);
} else if (metric.getValue() instanceof Gauge) {
processGauge(metric.getKey(), (Gauge<?>) metric.getValue(), sb);
} else {
throw new IllegalStateException("Unknown metric " + metric);
}
}
return sb.toString();
}
示例7: copyIndexingMetricsToCounters
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
private void copyIndexingMetricsToCounters(Context context) {
final String COUNTER_GROUP = "HBase Indexer Metrics";
SortedMap<String, SortedMap<MetricName, Metric>> groupedMetrics = Metrics.defaultRegistry().groupedMetrics(
new IndexerMetricsUtil.IndexerMetricPredicate());
for (Entry<String, SortedMap<MetricName, Metric>> metricsGroupEntry : groupedMetrics.entrySet()) {
SortedMap<MetricName, Metric> metricsGroupMap = metricsGroupEntry.getValue();
for (Entry<MetricName, Metric> metricEntry : metricsGroupMap.entrySet()) {
MetricName metricName = metricEntry.getKey();
Metric metric = metricEntry.getValue();
String counterName = metricName.getType() + ": " + metricName.getName();
if (metric instanceof Counter) {
Counter counter = (Counter) metric;
context.getCounter(COUNTER_GROUP, counterName).increment(counter.count());
} else if (metric instanceof Meter) {
Meter meter = (Meter) metric;
context.getCounter(COUNTER_GROUP, counterName).increment(meter.count());
} else if (metric instanceof Timer) {
Timer timer = (Timer) metric;
context.getCounter(COUNTER_GROUP, counterName).increment((long) timer.sum());
}
}
}
}
示例8: processTimer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
public void processTimer(MetricName metricName, Timer timer, Context context) throws Exception {
final Snapshot snapshot = timer.getSnapshot();
Point.Builder pointbuilder = buildMetricsPointByMetricName(metricName, context);
pointbuilder.tag("metric_type", "timer");
pointbuilder.addField("count", timer.count());
pointbuilder.addField("meanRate", timer.meanRate());
pointbuilder.addField("1MinuteRate", timer.oneMinuteRate());
pointbuilder.addField("5MinuteRate", timer.fiveMinuteRate());
pointbuilder.addField("15MinuteRate", timer.fifteenMinuteRate());
pointbuilder.addField("max", timer.max());
pointbuilder.addField("mean", timer.mean());
pointbuilder.addField("min", timer.min());
pointbuilder.addField("stddev", timer.max());
pointbuilder.addField("sum", timer.sum());
pointbuilder.addField("median", snapshot.getMedian());
pointbuilder.addField("p75", snapshot.get75thPercentile());
pointbuilder.addField("p95", snapshot.get95thPercentile());
pointbuilder.addField("p98", snapshot.get98thPercentile());
pointbuilder.addField("p99", snapshot.get99thPercentile());
pointbuilder.addField("p999", snapshot.get999thPercentile());
addPoint(pointbuilder.build());
}
示例9: processTimer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
@Override
public void processTimer(final MetricName name, final Timer timer,
final PrintStream stream) {
processMeter(name, timer, stream);
final String durationUnit = abbrev(timer.durationUnit());
final Snapshot snapshot = timer.getSnapshot();
stream.printf(locale, " min = %,2.2f %s\n", timer.min(),
durationUnit);
stream.printf(locale, " max = %,2.2f %s\n", timer.max(),
durationUnit);
stream.printf(locale, " mean = %,2.2f %s\n", timer.mean(),
durationUnit);
stream.printf(locale, " stddev = %,2.2f %s\n",
timer.stdDev(), durationUnit);
stream.printf(locale, " median = %,2.2f %s\n",
snapshot.getMedian(), durationUnit);
stream.printf(locale, " 75%% <= %,2.2f %s\n",
snapshot.get75thPercentile(), durationUnit);
stream.printf(locale, " 95%% <= %,2.2f %s\n",
snapshot.get95thPercentile(), durationUnit);
stream.printf(locale, " 98%% <= %,2.2f %s\n",
snapshot.get98thPercentile(), durationUnit);
stream.printf(locale, " 99%% <= %,2.2f %s\n",
snapshot.get99thPercentile(), durationUnit);
stream.printf(locale, " 99.9%% <= %,2.2f %s\n",
snapshot.get999thPercentile(), durationUnit);
}
示例10: processTimer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
@Override
public void processTimer(MetricName name, Timer timer, Long epoch) throws IOException {
processMeter(name, timer, epoch);
final String sanitizedName = sanitizeName(name);
sendSummarizable(epoch, sanitizedName, timer);
sendSampling(epoch, sanitizedName, timer);
}
示例11: processTimer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
@Override
public void processTimer(MetricName name, Timer timer, Long epoch) throws Exception {
processMeter(name, timer, epoch);
final String sanitizedName = sanitizeName(name);
sendSummarizable(sanitizedName, timer);
sendSampling(sanitizedName, timer);
}
示例12: timer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
@Test
public final void timer() throws Exception {
addMetricAndRunReporter(
new Callable<Timer>() {
@Override
public Timer call() throws Exception {
return createTimer();
}
});
verifyTimer();
}
示例13: createTimer
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
static Timer createTimer() throws Exception {
final Timer mock = mock(Timer.class);
when(mock.durationUnit()).thenReturn(TimeUnit.MILLISECONDS);
setupSummarizableMock(mock);
setupMeteredMock(mock);
setupSamplingMock(mock);
return configureMatcher(mock, doAnswer(new MetricsProcessorAction() {
@Override
void delegateToProcessor(MetricProcessor<Object> processor, MetricName name, Object context) throws Exception {
processor.processTimer(name, mock, context);
}
}));
}
示例14: time
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
public List<TimerContext> time(final Object param) {
Timer timer = timers.get(param);
if (timer == null) {
final MetricName name = paramMetricName.name(param);
timer = registry.newTimer(name, durationUnit, timeUnit);
final Timer existingTimer = timers.putIfAbsent(param, timer);
if (existingTimer != null) {
timer = existingTimer;
}
}
return of(timer.time(), allTimer.time());
}
示例15: around
import com.yammer.metrics.core.Timer; //導入依賴的package包/類
@Around(value = "timeChecked()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
MetricsRegistry registry = Metrics.defaultRegistry();
Timer timer = registry.newTimer(joinPoint.getThis().getClass(), joinPoint.getSignature().getName());
TimerContext time = timer.time();
try {
return joinPoint.proceed();
} finally {
time.stop();
}
}