Java源码示例:com.netflix.spectator.api.histogram.PercentileTimer
示例1
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);
}
}
示例2
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);
}
}
示例3
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);
}
}
示例4
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);
}
}
示例5
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();
}
}
示例6
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);
});
}
示例7
private void recordClientMetrics() {
Id clientCall = createCallId(IpcMetric.clientCall.metricName());
PercentileTimer.builder(registry)
.withId(clientCall)
.build()
.record(getLatency(), TimeUnit.NANOSECONDS);
}
示例8
private void recordServerMetrics() {
Id serverCall = createCallId(IpcMetric.serverCall.metricName());
PercentileTimer.builder(registry)
.withId(serverCall)
.build()
.record(getLatency(), TimeUnit.NANOSECONDS);
}
示例9
@Threads(1)
@Benchmark
public void percentileTimerBuilder() {
PercentileTimer.builder(registry)
.withId(pctId)
.withRange(10, 10000, TimeUnit.MILLISECONDS)
.build()
.record(31, TimeUnit.MILLISECONDS);
}
示例10
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());
}
示例11
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
);
}
示例12
@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());
}
}
示例13
private void recordTiming(Id id, long startTimeMs) {
PercentileTimer.get(registry, id)
.record(System.currentTimeMillis() - startTimeMs, TimeUnit.MILLISECONDS);
}
示例14
@Threads(1)
@Benchmark
public void percentileTimerGet() {
PercentileTimer.get(registry, pctId).record(31, TimeUnit.MILLISECONDS);
}