com.netflix.spectator.api.histogram.PercentileTimer Java Examples

The following examples show how to use com.netflix.spectator.api.histogram.PercentileTimer. 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: InstrumentedPipeline.java    From kork with Apache License 2.0 6 votes vote down vote up
private <T> T internalInstrumented(
    String command, Optional<Long> payloadSize, Callable<T> action) {
  payloadSize.ifPresent(
      size ->
          PercentileDistributionSummary.get(
                  registry, payloadSizeId(registry, poolName, command, true))
              .record(size));
  try {
    return PercentileTimer.get(registry, timerId(registry, poolName, command, true))
        .record(
            () -> {
              T result = action.call();
              registry.counter(invocationId(registry, poolName, command, true, true)).increment();
              return result;
            });
  } catch (Exception e) {
    registry.counter(invocationId(registry, poolName, command, true, false)).increment();
    throw new InstrumentedJedisException("could not execute delegate function", e);
  }
}
 
Example #2
Source File: InstrumentedPipeline.java    From kork with Apache License 2.0 6 votes vote down vote up
private void internalInstrumented(String command, Optional<Long> payloadSize, Runnable action) {
  payloadSize.ifPresent(
      size ->
          PercentileDistributionSummary.get(
                  registry, payloadSizeId(registry, poolName, command, true))
              .record(size));
  try {
    PercentileTimer.get(registry, timerId(registry, poolName, command, true))
        .record(
            () -> {
              action.run();
              registry.counter(invocationId(registry, poolName, command, true, true)).increment();
            });
  } catch (Exception e) {
    registry.counter(invocationId(registry, poolName, command, true, false)).increment();
    throw new InstrumentedJedisException("could not execute delegate function", e);
  }
}
 
Example #3
Source File: InstrumentedJedis.java    From kork with Apache License 2.0 6 votes vote down vote up
private <T> T internalInstrumented(
    String command, Optional<Long> payloadSize, Callable<T> action) {
  payloadSize.ifPresent(
      size ->
          PercentileDistributionSummary.get(
                  registry, payloadSizeId(registry, poolName, command, false))
              .record(size));
  try {
    return PercentileTimer.get(registry, timerId(registry, poolName, command, false))
        .record(
            () -> {
              T result = action.call();
              registry
                  .counter(invocationId(registry, poolName, command, false, true))
                  .increment();
              return result;
            });
  } catch (Exception e) {
    registry.counter(invocationId(registry, poolName, command, false, false)).increment();
    throw new InstrumentedJedisException("could not execute delegate function", e);
  }
}
 
Example #4
Source File: InstrumentedJedis.java    From kork with Apache License 2.0 6 votes vote down vote up
private void internalInstrumented(String command, Optional<Long> payloadSize, Runnable action) {
  payloadSize.ifPresent(
      size ->
          PercentileDistributionSummary.get(
                  registry, payloadSizeId(registry, poolName, command, false))
              .record(size));
  try {
    PercentileTimer.get(registry, timerId(registry, poolName, command, false))
        .record(
            () -> {
              action.run();
              registry
                  .counter(invocationId(registry, poolName, command, false, true))
                  .increment();
            });
  } catch (Exception e) {
    registry.counter(invocationId(registry, poolName, command, false, false)).increment();
    throw new InstrumentedJedisException("could not execute delegate function", e);
  }
}
 
Example #5
Source File: EVCacheMetricsFactory.java    From EVCache with Apache License 2.0 6 votes vote down vote up
public Timer getPercentileTimer(String metric, Collection<Tag> tags, Duration max) {
    final String name = tags != null ? metric + tags.toString() : metric;
    final Timer duration = timerMap.get(name);
    if (duration != null) return duration;

    writeLock.lock();
    try {
        if (timerMap.containsKey(name))
            return timerMap.get(name);
        else {
            Id id = getId(metric, tags);
            final Timer _duration = PercentileTimer.builder(getRegistry()).withId(id).withRange(Duration.ofNanos(100000), max).build();
            timerMap.put(name, _duration);
            return _duration;
        }
    } finally {
        writeLock.unlock();
    }
}
 
Example #6
Source File: Monitors.java    From conductor with Apache License 2.0 5 votes vote down vote up
public static Timer getTimer(String className, String name, String... additionalTags) {
	Map<String, String> tags = toMap(className, additionalTags);
	return timers.computeIfAbsent(name, s -> new ConcurrentHashMap<>()).computeIfAbsent(tags, t -> {
		Id id = registry.createId(name, tags);
		return PercentileTimer.get(registry, id);
	});
}
 
Example #7
Source File: IpcLogEntry.java    From spectator with Apache License 2.0 5 votes vote down vote up
private void recordClientMetrics() {
  Id clientCall = createCallId(IpcMetric.clientCall.metricName());
  PercentileTimer.builder(registry)
      .withId(clientCall)
      .build()
      .record(getLatency(), TimeUnit.NANOSECONDS);
}
 
Example #8
Source File: IpcLogEntry.java    From spectator with Apache License 2.0 5 votes vote down vote up
private void recordServerMetrics() {
  Id serverCall = createCallId(IpcMetric.serverCall.metricName());
  PercentileTimer.builder(registry)
      .withId(serverCall)
      .build()
      .record(getLatency(), TimeUnit.NANOSECONDS);
}
 
Example #9
Source File: PercentileTimers.java    From spectator with Apache License 2.0 5 votes vote down vote up
@Threads(1)
@Benchmark
public void percentileTimerBuilder() {
  PercentileTimer.builder(registry)
      .withId(pctId)
      .withRange(10, 10000, TimeUnit.MILLISECONDS)
      .build()
      .record(31, TimeUnit.MILLISECONDS);
}
 
Example #10
Source File: DefaultClientChannelManager.java    From zuul with Apache License 2.0 5 votes vote down vote up
public DefaultClientChannelManager(String originName, String vip, IClientConfig clientConfig, Registry spectatorRegistry) {
    this.loadBalancer = createLoadBalancer(clientConfig);

    this.vip = vip;
    this.clientConfig = clientConfig;
    this.spectatorRegistry = spectatorRegistry;
    this.perServerPools = new ConcurrentHashMap<>(200);

    // Setup a listener for Discovery serverlist changes.
    this.loadBalancer.addServerListChangeListener(this::removeMissingServerConnectionPools);

    this.connPoolConfig = new ConnectionPoolConfigImpl(originName, this.clientConfig);

    this.createNewConnCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_create", originName);
    this.createConnSucceededCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_create_success", originName);
    this.createConnFailedCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_create_fail", originName);

    this.closeConnCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_close", originName);
    this.requestConnCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_request", originName);
    this.reuseConnCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_reuse", originName);
    this.releaseConnCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_release", originName);
    this.alreadyClosedCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_alreadyClosed", originName);
    this.connTakenFromPoolIsNotOpen = SpectatorUtils.newCounter(METRIC_PREFIX + "_fromPoolIsClosed", originName);
    this.maxConnsPerHostExceededCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_maxConnsPerHostExceeded", originName);
    this.closeWrtBusyConnCounter = SpectatorUtils.newCounter(METRIC_PREFIX + "_closeWrtBusyConnCounter", originName);
    this.connEstablishTimer = PercentileTimer.get(spectatorRegistry, spectatorRegistry.createId(METRIC_PREFIX + "_createTiming", "id", originName));
    this.connsInPool = SpectatorUtils.newGauge(METRIC_PREFIX + "_inPool", originName, new AtomicInteger());
    this.connsInUse = SpectatorUtils.newGauge(METRIC_PREFIX + "_inUse", originName, new AtomicInteger());
}
 
Example #11
Source File: DefaultClientChannelManager.java    From zuul with Apache License 2.0 5 votes vote down vote up
protected IConnectionPool createConnectionPool(
        Server chosenServer, ServerStats stats, InstanceInfo instanceInfo, SocketAddress serverAddr,
        NettyClientConnectionFactory clientConnFactory, PooledConnectionFactory pcf,
        ConnectionPoolConfig connPoolConfig, IClientConfig clientConfig, Counter createNewConnCounter,
        Counter createConnSucceededCounter, Counter createConnFailedCounter, Counter requestConnCounter,
        Counter reuseConnCounter, Counter connTakenFromPoolIsNotOpen, Counter maxConnsPerHostExceededCounter,
        PercentileTimer connEstablishTimer, AtomicInteger connsInPool, AtomicInteger connsInUse) {
    return new PerServerConnectionPool(
            chosenServer,
            stats,
            instanceInfo,
            serverAddr,
            clientConnFactory,
            pcf,
            connPoolConfig,
            clientConfig,
            createNewConnCounter,
            createConnSucceededCounter,
            createConnFailedCounter,
            requestConnCounter,
            reuseConnCounter,
            connTakenFromPoolIsNotOpen,
            maxConnsPerHostExceededCounter,
            connEstablishTimer,
            connsInPool,
            connsInUse
    );
}
 
Example #12
Source File: MetricsInterceptor.java    From kork with Apache License 2.0 4 votes vote down vote up
@Override
public void afterCompletion(
    HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
    throws Exception {
  if (handler instanceof HandlerMethod) {
    HandlerMethod handlerMethod = (HandlerMethod) handler;

    String controller = handlerMethod.getMethod().getDeclaringClass().getSimpleName();
    if (controllersToExclude.contains(controller)) {
      return;
    }

    Integer status = response.getStatus();
    if (ex != null) {
      // propagated exceptions should get tracked as '500' regardless of response status
      status = 500;
    }

    Id id =
        registry
            .createId(metricName)
            .withTag("controller", controller)
            .withTag("method", handlerMethod.getMethod().getName())
            .withTag("status", status.toString().charAt(0) + "xx")
            .withTag("statusCode", status.toString());

    Map variables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
    for (String pathVariable : pathVariablesToTag) {
      if (variables.containsKey(pathVariable)) {
        id = id.withTag(pathVariable, variables.get(pathVariable).toString());
      } else {
        id = id.withTag(pathVariable, "None");
      }
    }

    for (String queryParamName : queryParamsToTag) {
      String parameter = request.getParameter(queryParamName);
      if (parameter != null) {
        id = id.withTag(queryParamName, parameter);
      } else {
        id = id.withTag(queryParamName, "None");
      }
    }

    if (ex != null) {
      id = id.withTag("success", "false").withTag("cause", ex.getClass().getSimpleName());
    } else {
      id = id.withTag("success", "true").withTag("cause", "None");
    }

    PercentileTimer.get(registry, id)
        .record(
            getNanoTime() - ((Long) request.getAttribute(TIMER_ATTRIBUTE)), TimeUnit.NANOSECONDS);

    PercentileDistributionSummary.get(
            registry, registry.createId(contentLengthMetricName).withTags(id.tags()))
        .record(request.getContentLengthLong());
  }
}
 
Example #13
Source File: InstrumentedProxy.java    From kork with Apache License 2.0 4 votes vote down vote up
private void recordTiming(Id id, long startTimeMs) {
  PercentileTimer.get(registry, id)
      .record(System.currentTimeMillis() - startTimeMs, TimeUnit.MILLISECONDS);
}
 
Example #14
Source File: PercentileTimers.java    From spectator with Apache License 2.0 4 votes vote down vote up
@Threads(1)
@Benchmark
public void percentileTimerGet() {
  PercentileTimer.get(registry, pctId).record(31, TimeUnit.MILLISECONDS);
}