Search in sources :

Example 11 with Context

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();
}
Also used : Context(com.codahale.metrics.Timer.Context) RateLimiter(com.google.common.util.concurrent.RateLimiter)

Example 12 with Context

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);
}
Also used : Context(com.codahale.metrics.Timer.Context) HystrixRequestContext(com.netflix.hystrix.strategy.concurrency.HystrixRequestContext) HystrixCollapserKey(com.netflix.hystrix.HystrixCollapserKey) Retryer(com.github.rholder.retry.Retryer) RetryerBuilder(com.github.rholder.retry.RetryerBuilder) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) Keyspace(ai.grakn.Keyspace) RetryException(com.github.rholder.retry.RetryException) LoggerFactory(org.slf4j.LoggerFactory) HystrixThreadPoolProperties(com.netflix.hystrix.HystrixThreadPoolProperties) Observable(rx.Observable) Meter(com.codahale.metrics.Meter) HystrixCollapserProperties(com.netflix.hystrix.HystrixCollapserProperties) Schedulers(rx.schedulers.Schedulers) Context(com.codahale.metrics.Timer.Context) ConnectException(java.net.ConnectException) ExecutorService(java.util.concurrent.ExecutorService) WaitStrategies(com.github.rholder.retry.WaitStrategies) HystrixCollapser(com.netflix.hystrix.HystrixCollapser) HystrixCommandGroupKey(com.netflix.hystrix.HystrixCommandGroupKey) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) Collection(java.util.Collection) Attempt(com.github.rholder.retry.Attempt) API(ai.grakn.API) UUID(java.util.UUID) Scheduler(rx.Scheduler) RetryListener(com.github.rholder.retry.RetryListener) Collectors(java.util.stream.Collectors) Query(ai.grakn.graql.Query) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) HystrixRequestContext(com.netflix.hystrix.strategy.concurrency.HystrixRequestContext) HystrixCommand(com.netflix.hystrix.HystrixCommand) List(java.util.List) StopStrategies(com.github.rholder.retry.StopStrategies) Closeable(java.io.Closeable) Timer(com.codahale.metrics.Timer) Optional(java.util.Optional) MetricRegistry.name(com.codahale.metrics.MetricRegistry.name) SimpleURI(ai.grakn.util.SimpleURI)

Example 13 with Context

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();
    }
}
Also used : Context(com.codahale.metrics.Timer.Context)

Example 14 with Context

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);
    }
}
Also used : Context(com.codahale.metrics.Timer.Context) MetricRegistry(com.codahale.metrics.MetricRegistry)

Example 15 with Context

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());
}
Also used : SampleRepository(org.opennms.newts.api.SampleRepository) Context(com.codahale.metrics.Timer.Context) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter) Sample(org.opennms.newts.api.Sample) List(java.util.List) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Func1(rx.functions.Func1)

Aggregations

Context (com.codahale.metrics.Timer.Context)37 Timer (com.codahale.metrics.Timer)11 MetricsContext (com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext)10 ApplierContext (com.torodb.mongodb.repl.oplogreplier.ApplierContext)9 OplogOperation (com.eightkdata.mongowp.server.api.oplog.OplogOperation)8 Test (org.junit.Test)7 RetrierGiveUpException (com.torodb.core.retrier.RetrierGiveUpException)6 SQLException (java.sql.SQLException)5 PreparedStatementExecutorWrapper (com.dangdang.ddframe.rdb.sharding.executor.wrapper.PreparedStatementExecutorWrapper)4 RetrierAbortException (com.torodb.core.retrier.RetrierAbortException)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 StatementExecutorWrapper (com.dangdang.ddframe.rdb.sharding.executor.wrapper.StatementExecutorWrapper)3 RollbackException (com.torodb.core.transaction.RollbackException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3 ConsoleReporter (com.codahale.metrics.ConsoleReporter)2 Counter (com.codahale.metrics.Counter)2