/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given config. The timer * will report the times in milliseconds to observers. * * @see #start(MonitorConfig, TimeUnit) */ public static Stopwatch start(MonitorConfig config) { return INSTANCE.get(config, TimeUnit.MILLISECONDS).start(); }
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; } }
/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given config. * * @param config Config to identify a particular timer instance to update. * @param unit The unit to use when reporting values to observers. For example if sent to * a typical time series graphing system this would be the unit for the y-axis. * It is generally recommended to use base units for reporting, so * {@link TimeUnit#SECONDS} is the preferred value. */ public static Stopwatch start(MonitorConfig config, TimeUnit unit) { return INSTANCE.get(config, unit).start(); }
@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(); } }
@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(); } } }
/** * 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; }
@Override protected BasicPoolEntry createEntry(RouteSpecificPool rospl, ClientConnectionOperator op) { createEntryCounter.increment(); Stopwatch stopWatch = creationTimer.start(); try { return super.createEntry(rospl, op); } finally { stopWatch.stop(); } }
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; }
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; }
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); } }
@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(); } }
tracer = serializeAllAppsWithRemoteRegionTimer.start(); payload = getPayLoad(key, registry.getApplicationsFromMultipleRegions(key.getRegions())); } else { tracer = serializeAllAppsTimer.start(); payload = getPayLoad(key, registry.getApplications()); tracer = serializeDeltaAppsWithRemoteRegionTimer.start(); versionDeltaWithRegions.incrementAndGet(); versionDeltaWithRegionsLegacy.incrementAndGet(); registry.getApplicationDeltasFromMultipleRegions(key.getRegions())); } else { tracer = serializeDeltaAppsTimer.start(); versionDelta.incrementAndGet(); versionDeltaLegacy.incrementAndGet(); tracer = serializeOneApptimer.start(); payload = getPayLoad(key, registry.getApplication(key.getName())); case VIP: case SVIP: tracer = serializeViptimer.start(); payload = getPayLoad(key, getApplicationsForVip(key, registry)); break;
/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given config. The timer * uses a TimeUnit of milliseconds. */ public static Stopwatch start(String name, TagList list) { final MonitorConfig config = new MonitorConfig.Builder(name).withTags(list).build(); return INSTANCE.get(config, TimeUnit.MILLISECONDS).start(); }
/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given config. The timer * uses a TimeUnit of milliseconds. */ public static Stopwatch start(String name, TagList list, TimeUnit unit) { final MonitorConfig config = new MonitorConfig.Builder(name).withTags(list).build(); return INSTANCE.get(config, unit).start(); }
/** * 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; }
Stopwatch tracer = FETCH_REGISTRY_TIMER.start();
private void putMetricData(List<Metric> batch) { METRICS_COUNTER.increment(batch.size()); final Stopwatch s = PUTS_TIMER.start(); try { cloudWatch.putMetricData(createPutRequest(batch)); } catch (AmazonServiceException e) { final Tag error = new BasicTag("error", e.getErrorCode()); DynamicCounter.increment(ERRORS_COUNTER_ID.withAdditionalTag(error)); LOG.error("Error while submitting data for metrics : " + batch, e); } catch (Exception e) { final Tag error = new BasicTag("error", e.getClass().getSimpleName()); DynamicCounter.increment(ERRORS_COUNTER_ID.withAdditionalTag(error)); LOG.error("Error while submitting data for metrics : " + batch, e); } catch (Error e) { final Tag error = new BasicTag("error", e.getClass().getSimpleName()); DynamicCounter.increment(ERRORS_COUNTER_ID.withAdditionalTag(error)); throw Throwables.propagate(e); } finally { s.stop(); } }
/** * Returns a stopwatch that has been started and will automatically * record its result to the dynamic timer specified by the given name, and sequence of (key, * value) pairs. The timer uses a TimeUnit of milliseconds. */ public static Stopwatch start(String name, String... tags) { final MonitorConfig.Builder configBuilder = MonitorConfig.builder(name); Preconditions.checkArgument(tags.length % 2 == 0, "The sequence of (key, value) pairs must have even size: one key, one value"); for (int i = 0; i < tags.length; i += 2) { configBuilder.withTag(tags[i], tags[i + 1]); } return INSTANCE.get(configBuilder.build(), TimeUnit.MILLISECONDS).start(); }
/** * 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(); } }
@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()); } }