com.netflix.servo.monitor.Stopwatch.stop()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中com.netflix.servo.monitor.Stopwatch.stop()方法的一些代码示例,展示了Stopwatch.stop()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Stopwatch.stop()方法的具体详情如下:
包路径:com.netflix.servo.monitor.Stopwatch
类名称:Stopwatch
方法名:stop

Stopwatch.stop介绍

[英]Mark the end time.
[中]标记结束时间。

代码示例

代码示例来源:origin: Netflix/eureka

public Value(String payload) {
  this.payload = payload;
  if (!EMPTY_PAYLOAD.equals(payload)) {
    Stopwatch tracer = compressPayloadTimer.start();
    try {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      GZIPOutputStream out = new GZIPOutputStream(bos);
      byte[] rawBytes = payload.getBytes();
      out.write(rawBytes);
      // Finish creation of gzip file
      out.finish();
      out.close();
      bos.close();
      gzipped = bos.toByteArray();
    } catch (IOException e) {
      gzipped = null;
    } finally {
      if (tracer != null) {
        tracer.stop();
      }
    }
  } else {
    gzipped = null;
  }
}

代码示例来源:origin: Netflix/eureka

@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();
  }
}

代码示例来源:origin: Netflix/servo

@Override
 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
  // if the method is one of the CompositeMonitor interface
  final Class<?> declaringClass = method.getDeclaringClass();
  if (declaringClass.isAssignableFrom(CompositeMonitor.class)) {
   return method.invoke(this, args);
  }
  final String methodName = method.getName();
  final Timer timer = timers.get(methodName);
  final Stopwatch stopwatch = timer.start();
  try {
   return method.invoke(concrete, args);
  } finally {
   stopwatch.stop();
  }
 }
}

代码示例来源:origin: Netflix/eureka

/**
 * Queries AWS to see if the load balancer flag is suspended.
 *
 * @param asgAccountid the accountId this asg resides in, if applicable (null will use the default accountId)
 * @param asgName the name of the asg
 * @return true, if the load balancer flag is not suspended, false otherwise.
 */
private Boolean isASGEnabledinAWS(String asgAccountid, String asgName) {
  try {
    Stopwatch t = this.loadASGInfoTimer.start();
    boolean returnValue = !isAddToLoadBalancerSuspended(asgAccountid, asgName);
    t.stop();
    return returnValue;
  } catch (Throwable e) {
    logger.error("Could not get ASG information from AWS: ", e);
  }
  return Boolean.TRUE;
}

代码示例来源:origin: Netflix/eureka

@Override
protected BasicPoolEntry createEntry(RouteSpecificPool rospl,
                   ClientConnectionOperator op) {
  createEntryCounter.increment();
  Stopwatch stopWatch = creationTimer.start();
  try {
    return super.createEntry(rospl, op);
  } finally {
    stopWatch.stop();
  }
}

代码示例来源:origin: Netflix/EVCache

public long incr(String key, long by, long def, int exp) {
  final Stopwatch operationDuration = getTimer(INCR_OPERATION_STRING).start();
  long val = 0;
  try {
    val = mutate(Mutator.incr, key, by, def, exp);
  } finally {
    operationDuration.stop();
    if (log.isDebugEnabled()) log.debug("Increment Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp 
        + "; val : " + val + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS));
  }
  return val;
}

代码示例来源:origin: Netflix/EVCache

public long decr(String key, long by, long def, int exp) {
  final Stopwatch operationDuration = getTimer(DECR_OPERATION_STRING).start();
  long val = 0;
  try {
    val = super.decr(key, by, def, exp);
  } finally {
    operationDuration.stop();
    if (log.isDebugEnabled()) log.debug("decrement Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp 
        + "; val : " + val + "; Elapsed Time - " + (operationDuration.getDuration(TimeUnit.MILLISECONDS)));
  }
  return val;
}

代码示例来源:origin: Netflix/eureka

public void cleanIdle(long delayMs) {
    Stopwatch start = executionTimeStats.start();
    try {
      apacheHttpClient.getClientHandler().getHttpClient()
          .getConnectionManager()
          .closeIdleConnections(delayMs, TimeUnit.SECONDS);
    } catch (Throwable e) {
      logger.error("Cannot clean connections", e);
      cleanupFailed.increment();
    } finally {
      if (null != start) {
        start.stop();
      }
    }
  }
}

代码示例来源:origin: Netflix/servo

protected void sendNow(UpdateTasks updateTasks) {
 if (updateTasks.numMetrics == 0) {
  return;
 }
 final Stopwatch s = updateTimer.start();
 int totalSent = 0;
 try {
  totalSent = httpHelper.sendAll(updateTasks.tasks,
    updateTasks.numMetrics, sendTimeoutMs);
  LOGGER.debug("Sent {}/{} metrics to atlas", totalSent, updateTasks.numMetrics);
 } finally {
  s.stop();
  int dropped = updateTasks.numMetrics - totalSent;
  numMetricsDroppedSendTimeout.increment(dropped);
 }
}

代码示例来源:origin: Netflix/eureka

@Override
protected <R> EurekaHttpResponse<R> execute(RequestExecutor<R> requestExecutor) {
  EurekaHttpClientRequestMetrics requestMetrics = metricsByRequestType.get(requestExecutor.getRequestType());
  Stopwatch stopwatch = requestMetrics.latencyTimer.start();
  try {
    EurekaHttpResponse<R> httpResponse = requestExecutor.execute(delegate);
    requestMetrics.countersByStatus.get(mappedStatus(httpResponse)).increment();
    return httpResponse;
  } catch (Exception e) {
    requestMetrics.connectionErrors.increment();
    exceptionsMetric.count(e);
    throw e;
  } finally {
    stopwatch.stop();
  }
}

代码示例来源:origin: Netflix/eureka

@Override
  public void run() {
    Stopwatch start = executionTimeStats.start();
    try {
      HttpClientConnectionManager cm = (HttpClientConnectionManager) apacheHttpClient
          .getConfiguration()
          .getProperty(ApacheClientProperties.CONNECTION_MANAGER);
      cm.closeIdleConnections(connectionIdleTimeout, TimeUnit.SECONDS);
    } catch (Throwable e) {
      s_logger.error("Cannot clean connections", e);
      cleanupFailed.increment();
    } finally {
      if (null != start) {
        start.stop();
      }
    }
  }
}

代码示例来源:origin: Netflix/eureka

/**
 * Fetch the registry information from the remote region.
 * @return true, if the fetch was successful, false otherwise.
 */
private boolean fetchRegistry() {
  boolean success;
  Stopwatch tracer = fetchRegistryTimer.start();
  try {
    // If the delta is disabled or if it is the first time, get all applications
    if (serverConfig.shouldDisableDeltaForRemoteRegions()
        || (getApplications() == null)
        || (getApplications().getRegisteredApplications().size() == 0)) {
      logger.info("Disable delta property : {}", serverConfig.shouldDisableDeltaForRemoteRegions());
      logger.info("Application is null : {}", getApplications() == null);
      logger.info("Registered Applications size is zero : {}", getApplications().getRegisteredApplications().isEmpty());
      success = storeFullRegistry();
    } else {
      success = fetchAndStoreDelta();
    }
    logTotalInstances();
  } catch (Throwable e) {
    logger.error("Unable to fetch registry information from the remote registry {}", this.remoteRegionURL, e);
    return false;
  } finally {
    if (tracer != null) {
      tracer.stop();
    }
  }
  return success;
}

代码示例来源:origin: Netflix/servo

@Test
public void testGetValue() throws Exception {
 Stopwatch s = DynamicTimer.start("test1", tagList);
 Timer c = getByName("test1");
 s.stop();
 // we don't call s.stop(), so we only have one recorded value
 assert c != null;
 assertEquals(c.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS));
 c.record(13, TimeUnit.MILLISECONDS);
 long expected = (13 + s.getDuration(TimeUnit.MILLISECONDS)) / 2;
 assertEquals(c.getValue().longValue(), expected);
}

代码示例来源:origin: Netflix/servo

@Test
 public void testByStrings() throws Exception {
  Stopwatch s = DynamicTimer.start("byName");
  Stopwatch s2 = DynamicTimer.start("byName2", "key", "value");

  Thread.sleep(100L);

  s.stop();
  s2.stop();

  Timer c1 = getByName("byName");
  assert c1 != null;
  assertEquals(c1.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS));

  Timer c2 = getByName("byName2");
  assert c2 != null;
  assertEquals(c2.getValue().longValue(), s2.getDuration(TimeUnit.MILLISECONDS));
 }
}

代码示例来源:origin: Netflix/EVCache

@Override
@SuppressWarnings("synthetic-access")
public void receivedStatus(OperationStatus status) {
  operationDuration.stop();
  if (log.isDebugEnabled()) log.debug("GetBulk Keys : " + keys + "; Status : " + status.getStatusCode().name()
      + "; Message : " + status.getMessage() + "; Elapsed Time - " + operationDuration.getDuration(TimeUnit.MILLISECONDS));
  if (status.getStatusCode().equals(StatusCode.SUCCESS)) {
    getCounter(BULK_OPERATION_STRING + "-SUCCESS").increment();
  } else {
    getCounter(BULK_OPERATION_STRING + "-" + status.getStatusCode().name()).increment();//First lets get some data and then we can add Host info
  }                
  rv.setStatus(status);
}

代码示例来源:origin: Netflix/eureka

/**
 * Replicates all eureka actions to peer eureka nodes except for replication
 * traffic to this node.
 *
 */
private void replicateToPeers(Action action, String appName, String id,
               InstanceInfo info /* optional */,
               InstanceStatus newStatus /* optional */, boolean isReplication) {
  Stopwatch tracer = action.getTimer().start();
  try {
    if (isReplication) {
      numberOfReplicationsLastMin.increment();
    }
    // If it is a replication already, do not replicate again as this will create a poison replication
    if (peerEurekaNodes == Collections.EMPTY_LIST || isReplication) {
      return;
    }
    for (final PeerEurekaNode node : peerEurekaNodes.getPeerEurekaNodes()) {
      // If the url represents this host, do not replicate to yourself.
      if (peerEurekaNodes.isThisMyUrl(node.getServiceUrl())) {
        continue;
      }
      replicateInstanceActionsToPeers(action, appName, id, info, newStatus, node);
    }
  } finally {
    tracer.stop();
  }
}

代码示例来源:origin: Netflix/eureka

} finally {
  if (tracer != null) {
    tracer.stop();

代码示例来源:origin: Netflix/servo

@Test
public void testValue() throws Exception {
 ManualClock clock = new ManualClock(0L);
 DurationTimer timer = new DurationTimer(MonitorConfig.builder("test").build(), clock);
 assertEquals(0L, timer.getValue().longValue());
 Stopwatch s = timer.start();
 clock.set(10 * 1000L);
 assertEquals(10L, timer.getValue().longValue());
 s.stop();
 assertEquals(0L, timer.getValue().longValue());
}

代码示例来源:origin: Netflix/servo

@Test
public void testExpiration() throws Exception {
 clock.set(0L);
 DynamicTimer.start("test1", tagList);
 DynamicTimer.start("test2", tagList);
 clock.set(500L);
 DynamicTimer.start("test1", tagList);
 clock.set(1000L);
 Stopwatch s = DynamicTimer.start("test1", tagList);
 clock.set(1200L);
 s.stop();
 Timer c1 = getByName("test1");
 assert c1 != null;
 assertEquals(c1.getValue().longValue(), s.getDuration(TimeUnit.MILLISECONDS));
 Thread.sleep(200L);
 Timer c2 = getByName("test2");
 assertNull(c2, "Timers not used in a while should expire");
}

代码示例来源:origin: Netflix/servo

@Override
public void handle(HttpExchange exchange) throws IOException {
 CountingInputStream input = new CountingInputStream(exchange.getRequestBody());
 CountingOutputStream output = new CountingOutputStream(exchange.getResponseBody());
 exchange.setStreams(input, output);
 Stopwatch stopwatch = latency.start();
 try {
  handleImpl(exchange);
 } finally {
  stopwatch.stop();
  bytesReceived.increment(input.getCount());
  bytesSent.increment(output.getCount());
 }
}

相关文章