Java Code Examples for io.micrometer.core.instrument.MeterRegistry#gauge()
The following examples show how to use
io.micrometer.core.instrument.MeterRegistry#gauge() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheGenieFileTransferService.java From genie with Apache License 2.0 | 6 votes |
/** * Constructor. * * @param fileTransferFactory file transfer implementation factory * @param baseCacheLocation file cache location * @param localFileTransfer Local file transfer service * @param registry spectator registry * @throws GenieException If there is any problem */ public CacheGenieFileTransferService( @NotNull final FileTransferFactory fileTransferFactory, @NotNull final String baseCacheLocation, @NotNull final LocalFileTransferImpl localFileTransfer, @NotNull final MeterRegistry registry ) throws GenieException { super(fileTransferFactory); this.baseCacheLocation = this.createDirectories(baseCacheLocation).toString(); this.localFileTransfer = localFileTransfer; // TODO: May want to switch to DistributionSummary registry.gauge("genie.jobs.file.cache.hitRate", this.fileCache, value -> value.stats().hitRate()); registry.gauge("genie.jobs.file.cache.missRate", this.fileCache, value -> value.stats().missRate()); registry.gauge( "genie.jobs.file.cache.loadExceptionRate", this.fileCache, value -> value.stats().loadExceptionCount() ); }
Example 2
Source File: AgentRoutingServiceCuratorDiscoveryImpl.java From genie with Apache License 2.0 | 6 votes |
/** * Constructor. * * @param genieHostInfo The genie local host information * @param serviceDiscovery The service discovery client * @param taskScheduler The task scheduler * @param listenableCuratorConnectionState The listenable curator client connection status * @param registry The metrics registry */ public AgentRoutingServiceCuratorDiscoveryImpl( final GenieHostInfo genieHostInfo, final ServiceDiscovery<Agent> serviceDiscovery, final TaskScheduler taskScheduler, final Listenable<ConnectionStateListener> listenableCuratorConnectionState, final MeterRegistry registry ) { this.localHostname = genieHostInfo.getHostname(); this.serviceDiscovery = serviceDiscovery; this.taskScheduler = taskScheduler; this.registry = registry; // Schedule periodic reconciliation between in-memory connected set and Service Discovery state this.taskScheduler.schedule(this::reconcileRegistrationsTask, trigger); // Listen for Curator session state changes listenableCuratorConnectionState.addListener(this::handleConnectionStateChange); // Create gauge metric for agents connected and registered registry.gauge(CONNECTED_AGENTS_GAUGE_NAME, EMPTY_TAG_SET, this.connectedAgentsSet, Set::size); registry.gaugeMapSize(REGISTERED_AGENTS_GAUGE_NAME, EMPTY_TAG_SET, this.registeredAgentsMap); }
Example 3
Source File: CaffeineMetricSupport.java From armeria with Apache License 2.0 | 6 votes |
CaffeineMetrics(MeterRegistry parent, MeterIdPrefix idPrefix) { this.parent = requireNonNull(parent, "parent"); this.idPrefix = requireNonNull(idPrefix, "idPrefix"); final String requests = idPrefix.name("requests"); parent.more().counter(requests, idPrefix.tags("result", "hit"), this, func(HIT_COUNT, ref -> ref.cacheStats.hitCount())); parent.more().counter(requests, idPrefix.tags("result", "miss"), this, func(MISS_COUNT, ref -> ref.cacheStats.missCount())); parent.more().counter(idPrefix.name("evictions"), idPrefix.tags(), this, func(EVICTION_COUNT, ref -> ref.cacheStats.evictionCount())); parent.more().counter(idPrefix.name(Flags.useLegacyMeterNames() ? "evictionWeight" : "eviction.weight"), idPrefix.tags(), this, func(EVICTION_WEIGHT, ref -> ref.cacheStats.evictionWeight())); parent.gauge(idPrefix.name(Flags.useLegacyMeterNames() ? "estimatedSize" : "estimated.size"), idPrefix.tags(), this, func(null, ref -> ref.estimatedSize)); }
Example 4
Source File: NullGaugeSample.java From micrometer with Apache License 2.0 | 6 votes |
public static void main(String[] args) { MeterRegistry registry = SampleConfig.myMonitoringSystem(); AtomicInteger n = new AtomicInteger(46875392); registry.gauge("my.null.gauge", (Object) null, o -> 1.0); registry.gauge("my.nonnull.gauge", n); Flux.never().blockLast(); }
Example 5
Source File: CircuitBreakerMetrics.java From armeria with Apache License 2.0 | 6 votes |
CircuitBreakerMetrics(MeterRegistry parent, MeterIdPrefix idPrefix) { requireNonNull(parent, "parent"); requireNonNull(idPrefix, "idPrefix"); parent.gauge(idPrefix.name("state"), idPrefix.tags(), state, AtomicDouble::get); final String requests = idPrefix.name("requests"); parent.gauge(requests, idPrefix.tags("result", "success"), latestEventCount, lec -> lec.get().success()); parent.gauge(requests, idPrefix.tags("result", "failure"), latestEventCount, lec -> lec.get().failure()); final String transitions = idPrefix.name("transitions"); transitionsToClosed = parent.counter(transitions, idPrefix.tags("state", CLOSED.name())); transitionsToOpen = parent.counter(transitions, idPrefix.tags("state", OPEN.name())); transitionsToHalfOpen = parent.counter(transitions, idPrefix.tags("state", HALF_OPEN.name())); rejectedRequests = parent.counter(idPrefix.name(Flags.useLegacyMeterNames() ? "rejectedRequests" : "rejected.requests"), idPrefix.tags()); }
Example 6
Source File: MicrometerBasedMetrics.java From hono with Eclipse Public License 2.0 | 6 votes |
/** * Creates a new metrics instance. * * @param registry The meter registry to use. * @param vertx The Vert.x instance to use. * @throws NullPointerException if registry or vertx is {@code null}. */ protected MicrometerBasedMetrics(final MeterRegistry registry, final Vertx vertx) { Objects.requireNonNull(registry); Objects.requireNonNull(vertx); this.registry = registry; this.vertx = vertx; this.registry.config().onMeterRemoved(meter -> { // execution is synchronized in MeterRegistry#remove(Meter) if (METER_CONNECTIONS_AUTHENTICATED.equals(meter.getId().getName())) { authenticatedConnections.remove(meter.getId().getTag(MetricsTags.TAG_TENANT)); } }); this.unauthenticatedConnections = registry.gauge(METER_CONNECTIONS_UNAUTHENTICATED, new AtomicLong()); }
Example 7
Source File: MeteredScheduledThreadPoolExecutorMinimal.java From Hands-On-Reactive-Programming-in-Spring-5 with MIT License | 5 votes |
public MeteredScheduledThreadPoolExecutorMinimal( int corePoolSize, MeterRegistry registry ) { super(corePoolSize); registry.gauge("pool.size", this.getCorePoolSize()); registry.gauge("pool.active.tasks", this.getActiveCount()); registry.gauge("pool.queue.size", getQueue().size()); }
Example 8
Source File: DiskCleanupTask.java From genie with Apache License 2.0 | 5 votes |
/** * Constructor. Schedules this task to be run by the task scheduler. * * @param properties The disk cleanup properties to use. * @param scheduler The scheduler to use to schedule the cron trigger. * @param jobsDir The resource representing the location of the job directory * @param dataServices The {@link DataServices} instance to use * @param jobsProperties The jobs properties to use * @param processExecutor The process executor to use to delete directories * @param registry The metrics registry * @throws IOException When it is unable to open a file reference to the job directory */ public DiskCleanupTask( @NotNull final DiskCleanupProperties properties, @NotNull final TaskScheduler scheduler, @NotNull final Resource jobsDir, @NotNull final DataServices dataServices, @NotNull final JobsProperties jobsProperties, @NotNull final Executor processExecutor, @NotNull final MeterRegistry registry ) throws IOException { // Job Directory is guaranteed to exist by the MvcConfig bean creation but just in case someone overrides if (!jobsDir.exists()) { throw new IOException("Jobs dir " + jobsDir + " doesn't exist. Unable to create task to cleanup."); } this.properties = properties; this.jobsDir = jobsDir.getFile(); this.persistenceService = dataServices.getPersistenceService(); this.runAsUser = jobsProperties.getUsers().isRunAsUserEnabled(); this.processExecutor = processExecutor; this.numberOfDeletedJobDirs = registry.gauge( "genie.tasks.diskCleanup.numberDeletedJobDirs.gauge", new AtomicLong() ); this.numberOfDirsUnableToDelete = registry.gauge( "genie.tasks.diskCleanup.numberDirsUnableToDelete.gauge", new AtomicLong() ); this.unableToGetJobCounter = registry.counter("genie.tasks.diskCleanup.unableToGetJobs.rate"); this.unableToDeleteJobDirCounter = registry.counter("genie.tasks.diskCleanup.unableToDeleteJobsDir.rate"); // Only schedule the task if we don't need sudo while on a non-unix system if (this.runAsUser && !SystemUtils.IS_OS_UNIX) { log.error("System is not UNIX like. Unable to schedule disk cleanup due to needing Unix commands"); } else { final CronTrigger trigger = new CronTrigger(properties.getExpression(), JobConstants.UTC); scheduler.schedule(this, trigger); } }
Example 9
Source File: HealthCheckedEndpointGroupMetrics.java From armeria with Apache License 2.0 | 5 votes |
@Override public void bindTo(MeterRegistry registry) { final String count = idPrefix.name("count"); registry.gauge(count, idPrefix.tags("state", "healthy"), endpointGroup, unused -> endpointGroup.endpoints().size()); registry.gauge(count, idPrefix.tags("state", "unhealthy"), endpointGroup, unused -> endpointGroup.delegate.endpoints().size() - endpointGroup.endpoints().size()); final ListenerImpl listener = new ListenerImpl(registry, idPrefix.append("healthy")); listener.accept(endpointGroup.endpoints()); endpointGroup.addListener(listener); }
Example 10
Source File: DataSourcePoolMetrics.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private <N extends Number> void bindDataSource( MeterRegistry registry, String metricName, Function<DataSource, N> function ) { if ( function.apply( this.dataSource ) != null ) { registry.gauge( "jdbc.connections." + metricName, this.tags, this.dataSource, ( m ) -> function.apply( m ).doubleValue() ); } }
Example 11
Source File: MemcachedCacheMetrics.java From memcached-spring-boot with Apache License 2.0 | 5 votes |
@Override protected void bindImplementationSpecificMetrics(MeterRegistry registry) { if (cache.getNativeCache() instanceof MemcachedClient) { final MemcachedClient memcachedClient = (MemcachedClient) cache.getNativeCache(); registry.gauge("available_servers_count", memcachedClient.getAvailableServers().size()); } }
Example 12
Source File: Subscriber.java From curiostack with MIT License | 5 votes |
public Subscriber( @Provided SubscriberStub stub, @Provided Optional<MeterRegistry> meterRegistry, @Provided Tracing tracing, SubscriberOptions options) { this.stub = options.getUnsafeWrapBuffers() ? Clients.newDerivedClient( stub, GrpcClientOptions.UNSAFE_WRAP_RESPONSE_BUFFERS.newValue(true)) : stub; this.options = options; MeterRegistry registry = meterRegistry.orElse(NoopMeterRegistry.get()); List<Tag> tags = ImmutableList.of(Tag.of("subscription", options.getSubscription())); receivedMessages = registry.counter("subscriber-received-messages", tags); ackedMessages = registry.counter("subscriber-acked-messages", tags); nackedMessages = registry.counter("subscriber-nacked-messages", tags); registry.gauge("reconnect-backoff-millis", tags, streamReconnectBackoff, Duration::toMillis); messageProcessingTime = MoreMeters.newTimer(registry, "subscriber-message-processing-time", tags); tracer = tracing.tracer(); traceExtractor = tracing .propagation() .extractor((message, key) -> message.getAttributesOrDefault(key, null)); }
Example 13
Source File: GaugeSample.java From micrometer with Apache License 2.0 | 5 votes |
public static void main(String[] args) { MeterRegistry registry = SampleConfig.myMonitoringSystem(); AtomicLong n = new AtomicLong(); registry.gauge("gauge", Tags.of("k", "v"), n); registry.gauge("gauge", Tags.of("k", "v1"), n, n2 -> n2.get() - 1); RandomEngine r = new MersenneTwister64(0); Normal dist = new Normal(0, 10, r); Flux.interval(Duration.ofSeconds(5)) .doOnEach(d -> n.set(Math.abs(dist.nextInt()))) .blockLast(); }
Example 14
Source File: GaugeTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test @DisplayName("gauges attached to an object are updated when their values are observed") default void objectGauge(MeterRegistry registry) { List<String> list = registry.gauge("my.gauge", emptyList(), new ArrayList<>(), List::size); list.addAll(Arrays.asList("a", "b")); Gauge g = registry.get("my.gauge").gauge(); assertThat(g.value()).isEqualTo(2); }
Example 15
Source File: GaugeTest.java From micrometer with Apache License 2.0 | 5 votes |
@Test @DisplayName("gauges attached to a number are updated when their values are observed") default void numericGauge(MeterRegistry registry) { AtomicInteger n = registry.gauge("my.gauge", new AtomicInteger(0)); n.set(1); Gauge g = registry.get("my.gauge").gauge(); assertThat(g.value()).isEqualTo(1); n.set(2); assertThat(g.value()).isEqualTo(2); }
Example 16
Source File: HealthMetricsConfiguration.java From summerframework with Apache License 2.0 | 5 votes |
public HealthMetricsConfiguration(HealthAggregator healthAggregator, List<HealthIndicator> healthIndicators, MeterRegistry registry, PlatformTag platformTag) { healthIndicator = new CompositeHealthIndicator(healthAggregator); healthIndicators.forEach(h -> { registry.gauge("health." + h.getClass().getSimpleName().replace("HealthIndicator", "").toLowerCase(), platformTag.getTags(), h, HealthMetricsConfiguration::getStatusCode); healthIndicator.addHealthIndicator(h.toString(), h); }); registry.gauge("health", platformTag.getTags(), healthIndicator, HealthMetricsConfiguration::getStatusCode); }
Example 17
Source File: IssuesService.java From github-analytics with Apache License 2.0 | 4 votes |
IssuesService(IssuesRepository repository, MeterRegistry meterRegistry) { this.repository = repository; meterRegistry.gauge("issues", this, IssuesService::count); }
Example 18
Source File: GaugeTest.java From micrometer with Apache License 2.0 | 4 votes |
@Test @DisplayName("gauges that reference an object that is garbage collected report NaN") default void garbageCollectedSourceObject(MeterRegistry registry) { registry.gauge("my.gauge", emptyList(), (Map) null, Map::size); assertThat(registry.get("my.gauge").gauge().value()).matches(val -> val == null || Double.isNaN(val) || val == 0.0); }