/** * Create a new DurationTimer using a specific configuration and clock. This is useful for * unit tests that need to manipulate the clock. */ public DurationTimer(MonitorConfig config, final Clock clock) { super(config); this.clock = clock; Monitor<?> duration = new BasicGauge<>(subId(config, "duration"), () -> getDurationMillis() / 1000L); Monitor<?> activeTasks = new BasicGauge<>(subId(config, "activeTasks"), new Callable<Long>() { @Override public Long call() throws Exception { return (long) tasks.size(); } }); monitors = UnmodifiableList.of(duration, activeTasks); }
public ServerChannelMetrics(String id) { super(); String metricNamePrefix = "server.connections."; currentConnectionsGauge = new BasicGauge<>(MonitorConfig.builder(metricNamePrefix + "current").withTag("id", id).build(), () -> currentConnections.get() ); DefaultMonitorRegistry.getInstance().register(currentConnectionsGauge); totalConnections = createCounter(metricNamePrefix + "connect", id); connectionErrors = createCounter(metricNamePrefix + "errors", id); connectionClosed = createCounter(metricNamePrefix + "close", id); connectionIdleTimeout = createCounter(metricNamePrefix + "idle.timeout", id); connectionThrottled = createCounter(metricNamePrefix + "throttled", id); }
@Test public void testBasicGauge() { BasicGauge<Double> c = new BasicGauge<>(CONFIG, () -> 42.0); register(c); PolledMeter.update(registry); assertEquals(42.0, registry.gauge(ID).value(), 1e-12); }
public BasicGauge<Long> newInstance(String name) { long v = Long.parseLong(name); return new BasicGauge<>(MonitorConfig.builder(name).build(), new TestFunc(v)); }
public ServerChannelMetrics(String id) { super(); String metricNamePrefix = "server.connections."; currentConnectionsGauge = new BasicGauge<>(MonitorConfig.builder(metricNamePrefix + "current").withTag("id", id).build(), () -> currentConnections.get() ); DefaultMonitorRegistry.getInstance().register(currentConnectionsGauge); totalConnections = createCounter(metricNamePrefix + "connect", id); connectionErrors = createCounter(metricNamePrefix + "errors", id); connectionClosed = createCounter(metricNamePrefix + "close", id); connectionIdleTimeout = createCounter(metricNamePrefix + "idle.timeout", id); connectionThrottled = createCounter(metricNamePrefix + "throttled", id); }
public void setSelfPreservationMonitor(final PreservableEurekaRegistry registry) { Callable<Integer> selfPreservationCallable = new Callable<Integer>() { @Override public Integer call() throws Exception { return registry.isInSelfPreservation() ? 1 : 0; } }; BasicGauge<Integer> gauge = new BasicGauge<>(monitorConfig("selfPreservation"), selfPreservationCallable); register(gauge); } }
public void setRegistrySizeMonitor(final EurekaServerRegistry<InstanceInfo> registry) { Callable<Integer> registrySizeCallable = new Callable<Integer>() { @Override public Integer call() throws Exception { return registry.size(); } }; BasicGauge<Integer> gauge = new BasicGauge<>(monitorConfig("registrySize"), registrySizeCallable); register(gauge); }
public void setRegistrySizeMonitor(Callable<Integer> registrySizeCallable) { BasicGauge<Integer> gauge = new BasicGauge<>(monitorConfig("registrySize"), registrySizeCallable); register(gauge); } }
public void setEvictionQueueSizeMonitor(final EvictionQueue evictionQueue) { Callable<Integer> registrySizeCallable = new Callable<Integer>() { @Override public Integer call() throws Exception { return evictionQueue.size(); } }; BasicGauge<Integer> gauge = new BasicGauge<>(monitorConfig("evictionQueueSize"), registrySizeCallable); register(gauge); } }
public static <T extends Number> Gauge<T> gauge(final String id, final Callable<T> callable) { return new BasicGauge<>(MonitorConfig.builder(id).build(), callable); }
/** * Create a new DurationTimer using a specific configuration and clock. This is useful for * unit tests that need to manipulate the clock. */ public DurationTimer(MonitorConfig config, final Clock clock) { super(config); this.clock = clock; Monitor<?> duration = new BasicGauge<>(subId(config, "duration"), () -> getDurationMillis() / 1000L); Monitor<?> activeTasks = new BasicGauge<>(subId(config, "activeTasks"), new Callable<Long>() { @Override public Long call() throws Exception { return (long) tasks.size(); } }); monitors = UnmodifiableList.of(duration, activeTasks); }
public ServerChannelMetrics(String id) { super(); String metricNamePrefix = "server.connections."; currentConnectionsGauge = new BasicGauge<>(MonitorConfig.builder(metricNamePrefix + "current").withTag("id", id).build(), () -> currentConnections.get() ); DefaultMonitorRegistry.getInstance().register(currentConnectionsGauge); totalConnections = createCounter(metricNamePrefix + "connect", id); connectionErrors = createCounter(metricNamePrefix + "errors", id); connectionClosed = createCounter(metricNamePrefix + "close", id); connectionIdleTimeout = createCounter(metricNamePrefix + "idle.timeout", id); connectionThrottled = createCounter(metricNamePrefix + "throttled", id); }
.build(); DefaultMonitorRegistry.getInstance().register( new BasicGauge<>( consumersSizeMonitorConfig, new CollectionSizeCallable(this.consumers)));
public EventConsumerStats(String consumerName, long collectionDurationInMillis) { String statsPrefix = "eventbus_consumer_" + consumerName; QUEUE_SIZE_COUNTER = new AtomicLong(); QUEUE_SIZE_GAUGE = new BasicGauge<Long>(MonitorConfig.builder(statsPrefix + "_queue_size").build(), new Callable<Long>() { @Override public Long call() throws Exception { return QUEUE_SIZE_COUNTER.get(); } }); QUEUE_OFFER_RETRY_COUNTER = new BasicCounter(MonitorConfig.builder(statsPrefix + "_queue_retry").build()); EVENT_ENQUEUE_REJECTED_COUNTER = new BasicCounter(MonitorConfig.builder(statsPrefix + "_enqueue_reject").build()); enqueueStats = newStatsTimer(statsPrefix + "_enqueue", collectionDurationInMillis); consumptionStats = newStatsTimer(statsPrefix + "_consumption", collectionDurationInMillis); filterStats = newStatsTimer(statsPrefix + "_filter", collectionDurationInMillis); try { DefaultMonitorRegistry.getInstance().register(QUEUE_SIZE_GAUGE); DefaultMonitorRegistry.getInstance().register(QUEUE_OFFER_RETRY_COUNTER); DefaultMonitorRegistry.getInstance().register(EVENT_ENQUEUE_REJECTED_COUNTER); DefaultMonitorRegistry.getInstance().register(enqueueStats); DefaultMonitorRegistry.getInstance().register(consumptionStats); DefaultMonitorRegistry.getInstance().register(filterStats); } catch (Throwable th) { LOGGER.error("Unable to register to event bus consumer stats to servo.", th); } } }