@Test public void shouldCaptureNonCounterGauge() throws Exception { GaugeConfig gaugeConfig = ImmutableGaugeConfig.builder() .mbeanObjectName("test:aaa=bbb") .addMbeanAttributes(ImmutableMBeanAttribute.of("ccc", false)) .build(); when(lazyPlatformMBeanServer.getAttribute(any(ObjectName.class), anyString())) .thenReturn(555); List<GaugeValue> gaugeValues = gaugeCollector.collectGaugeValues(gaugeConfig); assertThat(gaugeValues).hasSize(1); assertThat(gaugeValues.get(0).getValue()).isEqualTo(555); assertThat(gaugeValues.get(0).getWeight()).isEqualTo(1); }
@VisibleForTesting @RequiresNonNull("priorRawCounterValues") List<GaugeValue> collectGaugeValues(GaugeConfig gaugeConfig) throws Exception { String mbeanObjectName = gaugeConfig.mbeanObjectName(); ObjectName objectName; try { objectName = ObjectName.getInstance(mbeanObjectName); } catch (MalformedObjectNameException e) { logger.debug(e.getMessage(), e); logFirstTimeMBeanException(mbeanObjectName, e); return ImmutableList.of(); } if (!objectName.isPattern()) { return collectGaugeValues(objectName, gaugeConfig.mbeanAttributes(), mbeanObjectName); } Set<ObjectName> matchingObjectNames = lazyPlatformMBeanServer.queryNames(objectName, null); if (matchingObjectNames.isEmpty()) { logFirstTimeMBeanNotMatchedOrFound(mbeanObjectName); return ImmutableList.of(); } pendingLoggedMBeanGauges.remove(mbeanObjectName); List<GaugeValue> gaugeValues = Lists.newArrayList(); for (ObjectName matchingObjectName : matchingObjectNames) { gaugeValues.addAll(collectGaugeValues(matchingObjectName, gaugeConfig.mbeanAttributes(), matchingObjectName.getDomain() + ":" + matchingObjectName.getKeyPropertyListString())); } return gaugeValues; }
GaugeCollector extends ScheduledRunnable { @VisibleForTesting @RequiresNonNull("priorRawCounterValues") List<GaugeValue> collectGaugeValues(GaugeConfig gaugeConfig) throws Exception { String mbeanObjectName = gaugeConfig.mbeanObjectName(); ObjectName objectName; try { objectName = ObjectName.getInstance(mbeanObjectName); } catch (MalformedObjectNameException e) { logger.debug(e.getMessage(), e); logFirstTimeMBeanException(mbeanObjectName, e); return ImmutableList.of(); } if (!objectName.isPattern()) { return collectGaugeValues(objectName, gaugeConfig.mbeanAttributes(), mbeanObjectName); } Set<ObjectName> matchingObjectNames = lazyPlatformMBeanServer.queryNames(objectName, null); if (matchingObjectNames.isEmpty()) { logFirstTimeMBeanNotMatchedOrFound(mbeanObjectName); return ImmutableList.of(); } pendingLoggedMBeanGauges.remove(mbeanObjectName); List<GaugeValue> gaugeValues = Lists.newArrayList(); for (ObjectName matchingObjectName : matchingObjectNames) { gaugeValues.addAll(collectGaugeValues(matchingObjectName, gaugeConfig.mbeanAttributes(), matchingObjectName.getDomain() + ":" + matchingObjectName.getKeyPropertyListString())); } return gaugeValues; } }
GaugeCollector extends ScheduledRunnable { @VisibleForTesting @RequiresNonNull("priorRawCounterValues") List<GaugeValue> collectGaugeValues(GaugeConfig gaugeConfig) throws Exception { String mbeanObjectName = gaugeConfig.mbeanObjectName(); ObjectName objectName; try { objectName = ObjectName.getInstance(mbeanObjectName); } catch (MalformedObjectNameException e) { logger.debug(e.getMessage(), e); logFirstTimeMBeanException(mbeanObjectName, e); return ImmutableList.of(); } if (!objectName.isPattern()) { return collectGaugeValues(objectName, gaugeConfig.mbeanAttributes(), mbeanObjectName); } Set<ObjectName> matchingObjectNames = lazyPlatformMBeanServer.queryNames(objectName, null); if (matchingObjectNames.isEmpty()) { logFirstTimeMBeanNotMatchedOrFound(mbeanObjectName); return ImmutableList.of(); } pendingLoggedMBeanGauges.remove(mbeanObjectName); List<GaugeValue> gaugeValues = Lists.newArrayList(); for (ObjectName matchingObjectName : matchingObjectNames) { gaugeValues.addAll(collectGaugeValues(matchingObjectName, gaugeConfig.mbeanAttributes(), matchingObjectName.getDomain() + ":" + matchingObjectName.getKeyPropertyListString())); } return gaugeValues; } GaugeCollector(ConfigService configService, Collector collector,
            LazyPlatformMBeanServer lazyPlatformMBeanServer,
            final @Nullable Instrumentation instrumentation, Clock clock, Ticker ticker); }
GaugeCollector extends ScheduledRunnable { @VisibleForTesting @RequiresNonNull("priorRawCounterValues") List<GaugeValue> collectGaugeValues(GaugeConfig gaugeConfig) throws Exception { String mbeanObjectName = gaugeConfig.mbeanObjectName(); ObjectName objectName; try { objectName = ObjectName.getInstance(mbeanObjectName); } catch (MalformedObjectNameException e) { logger.debug(e.getMessage(), e); logFirstTimeMBeanException(mbeanObjectName, e); return ImmutableList.of(); } if (!objectName.isPattern()) { return collectGaugeValues(objectName, gaugeConfig.mbeanAttributes(), mbeanObjectName); } Set<ObjectName> matchingObjectNames = lazyPlatformMBeanServer.queryNames(objectName, null); if (matchingObjectNames.isEmpty()) { logFirstTimeMBeanNotMatchedOrFound(mbeanObjectName); return ImmutableList.of(); } pendingLoggedMBeanGauges.remove(mbeanObjectName); List<GaugeValue> gaugeValues = Lists.newArrayList(); for (ObjectName matchingObjectName : matchingObjectNames) { gaugeValues.addAll(collectGaugeValues(matchingObjectName, gaugeConfig.mbeanAttributes(), matchingObjectName.getDomain() + ":" + matchingObjectName.getKeyPropertyListString())); } return gaugeValues; } GaugeCollector(ConfigService configService, Collector collector,
            LazyPlatformMBeanServer lazyPlatformMBeanServer,
            final @Nullable Instrumentation instrumentation, Clock clock, Ticker ticker);  }
GaugeCollector extends ScheduledRunnable { @VisibleForTesting @RequiresNonNull("priorRawCounterValues") List<GaugeValue> collectGaugeValues(GaugeConfig gaugeConfig) throws Exception { String mbeanObjectName = gaugeConfig.mbeanObjectName(); ObjectName objectName; try { objectName = ObjectName.getInstance(mbeanObjectName); } catch (MalformedObjectNameException e) { logger.debug(e.getMessage(), e); logFirstTimeMBeanException(mbeanObjectName, e); return ImmutableList.of(); } if (!objectName.isPattern()) { return collectGaugeValues(objectName, gaugeConfig.mbeanAttributes(), mbeanObjectName); } Set<ObjectName> matchingObjectNames = lazyPlatformMBeanServer.queryNames(objectName, null); if (matchingObjectNames.isEmpty()) { logFirstTimeMBeanNotMatchedOrFound(mbeanObjectName); return ImmutableList.of(); } pendingLoggedMBeanGauges.remove(mbeanObjectName); List<GaugeValue> gaugeValues = Lists.newArrayList(); for (ObjectName matchingObjectName : matchingObjectNames) { gaugeValues.addAll(collectGaugeValues(matchingObjectName, gaugeConfig.mbeanAttributes(), matchingObjectName.getDomain() + ":" + matchingObjectName.getKeyPropertyListString())); } return gaugeValues; } GaugeCollector(ConfigService configService, Collector collector,
            LazyPlatformMBeanServer lazyPlatformMBeanServer,
            final @Nullable Instrumentation instrumentation, Clock clock, Ticker ticker);   }