private void registerRatioGauge(MetricId metricId, String stat, Supplier<Ratio> ratioSupplier, SemanticMetricRegistry metricRegistry, What what) { metricRegistry.register( metricId.tagged("what", what.tag(), "stat", stat), new RatioGauge() { @Override protected Ratio getRatio() { return ratioSupplier.get(); } }); }
protected void registerAll(final MetricId prefix, final SemanticMetricSet metrics) throws IllegalArgumentException { for (final Map.Entry<MetricId, Metric> entry : metrics.getMetrics().entrySet()) { if (entry.getValue() instanceof SemanticMetricSet) { registerAll(MetricId.join(prefix, entry.getKey()), (SemanticMetricSet) entry.getValue()); } else { register(MetricId.join(prefix, entry.getKey()), entry.getValue()); } } }
metricRegistry.register(MetricId.EMPTY, new MemoryUsageGaugeSet()); metricRegistry.register(MetricId.EMPTY, new GarbageCollectorMetricSet()); metricRegistry.register(MetricId.EMPTY, new ThreadStatesMetricSet()); metricRegistry.register(MetricId.EMPTY, CpuGaugeSet.create()); metricRegistry.register(MetricId.EMPTY, new SemanticMetricSet() { private FileDescriptorRatioGauge fileDescriptorRatioGauge = new FileDescriptorRatioGauge();
protected void registerAll(final MetricId prefix, final SemanticMetricSet metrics) throws IllegalArgumentException { for (final Map.Entry<MetricId, Metric> entry : metrics.getMetrics().entrySet()) { if (entry.getValue() instanceof SemanticMetricSet) { registerAll(MetricId.join(prefix, entry.getKey()), (SemanticMetricSet) entry.getValue()); } else { register(MetricId.join(prefix, entry.getKey()), entry.getValue()); } } }
@Override public void registerQueuedEventsMetric(Gauge<Long> queuedEventsCount) { registry.register(QUEUED_EVENTS, queuedEventsCount); }
@Override public void registerSubmissionRateLimitMetric(Gauge<Double> submissionRateLimit) { registry.register(SUBMISSION_RATE_LIMIT, submissionRateLimit); }
private <T extends Metric> void tryRegister(String name, T metric) { try { MetricId metricId = metricIdBuilder.buildMetricId(name); target.register(metricId, metric); } catch (Exception e) { log.warn("Failed to register metric " + name, e); } }
private <T extends Metric> void tryRegister(String name, T metric) { try { MetricId metricId = metricIdBuilder.buildMetricId(name); target.register(metricId, metric); } catch (Exception e) { log.warn("Failed to register metric " + name, e); } }
@Override public void registerWorkflowCountMetric(String status, Gauge<Long> workflowCount) { registry.register(WORKFLOW_COUNT.tagged(STATUS, status), workflowCount); }
/** * A gauge is an instantaneous measurement of a value. We want to measure the number of pending * jobs in a queue */ private static void reportGauge() { // Create or fetch (if it is already created) the metric. registry.register(APP_PREFIX.tagged("what", "job-queue-length"), new Gauge<Integer>() { @Override public Integer getValue() { // fetch the queue length the way you like final int queueLength = 10; // obviously this is gonna keep reporting 10, but you know ;) return queueLength; } }); // That's it! The rest will be automatically done inside semantic metrics library. // Every time the reporter wants to report, getValue method of the Gauge will be invoked, // and a datapoint will be created and reported }
@Override public void registerActiveStatesMetric(RunState.State state, String triggerName, Gauge<Long> activeStatesCount) { registry.register(ACTIVE_STATES_PER_RUNSTATE_PER_TRIGGER.tagged( "state", state.name(), "trigger", triggerName), activeStatesCount); }
private void createConnectionCounterGauge() { final MetricId gaugeId = id.tagged("what", "global-connections", "unit", "connections"); // registry doesn't allow duplicate registrations, so remove the metric if already existing synchronized (registry) { registry.remove(gaugeId); registry.register(gaugeId, (Gauge<Integer>) Utils::getGlobalConnectionCount); } } }
@Override public void registerOutstandingRequestsGauge(final OutstandingRequestsGauge gauge) { final MetricId gaugeId = id.tagged( "what", "outstanding-requests", "unit", "requests"); // registry doesn't allow duplicate registrations, so remove the metric if already existing synchronized (registry) { registry.remove(gaugeId); registry.register(gaugeId, (Gauge<Integer>) () -> gauge.getOutstandingRequests()); } }
public static void main(final String[] args) throws Exception { registry.register(MetricId.build("jvm-memory"), new MemoryUsageGaugeSet()); registry.register(MetricId.build("jvm-gc"), new GarbageCollectorMetricSet()); registry.register(MetricId.build("jvm-threads"), new ThreadStatesMetricSet()); registry.register(MetricId.build("jvm-cpu"), CpuGaugeSet.create()); registry.register(MetricId.build("jvm-fd-ratio"), new FileDescriptorGaugeSet()); final FastForwardReporter reporter = FastForwardReporter .forRegistry(registry) .prefix(APP_PREFIX) .schedule(TimeUnit.SECONDS, 5) .build(); reporter.start(); System.out.println("Sending jvm metrics..."); System.in.read(); reporter.stop(); } }
private static Statistics setupStatistics() throws IOException { final String key = System.getProperty("ffwd.key", "ffwd-java"); final SemanticMetricRegistry registry = new SemanticMetricRegistry(); final SemanticCoreStatistics statistics = new SemanticCoreStatistics(registry); final MetricId gauges = MetricId.build(); registry.register(gauges, new ThreadStatesMetricSet()); registry.register(gauges, new GarbageCollectorMetricSet()); registry.register(gauges, new MemoryUsageGaugeSet()); final MetricId metric = MetricId.build(key); final FastForwardReporter ffwd = FastForwardReporter .forRegistry(registry) .schedule(TimeUnit.SECONDS, 30) .prefix(metric) .build(); ffwd.start(); return new Statistics(ffwd, statistics); }
registry.register(getId.tagged("what", "memcache-hit-ratio", "unit", "%"), hitRatio);