/** * Adds the given value to the set of values on which the average is based. * <p> * If the sum of all values is greater as <tt>Double.MAX_VALUE / 2</tt> or the count of all values is greater as * <tt>Long.Max_VALUE / 2</tt>, the average is resetted. * * @param value to value to add to the average */ public void addValue(long value) { addValue((double) value); }
@Override public void gather(MetricsCollector collector) { if (mongo.isConfigured()) { collector.metric("mongo_calls","mongo-calls", "Mongo DB Calls", mongo.callDuration.getCount(), "/min"); collector.metric("mongo_call_duration","mongo-call-duration", "Mongo DB Call Duration", mongo.callDuration.getAndClear(), "ms"); collector.differentialMetric("mongo_slow_queries", "mongo-slow-queries", "MongoDB Slow Queries", mongo.numSlowQueries.getCount(), "/min"); } } }
/** * Adds the given value to the set of values on which the average is based. * <p> * If the sum of all values is greater as <tt>Double.MAX_VALUE / 2</tt> or the count of all values is greater as * <tt>Long.Max_VALUE / 2</tt>, the average is resetted. * * @param value to value to add to the average */ public void addValue(double value) { addValues(1, value); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); if (descriptor != null) { sb.append(descriptor.getRelationName()); } else { sb.append(" ?"); } sb.append(" ["); sb.append(stmt != null ? "open" : "closed"); if (batchBacklog > 0) { sb.append("|Backlog: "); sb.append(batchBacklog); } if (avarage.getCount() > 0) { sb.append("|Executed: "); sb.append(avarage.getCount()); sb.append("|Duration: "); sb.append(NLS.toUserString(avarage.getAvg())); sb.append(" ms"); } sb.append("] "); if (query != null) { sb.append(query); } else { sb.append(" no query available yet"); } return sb.toString(); }
@Override public String toString() { return getAvg() + " (" + count + ")"; } }
"db-query-duration", "JDBC Query Duration", queryDuration.getAndClear(), "ms");
protected Timing(String category, String key) { this.category = category; this.key = key; this.avg = new Average(); }
/** * The average duration of a task in milliseconds. * * @return the average execution time of a task in milliseconds */ public double getAverageDuration() { return duration.getAvg(); }
protected void addNanos(long durationInNanos) { avg.addValue(durationInNanos / 1000); changedSinceLastCheck = true; } }
@Override public void gather(MetricsCollector collector) { if (elastic.isConfigured()) { collector.differentialMetric("es_slow_queries", "es-slow-queries", "Elasticsearch Slow Queries", elastic.numSlowQueries.getCount(), "/min"); collector.metric("es_calls", "es-calls", "Elasticsearch Calls", elastic.callDuration.getCount(), "/min"); collector.metric("es_call_duration", "es-call-duration", "Elasticsearch Call Duration", elastic.callDuration.getAndClear(), "ms"); } } }
/** * Returns the average just like {@link #getAvg()} but then resets the internal buffers to zero. * * @return the average of the last 100 values */ public double getAndClear() { double avg = getAvg(); count.set(0); sampleCount.set(0); sum.set(0); return avg; }
protected void tryCommit(boolean cascade) { if (stmt == null) { return; } if (batchBacklog > 0) { try { Watch w = Watch.start(); stmt.executeBatch(); avarage.addValues(batchBacklog, w.elapsedMillis()); batchBacklog = 0; } catch (SQLException e) { if (cascade) { context.safeClose(); } throw Exceptions.handle() .to(OMA.LOG) .error(e) .withSystemErrorMessage("An error occured while batch executing a statement: %s (%s)") .handle(); } } }
@Override public void iterate(Function<Row, Boolean> handler, @Nullable Limit limit) throws SQLException { Watch w = Watch.start(); try (ResultSet rs = query.prepareStmt().executeQuery()) { query.avarage.addValue(w.elapsedMillis()); TaskContext tc = TaskContext.get(); processResultSet(handler, limit, rs, tc); } }
@Override public void gather(MetricsCollector collector) { if (redis.isConfigured()) { collector.metric("redis_calls", "redis-calls", "Redis Calls", redis.callDuration.getCount(), "/min"); collector.metric("redis_call_duration", "redis-call-duration", "Redis Call Duration", redis.callDuration.getAndClear(), "ms"); collector.metric("redis_memory_usage", "redis-memory-usage", "Redis Memory Usage", Value.of(redis.getInfo().get(Redis.INFO_USED_MEMORY)).asLong(0) / 1024d / 1024d, "MB"); collector.metric("redis_messages", "redis-messages", "Redis PubSub Messages", redis.messageDuration.getCount(), "/min"); collector.metric("redis_message_duration", "redis-message-duration", "Redis PubSub Message Duration", redis.messageDuration.getAndClear(), "ms"); } } }
private void handleTracingAndReporting(String collection, Watch w) { mongo.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming(KEY_MONGO, "FIND ALL - " + collection + ": " + filterObject); } traceIfRequired(collection, w); }
"index-queryDuration", "ES-QueryDuration", index.queryDuration.getAndClear(), "ms"); collector.differentialMetric("index-queries", "index-queries", "ES-Queries", index.queryDuration.getCount(), "/min");
/** * Executes one or more Redis commands and returns a value of the given type. * * @param description a description of the actions performed used for debugging and tracing * @param task the actual task to perform using redis * @param <T> the generic type of the result * @return a result computed by <tt>task</tt> */ public <T> T query(Supplier<String> description, Function<Jedis, T> task) { Watch w = Watch.start(); try (Operation op = new Operation(description, Duration.ofSeconds(10)); Jedis redis = getConnection()) { return task.apply(redis); } catch (Exception e) { throw Exceptions.handle(Redis.LOG, e); } finally { redisInstance.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming("redis", description.get()); } } }
mongo.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming(KEY_MONGO,
/** * Counts the number of documents in the result of the given query. * <p> * Note that limits are ignored for this query. * * @param collection the collection to search in * @return the number of documents found */ public long countIn(String collection) { Watch w = Watch.start(); try { return mongo.db().getCollection(collection).count(filterObject); } finally { mongo.callDuration.addValue(w.elapsedMillis()); if (Microtiming.isEnabled()) { w.submitMicroTiming(KEY_MONGO, "COUNT - " + collection + ": " + filterObject); } traceIfRequired(collection, w); } }