private void collectMetrics(DataCollector<Metric> collector, MetricProvider provider) { try { provider.gather(new MetricCollectorAdapter(collector)); } catch (Exception e) { Exceptions.handle(e); } }
@Override public void metric(String code, String limitType, String label, double value, String unit) { collector.add(new Metric(code, label, value, computeState(limitType, value), unit)); }
@Override public void differentialMetric(String code, String limitType, String label, double currentValue, String unit) { Double lastValue = differentials.get(code); if (lastValue != null) { metric(code, limitType, label, currentValue - lastValue, unit); } differentials.put(code, currentValue); }
@Override public void gather(MetricsCollector collector) { if (backgroundTasks.getCount() > 0) { collector.differentialMetric("kernel_delay_line_tasks", "delay-line-tasks", "Delay-Line Tasks", backgroundTasks.getCount(), "1/min"); } long length; synchronized (waitingTasks) { length = waitingTasks.size(); } collector.metric("kernel_delay_line_length", "delay-line-length", "Delay-Line Length", length, null); } }
@Override public void gather(MetricsCollector collector) { gatherMemoryMetrics(collector); gatherGCMetrics(collector); collector.differentialMetric("kernel_interactions", "sys-interactions", "Interactions", CallContext.getInteractionCounter().getCount(), "/min"); collector.differentialMetric("kernel_log_entries", "sys-logs", "Log Messages", monitor.getNumLogMessages(), "/min"); collector.differentialMetric("kernel_incidents", "sys-incidents", "Incidents", monitor.getNumIncidents(), "/min"); collector.differentialMetric("kernel_unique_incidents", "sys-unique-incidents", "Unique Incidents", monitor.getNumUniqueIncidents(), "/min"); }
@Override public void execute(Output output, String... params) throws Exception { output.apply("%-8s %-30s %15s", "STATE", "NAME", "VALUE"); output.separator(); for (Metric metric : metrics.getMetrics()) { output.apply("%-8s %-30s %15s", metric.getState(), metric.getLabel(), metric.getValueAsString()); } output.separator(); }
@Override public void gather(MetricsCollector collector) { collector.metric("kernel_active_operations", "active-operations", "Active-Operations", ops.size(), null); collector.metric("kernel_hanging_operations", "hanging-operations", "Hanging-Operations", getActiveOperations().stream().filter(Operation::isOvertime).count(), null); } }
private void gatherGCMetrics(MetricsCollector collector) { for (GarbageCollectorMXBean gc : gcs) { collector.differentialMetric("jvm_gc_" + gc.getName().toLowerCase(), "jvm-gc", "GC - " + gc.getName(), gc.getCollectionCount(), "/min"); } }
@Override @SuppressWarnings("squid:S1698") @Explain("Indentity against this is safe and a shortcut to speed up comparisons") public int compareTo(Metric o) { if (o == null) { return -1; } if (o == this) { return 0; } if (o.state != state) { return o.state.ordinal() - state.ordinal(); } return code.compareTo(o.code); }
@Override public void metric(String code, String label, double value, String unit, MetricState state) { collector.add(new Metric(code, label, value, state, unit)); }
private void collectMetrics() { final DataCollector<Metric> collector = DataCollector.create(); for (MetricProvider provider : providers) { collectMetrics(collector, provider); } List<Metric> newMetricsList = collector.getData(); Collections.sort(newMetricsList); metricsList = newMetricsList; }
private Limit loadLimit(String limitType) { Limit limit = new Limit(); String configPrefix = HEALTH_LIMITS_PREFIX + limitType; if (Sirius.getSettings().getConfig().hasPath(configPrefix + LIMIT_TYPE_GRAY)) { limit.gray = Sirius.getSettings().getConfig().getDouble(configPrefix + LIMIT_TYPE_GRAY); } if (Sirius.getSettings().getConfig().hasPath(configPrefix + LIMIT_TYPE_WARNING)) { limit.yellow = Sirius.getSettings().getConfig().getDouble(configPrefix + LIMIT_TYPE_WARNING); } if (Sirius.getSettings().getConfig().hasPath(configPrefix + ".warn")) { Log.SYSTEM.WARN("Invalid metrics limit: '%s' - Use: '%s' instead", configPrefix + ".warn", configPrefix + LIMIT_TYPE_WARNING); } if (Sirius.getSettings().getConfig().hasPath(configPrefix + LIMIT_TYPE_ERROR)) { limit.red = Sirius.getSettings().getConfig().getDouble(configPrefix + LIMIT_TYPE_ERROR); } return limit; } }
@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"); } } }
private void gatherMemoryMetrics(MetricsCollector collector) { for (MemoryPoolMXBean pool : pools) { if (pool.getName().toLowerCase().contains("old") && pool.getUsage().getMax() > 0) { collector.metric("jvm_old_heap", "jvm-old-heap", "JVM Heap (" + pool.getName() + ")", 100d * pool.getUsage().getUsed() / pool.getUsage().getMax(), "%"); } } } }
@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"); } } }
@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"); } } }
collector.differentialMetric("jdbc_use", "db-uses", "JDBC Uses", numUses.getCount(), "/min"); collector.differentialMetric("jdbc_connects", "db-connects", "JDBC Connects", collector.metric("jdbc_pool_utilization", "db-pool-utilization", "JDBC Pool Utilization (max)", "%"); collector.differentialMetric("jdbc_queries", "db-queries", "JDBC Queries", numQueries.getCount(), "/min"); collector.differentialMetric("jdbc_slow_queries", "db-slow-queries", "Slow JDBC Queries", numSlowQueries.getCount(), "/min"); collector.metric("jdbc_query_duration", "db-query-duration", "JDBC Query Duration",
collector.metric("es_nodes", "ES-Nodes", res.getNumberOfNodes(), null, asMetricState(res.getStatus())); collector.metric("es_initializing_shards", "ES-InitializingShards", res.getInitializingShards(), null, res.getInitializingShards() > 0 ? MetricState.YELLOW : MetricState.GRAY); collector.metric("es_relocating_shards", "ES-RelocatingShards", res.getRelocatingShards(), null, res.getRelocatingShards() > 0 ? MetricState.YELLOW : MetricState.GRAY); collector.metric("es_unassigned_shards", "ES-UnassignedShards", res.getUnassignedShards(), null, res.getUnassignedShards() > 0 ? MetricState.RED : MetricState.GRAY); collector.metric("index_delay_line", "index-delay-line", "ES-DelayLine", IndexAccess.oneSecondDelayLine.size(), null); collector.differentialMetric("index-blocks", "index-blocks", "ES-DelayBlocks", index.blocks.getCount(), "/min"); collector.differentialMetric("index-delays", "index-delays", "ES-Delays", index.delays.getCount(), "/min"); collector.differentialMetric("index-locking-errors", "index-locking-errors", "ES-OptimisticLock-Errors", index.optimisticLockErrors.getCount(), "/min"); collector.metric("index_query_duration",