Java Code Examples for io.micrometer.core.instrument.MeterRegistry#gaugeMapSize()

The following examples show how to use io.micrometer.core.instrument.MeterRegistry#gaugeMapSize() . 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: AgentRoutingServiceCuratorDiscoveryImpl.java    From genie with Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source File: GaugeTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("gauges can be directly associated with map entry size")
default void mapSizeGauge(MeterRegistry registry) {
    Map<String, Integer> map = registry.gaugeMapSize("my.gauge", emptyList(), new HashMap<>());
    map.put("a", 1);

    Gauge g = registry.get("my.gauge").gauge();
    assertThat(g.value()).isEqualTo(1);
}