@Test public void testHistogramReporting() throws Exception { MetricRegistryImpl registry = null; String histogramName = "histogram"; try { registry = new MetricRegistryImpl( MetricRegistryConfiguration.defaultMetricRegistryConfiguration(), Collections.singletonList(ReporterSetup.forReporter("test", new JMXReporter(null)))); TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId"); TestHistogram histogram = new TestHistogram(); metricGroup.histogram(histogramName, histogram); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager." + histogramName, JMXReporter.generateJmxTable(metricGroup.getAllVariables())); MBeanInfo info = mBeanServer.getMBeanInfo(objectName); MBeanAttributeInfo[] attributeInfos = info.getAttributes(); assertEquals(11, attributeInfos.length); assertEquals(histogram.getCount(), mBeanServer.getAttribute(objectName, "Count")); assertEquals(histogram.getStatistics().getMean(), mBeanServer.getAttribute(objectName, "Mean")); assertEquals(histogram.getStatistics().getStdDev(), mBeanServer.getAttribute(objectName, "StdDev")); assertEquals(histogram.getStatistics().getMax(), mBeanServer.getAttribute(objectName, "Max")); assertEquals(histogram.getStatistics().getMin(), mBeanServer.getAttribute(objectName, "Min")); assertEquals(histogram.getStatistics().getQuantile(0.5), mBeanServer.getAttribute(objectName, "Median")); assertEquals(histogram.getStatistics().getQuantile(0.75), mBeanServer.getAttribute(objectName, "75thPercentile")); assertEquals(histogram.getStatistics().getQuantile(0.95), mBeanServer.getAttribute(objectName, "95thPercentile")); assertEquals(histogram.getStatistics().getQuantile(0.98), mBeanServer.getAttribute(objectName, "98thPercentile")); assertEquals(histogram.getStatistics().getQuantile(0.99), mBeanServer.getAttribute(objectName, "99thPercentile")); assertEquals(histogram.getStatistics().getQuantile(0.999), mBeanServer.getAttribute(objectName, "999thPercentile")); } finally { if (registry != null) { registry.shutdown().get(); } } }
static Hashtable<String, String> generateJmxTable(Map<String, String> variables) { Hashtable<String, String> ht = new Hashtable<>(variables.size()); for (Map.Entry<String, String> variable : variables.entrySet()) { ht.put(replaceInvalidChars(variable.getKey()), replaceInvalidChars(variable.getValue())); } return ht; }
JMXReporter implements MetricReporter { static Hashtable<String, String> generateJmxTable(Map<String, String> variables) { Hashtable<String, String> ht = new Hashtable<>(variables.size()); for (Map.Entry<String, String> variable : variables.entrySet()) { ht.put(replaceInvalidChars(variable.getKey()), replaceInvalidChars(variable.getValue())); } return ht; } }
JMXReporter implements MetricReporter { static Hashtable<String, String> generateJmxTable(Map<String, String> variables) { Hashtable<String, String> ht = new Hashtable<>(variables.size()); for (Map.Entry<String, String> variable : variables.entrySet()) { ht.put(replaceInvalidChars(variable.getKey()), replaceInvalidChars(variable.getValue())); } return ht; } JMXReporter(@Nullable final String portsConfig); }
JMXReporter implements MetricReporter { static Hashtable<String, String> generateJmxTable(Map<String, String> variables) { Hashtable<String, String> ht = new Hashtable<>(variables.size()); for (Map.Entry<String, String> variable : variables.entrySet()) { ht.put(replaceInvalidChars(variable.getKey()), replaceInvalidChars(variable.getValue())); } return ht; } JMXReporter(@Nullable final String portsConfig); @Override void open(MetricConfig config); @Override void close(); Optional<Integer> getPort(); @Override void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group); @Override void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group); }
JMXReporter implements MetricReporter { static Hashtable<String, String> generateJmxTable(Map<String, String> variables) { Hashtable<String, String> ht = new Hashtable<>(variables.size()); for (Map.Entry<String, String> variable : variables.entrySet()) { ht.put(replaceInvalidChars(variable.getKey()), replaceInvalidChars(variable.getValue())); } return ht; } JMXReporter(@Nullable final String portsConfig); @Override void open(MetricConfig config); @Override void close(); Optional<Integer> getPort(); @Override void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group); @Override void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group);  }