use of com.codahale.metrics.Timer.Context in project opennms by OpenNMS.
the class HeartbeatGenerator method start.
/**
* Start.
*/
public synchronized void start() {
stopped.set(false);
final RateLimiter rateLimiter = RateLimiter.create(rate);
thread = new Thread(new Runnable() {
@Override
public void run() {
while (!stopped.get()) {
rateLimiter.acquire();
try (Context ctx = sendTimer.time()) {
dispatcher.send(new Heartbeat());
sentMeter.mark();
}
}
}
});
thread.start();
}
use of com.codahale.metrics.Timer.Context in project grakn by graknlabs.
the class BatchExecutorClient method add.
/**
* Will block until there is space for the query to be submitted
*/
public Observable<QueryResponse> add(Query<?> query, Keyspace keyspace, boolean keepErrors) {
QueryRequest queryRequest = new QueryRequest(query);
queryRequest.acquirePermit();
Context contextAddTimer = addTimer.time();
Observable<QueryResponse> observable = new QueriesObservableCollapser(queryRequest, keyspace).observe().doOnError(error -> failureMeter.mark()).doOnEach(a -> {
if (a.getThrowable() != null) {
LOG.error("Error while executing statement", a.getThrowable());
} else if (a.isOnNext()) {
LOG.trace("Executed {}", a.getValue());
}
}).subscribeOn(scheduler).doOnTerminate(contextAddTimer::close);
return keepErrors ? observable : ignoreErrors(observable);
}
use of com.codahale.metrics.Timer.Context in project Singularity by HubSpot.
the class SingularityS3DownloaderAsyncHandler method run.
@Override
public void run() {
boolean success = false;
try (final Context context = metrics.getDownloadTimer().time()) {
success = download();
if (!success) {
metrics.getServerErrorsMeter().mark();
getResponse().sendError(500, "Hit client timeout");
}
} catch (Throwable t) {
metrics.getServerErrorsMeter().mark();
LOG.error("While handling {}", artifactDownloadRequest.getTargetDirectory(), t);
exceptionNotifier.notify(String.format("Error handling download (%s)", t.getMessage()), t, ImmutableMap.of("s3Bucket", artifactDownloadRequest.getS3Artifact().getS3Bucket(), "s3Key", artifactDownloadRequest.getS3Artifact().getS3ObjectKey(), "targetDirectory", artifactDownloadRequest.getTargetDirectory()));
try {
getResponse().sendError(500);
} catch (Throwable t2) {
LOG.error("While sending error for {}", artifactDownloadRequest.getTargetDirectory(), t2);
}
} finally {
continuation.complete();
}
}
use of com.codahale.metrics.Timer.Context in project wicket by apache.
the class WicketMetrics method measureTime.
/**
* Simply measure the time for a {@literal @}around
*
* @param name
* the name of the timer context
* @param joinPoint
* the joinPoint to be proceed
* @param renderClass
* if the class name should be rendered behind the metric path
*
* @return the value of the join point
* @throws Throwable
* if there is an exception while execution
*/
public Object measureTime(String name, ProceedingJoinPoint joinPoint, boolean renderClass) throws Throwable {
WicketMetricsSettings settings = getSettings();
MetricRegistry registry = getMetricRegistry();
if (settings.isEnabled()) {
Context context = registry.timer(settings.getPrefix() + name + (renderClass ? renderClassName(joinPoint) : "")).time();
try {
return proceedSilent(joinPoint);
} finally {
stopQuietly(context);
}
} else {
return proceedSilent(joinPoint);
}
}
use of com.codahale.metrics.Timer.Context in project newts by OpenNMS.
the class ImportRunner method directPoster.
private Observable<Boolean> directPoster(Observable<List<Sample>> samples, MetricRegistry metrics) {
final SampleRepository repository = repository();
final Timer timer = metrics.timer("writes");
final Meter completions = metrics.meter("samples-completed");
Func1<List<Sample>, Boolean> insert = new Func1<List<Sample>, Boolean>() {
@Override
public Boolean call(List<Sample> s) {
int sz = s.size();
try (Context timerCtx = timer.time()) {
repository.insert(s);
return true;
} finally {
completions.mark(sz);
}
}
};
return (m_threadCount == 1 ? samples.map(insert) : parMap(samples, metrics, insert)).all(Functions.<Boolean>identity());
}
Aggregations