com.yammer.metrics.core.Timer Java Examples
The following examples show how to use
com.yammer.metrics.core.Timer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScheduledReporterTest.java From ambari-metrics with Apache License 2.0 | 6 votes |
private Set<Entry<MetricName, Metric>> set(List<Metric> metrics) { final Map<MetricName, Metric> map = new HashMap<MetricName, Metric>(); for (Metric metric : metrics) { String name = null; if (metric instanceof Gauge) { name = "gauge"; } else if (metric instanceof Counter) { name = "counter"; } else if (metric instanceof Histogram) { name = "histogram"; } else if (metric instanceof Meter) { name = "meter"; } else if (metric instanceof Timer) { name = "timer"; } map.put(new MetricName(System.class, name), metric); } return map.entrySet(); }
Example #2
Source File: HBaseIndexerMapper.java From hbase-indexer with Apache License 2.0 | 6 votes |
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()); } } } }
Example #3
Source File: MemoryReporter.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@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()); }
Example #4
Source File: JSONReporter.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@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()); }
Example #5
Source File: YammerFacadeMetric.java From storm-metrics-reporter with Apache License 2.0 | 6 votes |
@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); }
Example #6
Source File: CustomReporter.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@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); }
Example #7
Source File: KafkaTimelineMetricsReporter.java From ambari-metrics with Apache License 2.0 | 5 votes |
@Override public void processTimer(MetricName name, Timer timer, Context context) throws Exception { final long currentTimeMillis = System.currentTimeMillis(); final Snapshot snapshot = timer.getSnapshot(); final String sanitizedName = sanitizeName(name); String[] metricMNames = cacheKafkaMetered(currentTimeMillis, sanitizedName, timer); String[] metricTNames = cacheKafkaSummarizable(currentTimeMillis, sanitizedName, timer); String[] metricSNames = cacheKafkaSnapshot(currentTimeMillis, sanitizedName, snapshot); String[] metricNames = (String[]) ArrayUtils.addAll(metricMNames, metricTNames); metricNames = (String[]) ArrayUtils.addAll(metricNames, metricSNames); populateMetricsList(context, MetricType.GAUGE, metricNames); }
Example #8
Source File: KafkaTimelineMetricsReporterTest.java From ambari-metrics with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { @SuppressWarnings({ "rawtypes", "unchecked" }) Gauge g = registry.newGauge(System.class, "gauge", gauge); Counter counter = registry.newCounter(System.class, "counter"); Histogram histogram = registry.newHistogram(System.class, "histogram"); Meter meter = registry.newMeter(System.class, "meter", "empty", TimeUnit.MILLISECONDS); Timer timer = registry.newTimer(System.class, "timer"); list.add(g); list.add(counter); list.add(histogram); list.add(meter); list.add(timer); Properties properties = new Properties(); properties.setProperty("zookeeper.connect", "localhost:2181"); properties.setProperty("kafka.timeline.metrics.sendInterval", "5900"); properties.setProperty("kafka.timeline.metrics.maxRowCacheSize", "10000"); properties.setProperty("kafka.timeline.metrics.hosts", "localhost:6188"); properties.setProperty("kafka.timeline.metrics.port", "6188"); properties.setProperty("kafka.timeline.metrics.reporter.enabled", "true"); properties.setProperty("external.kafka.metrics.exclude.prefix", "a.b.c"); properties.setProperty("external.kafka.metrics.include.prefix", "a.b.c.d"); properties.setProperty("external.kafka.metrics.include.regex", "a.b.c.*.f"); properties.setProperty("kafka.timeline.metrics.instanceId", "cluster"); properties.setProperty("kafka.timeline.metrics.set.instanceId", "false"); props = new VerifiableProperties(properties); }
Example #9
Source File: ScheduledReporterTest.java From ambari-metrics with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { Gauge g = registry.newGauge(System.class, "gauge", gauge); Counter counter = registry.newCounter(System.class, "counter"); Histogram histogram = registry.newHistogram(System.class, "histogram"); Meter meter = registry.newMeter(System.class, "meter", "empty", TimeUnit.MILLISECONDS); Timer timer = registry.newTimer(System.class, "timer"); list.add(g); list.add(counter); list.add(histogram); list.add(meter); list.add(timer); reporter.start(200, TimeUnit.MILLISECONDS); }
Example #10
Source File: CustomReporter.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@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); }
Example #11
Source File: StatsDReporterTest.java From kafka-statsd-metrics2 with Apache License 2.0 | 5 votes |
@Test public final void timer() throws Exception { addMetricAndRunReporter( new Callable<Timer>() { @Override public Timer call() throws Exception { return createTimer(); } }); verifyTimer(); }
Example #12
Source File: StatsDReporterTest.java From kafka-statsd-metrics2 with Apache License 2.0 | 5 votes |
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); } })); }
Example #13
Source File: YammerExample.java From signalfx-java with Apache License 2.0 | 5 votes |
private static Timer getTimer(MetricsRegistry metricsRegistry, MetricMetadata metricMetadata) { Timer timer = metricsRegistry .newTimer(YammerExample.class, "yammer.test.timer", TimeUnit.MILLISECONDS, TimeUnit.SECONDS); metricMetadata.forMetric(timer) .withSourceName(SIGNAL_FX) .withDimension(LIBRARY_VERSION, YAMMER); return timer; }
Example #14
Source File: CaliperMeasure.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
/** * Time meter. */ public Timer time() { return time; }
Example #15
Source File: StatementIteratorConsumer.java From Rhombus with MIT License | 4 votes |
protected void handle(CQLStatement statement) { String methodName = "NULL"; String cql = statement.getQuery(); int firstSpace = cql.indexOf(" "); if(firstSpace > 0) { methodName = cql.substring(0, firstSpace); } String timerName = "asyncExec." + methodName + "." + statement.getObjectName(); final Timer asyncExecTimer = Metrics.defaultRegistry().newTimer(StatementIteratorConsumer.class, timerName); final TimerContext asyncExecTimerContext = asyncExecTimer.time(); final long startTime = System.nanoTime(); ResultSetFuture future = null; try { future = this.cqlExecutor.executeAsync(statement); } catch (RuntimeException re) { logger.error("RuntimeException while executing statement {}\n {}", statement.getQuery(), re); shutdownLatch.countDown(); return; } futures.add(future); Futures.addCallback(future, new FutureCallback<ResultSet>() { @Override public void onSuccess(final ResultSet result) { Host queriedHost = result.getExecutionInfo().getQueriedHost(); Metrics.defaultRegistry().newMeter(StatementIteratorConsumer.class, "queriedhost." + queriedHost.getDatacenter(), queriedHost.getDatacenter(), TimeUnit.SECONDS).mark(); asyncExecTimerContext.stop(); logger.debug("Async exec time {}us", (System.nanoTime() - startTime) / 1000); shutdownLatch.countDown(); } @Override public void onFailure(final Throwable t) { asyncExecTimerContext.stop(); logger.debug("Async failure time {}us", (System.nanoTime() - startTime) / 1000); executionExceptions.add(t); shutdownLatch.countDown(); } } , executorService ); }
Example #16
Source File: AggregateMetricSenderSessionWrapper.java From signalfx-java with Apache License 2.0 | 4 votes |
void addTimer(MetricName key, Timer value) { addMetered(key, value); addSampling(key, value); }
Example #17
Source File: YammerExample.java From signalfx-java with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { System.out.println("Running example..."); Properties prop = new Properties(); prop.load(new FileInputStream("auth.properties")); final String auth_token = prop.getProperty("auth"); final String hostUrlStr = prop.getProperty("host"); final URL hostUrl = new URL(hostUrlStr); System.out.println("Auth=" + auth_token + " .. host=" + hostUrl); SignalFxReceiverEndpoint endpoint = new SignalFxEndpoint(hostUrl.getProtocol(), hostUrl.getHost(), hostUrl.getPort()); MetricsRegistry metricsRegistry = new MetricsRegistry(); SignalFxReporter reporter = new SignalFxReporter.Builder(metricsRegistry, new StaticAuthToken(auth_token), hostUrlStr).setEndpoint(endpoint) .setOnSendErrorHandlerCollection( Collections.<OnSendErrorHandler>singleton(new OnSendErrorHandler() { public void handleError(MetricError error) { System.out.println("" + error.getMessage()); } })) .setDetailsToAdd(ImmutableSet.of(SignalFxReporter.MetricDetails.COUNT, SignalFxReporter.MetricDetails.MIN, SignalFxReporter.MetricDetails.MAX)) .build(); final MetricMetadata metricMetadata = reporter.getMetricMetadata(); Counter counter = getCounter(metricsRegistry, metricMetadata); Metric cumulativeCounter = getCumulativeCounter(metricsRegistry, metricMetadata); Gauge gauge1 = getGauge(metricsRegistry, metricMetadata); Timer timer = getTimer(metricsRegistry, metricMetadata); // main body generating data and sending it in a loop while (true) { final TimerContext context = timer.time(); try { System.out.println("Sending data..."); Thread.sleep(500); counter.inc(); } finally { context.stop(); } reporter.report(); // Report all metrics } }
Example #18
Source File: StormYammerMetricsAdapter.java From storm-metrics-reporter with Apache License 2.0 | 4 votes |
/** * See {@link com.yammer.metrics.core.MetricsRegistry#newTimer} */ public Timer createTimer(final String component, final String methodName) { return metricsRegistry.newTimer(getMetricName(component, methodName), TimeUnit.MILLISECONDS, TimeUnit.SECONDS); }
Example #19
Source File: CaliperMeasure.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
/** * Time meter. */ public Timer time() { return time; }
Example #20
Source File: YammerMetricProcessor.java From cruise-control with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void processTimer(MetricName metricName, Timer timer, Context context) { if (MetricsUtils.isInterested(metricName)) { LOG.trace("Processing metric {} of type Timer.", metricName); CruiseControlMetric ccm = MetricsUtils.toCruiseControlMetric(context.time(), context.brokerId(), metricName, timer.fiveMinuteRate()); context.reporter().sendCruiseControlMetric(ccm); // Get max metric value ccm = MetricsUtils.toCruiseControlMetric(context.time(), context.brokerId(), metricName, timer.max(), MetricsUtils.ATTRIBUTE_MAX); context.reporter().sendCruiseControlMetric(ccm); // Get mean metric value ccm = MetricsUtils.toCruiseControlMetric(context.time(), context.brokerId(), metricName, timer.mean(), MetricsUtils.ATTRIBUTE_MEAN); context.reporter().sendCruiseControlMetric(ccm); Snapshot snapshot = timer.getSnapshot(); // Get 50th percentile (i.e. median) metric value ccm = MetricsUtils.toCruiseControlMetric(context.time(), context.brokerId(), metricName, snapshot.getMedian(), MetricsUtils.ATTRIBUTE_50TH_PERCENTILE); context.reporter().sendCruiseControlMetric(ccm); // Get 999th percentile metric value ccm = MetricsUtils.toCruiseControlMetric(context.time(), context.brokerId(), metricName, snapshot.get999thPercentile(), MetricsUtils.ATTRIBUTE_999TH_PERCENTILE); context.reporter().sendCruiseControlMetric(ccm); } }
Example #21
Source File: MetricsHelper.java From incubator-pinot with Apache License 2.0 | 3 votes |
/** * * Return an existing timer if * (a) A timer already exist with the same metric name. * Otherwise, creates a new timer and registers * * @param registry MetricsRegistry * @param name metric name * @param durationUnit TimeUnit for duration * @param rateUnit TimeUnit for rate determination * @return Timer */ public static Timer newTimer(MetricsRegistry registry, MetricName name, TimeUnit durationUnit, TimeUnit rateUnit) { if (registry != null) { return registry.newTimer(name, durationUnit, rateUnit); } else { return Metrics.newTimer(name, durationUnit, rateUnit); } }
Example #22
Source File: ValidatingMetricProcessor.java From kafka-graphite with Apache License 2.0 | 2 votes |
@Override public void processTimer(MetricName name, Timer timer, Object context) throws Exception { }
Example #23
Source File: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 2 votes |
/** * get all Timers metrics * @param filter * @return */ private SortedMap<MetricName, Timer> getTimers(MetricPredicate filter) { return getMetrics(Timer.class, filter); }
Example #24
Source File: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 2 votes |
/** * Called periodically by the polling thread. Subclasses should report all the given metrics. * * @param gauges all of the gauges in the registry * @param counters all of the counters in the registry * @param histograms all of the histograms in the registry * @param meters all of the meters in the registry * @param timers all of the timers in the registry */ public abstract void report(SortedMap<MetricName, Gauge> gauges, SortedMap<MetricName, Counter> counters, SortedMap<MetricName, Histogram> histograms, SortedMap<MetricName, Meter> meters, SortedMap<MetricName, Timer> timers);
Example #25
Source File: BcryptCommandTest.java From usergrid with Apache License 2.0 | 2 votes |
/** * Tests bcrypt hashing with a default number of rounds. Note that via the console output, this test should take * about 5 seconds to run since we want to force 500 ms per authentication attempt with bcrypt */ @Test public void testHashRoundSpeed() throws UnsupportedEncodingException { int cryptIterations = 2 ^ 11; int numberOfTests = 10; BcryptCommand command = new BcryptCommand(); command.setDefaultIterations( cryptIterations ); String baseString = "I am a test password for hashing"; CredentialsInfo info = new CredentialsInfo(); UUID user = UUID.randomUUID(); UUID applicationId = UUID.randomUUID(); byte[] result = command.hash( baseString.getBytes( "UTF-8" ), info, user, applicationId ); String stringResults = encodeBase64URLSafeString( result ); info.setSecret( stringResults ); Timer timer = Metrics.newTimer( BcryptCommandTest.class, "hashtimer" ); for ( int i = 0; i < numberOfTests; i++ ) { TimerContext timerCtx = timer.time(); //now check we can auth with the same phrase byte[] authed = command.auth( baseString.getBytes( "UTF-8" ), info, user, applicationId ); timerCtx.stop(); assertArrayEquals( result, authed ); } /** * Print out the data */ ConsoleReporter reporter = new ConsoleReporter( Metrics.defaultRegistry(), System.out, MetricPredicate.ALL ); reporter.run(); }