com.netflix.servo.monitor.Stopwatch Java Examples
The following examples show how to use
com.netflix.servo.monitor.Stopwatch.
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: NFHttpClient.java From ribbon with Apache License 2.0 | 6 votes |
@Override public <T> T execute( final HttpHost target, final HttpRequest request, final ResponseHandler<? extends T> responseHandler, final HttpContext context) throws IOException, ClientProtocolException { Stopwatch sw = tracer.start(); try{ // TODO: replaced method.getQueryString() with request.getRequestLine().getUri() LOGGER.debug("Executing HTTP method: {}, uri: {}", request.getRequestLine().getMethod(), request.getRequestLine().getUri()); return super.execute(target, request, responseHandler, context); }finally{ sw.stop(); } }
Example #2
Source File: MetricTypeManualTest.java From tutorials with MIT License | 6 votes |
@Test public void givenTimer_whenExecuteTask_thenTimerUpdated() throws Exception { BasicTimer timer = new BasicTimer(MonitorConfig .builder("test") .build(), MILLISECONDS); Stopwatch stopwatch = timer.start(); SECONDS.sleep(1); timer.record(2, SECONDS); stopwatch.stop(); assertEquals("timer should count 1 second", 1000, timer .getValue() .intValue(),1000); assertEquals("timer should count 3 second in total", 3000, timer.getTotalTime() .intValue(),1000); assertEquals("timer should record 2 updates", 2, timer .getCount() .intValue()); assertEquals("timer should have max 2", 2000, timer.getMax(), 0.01); }
Example #3
Source File: Monitors.java From conductor with Apache License 2.0 | 5 votes |
private static Stopwatch start(Timer sm) { Stopwatch sw = new BasicStopwatch() { @Override public void stop() { super.stop(); long duration = getDuration(TimeUnit.MILLISECONDS); sm.record(duration, TimeUnit.MILLISECONDS); } }; sw.start(); return sw; }
Example #4
Source File: NamedConnectionPool.java From ribbon with Apache License 2.0 | 5 votes |
@Override protected BasicPoolEntry createEntry(RouteSpecificPool rospl, ClientConnectionOperator op) { createEntryCounter.increment(); Stopwatch stopWatch = creationTimer.start(); try { return super.createEntry(rospl, op); } finally { stopWatch.stop(); } }
Example #5
Source File: NamedConnectionPool.java From ribbon with Apache License 2.0 | 5 votes |
@Override protected BasicPoolEntry getEntryBlocking(HttpRoute route, Object state, long timeout, TimeUnit tunit, WaitingThreadAborter aborter) throws ConnectionPoolTimeoutException, InterruptedException { Stopwatch stopWatch = requestTimer.start(); try { return super.getEntryBlocking(route, state, timeout, tunit, aborter); } finally { stopWatch.stop(); } }
Example #6
Source File: PrimeConnections.java From ribbon with Apache License 2.0 | 5 votes |
/** * Prime connections, blocking until configured percentage (default is 100%) of target servers are primed * or max time is reached. * * @see CommonClientConfigKey#MinPrimeConnectionsRatio * @see CommonClientConfigKey#MaxTotalTimeToPrimeConnections * */ public void primeConnections(List<Server> servers) { if (servers == null || servers.size() == 0) { logger.debug("No server to prime"); return; } for (Server server: servers) { server.setReadyToServe(false); } int totalCount = (int) (servers.size() * primeRatio); final CountDownLatch latch = new CountDownLatch(totalCount); final AtomicInteger successCount = new AtomicInteger(0); final AtomicInteger failureCount= new AtomicInteger(0); primeConnectionsAsync(servers, new PrimeConnectionListener() { @Override public void primeCompleted(Server s, Throwable lastException) { if (lastException == null) { successCount.incrementAndGet(); s.setReadyToServe(true); } else { failureCount.incrementAndGet(); } latch.countDown(); } }); Stopwatch stopWatch = initialPrimeTimer.start(); try { latch.await(maxTotalTimeToPrimeConnections, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { logger.error("Priming connection interrupted", e); } finally { stopWatch.stop(); } stats = new PrimeConnectionEndStats(totalCount, successCount.get(), failureCount.get(), stopWatch.getDuration(TimeUnit.MILLISECONDS)); printStats(stats); }
Example #7
Source File: MetricTypeManualTest.java From tutorials with MIT License | 5 votes |
@Test public void givenStatsTimer_whenExecuteTask_thenStatsCalculated() throws Exception { System.setProperty("netflix.servo", "1000"); StatsTimer timer = new StatsTimer(MonitorConfig .builder("test") .build(), new StatsConfig.Builder() .withComputeFrequencyMillis(2000) .withPercentiles(new double[]{99.0, 95.0, 90.0}) .withPublishMax(true) .withPublishMin(true) .withPublishCount(true) .withPublishMean(true) .withPublishStdDev(true) .withPublishVariance(true) .build(), MILLISECONDS); Stopwatch stopwatch = timer.start(); SECONDS.sleep(1); timer.record(3, SECONDS); stopwatch.stop(); stopwatch = timer.start(); timer.record(6, SECONDS); SECONDS.sleep(2); stopwatch.stop(); assertEquals("timer should count 12 seconds in total", 12000, timer.getTotalTime(),500); assertEquals("timer should count 12 seconds in total", 12000, timer.getTotalMeasurement(),500); assertEquals("timer should record 4 updates", 4, timer.getCount()); assertEquals("stats timer value time-cost/update should be 2", 3000, timer .getValue() .intValue(),500); final Map<String, Number> metricMap = timer .getMonitors() .stream() .collect(toMap(monitor -> getMonitorTagValue(monitor, "statistic"), monitor -> (Number) monitor.getValue())); assertThat(metricMap.keySet(), containsInAnyOrder("count", "totalTime", "max", "min", "variance", "stdDev", "avg", "percentile_99", "percentile_95", "percentile_90")); }
Example #8
Source File: Monitors.java From conductor with Apache License 2.0 | 4 votes |
public static Stopwatch start(String className, String name, String... additionalTags) { return start(getTimer(className, name, additionalTags)); }