166166import com .codahale .metrics .Metric ;
167167import com .codahale .metrics .MetricRegistry ;
168168import com .codahale .metrics .MetricSet ;
169+ import com .codahale .metrics .JmxReporter ;
169170import com .codahale .metrics .jvm .BufferPoolMetricSet ;
170171import com .codahale .metrics .jvm .GarbageCollectorMetricSet ;
171172import com .codahale .metrics .jvm .MemoryUsageGaugeSet ;
@@ -387,7 +388,11 @@ public String toString() {
387388 private boolean _dailyOrHourly = false ;
388389 protected long managementServerNodeId = ManagementServerNode .getManagementServerId ();
389390 protected long msId = managementServerNodeId ;
390- final static MetricRegistry METRIC_REGISTRY = new MetricRegistry ();
391+ public static final MetricRegistry METRIC_REGISTRY = new MetricRegistry ();
392+
393+ public static void registerMetric (String name , Metric metric ) {
394+ METRIC_REGISTRY .register (name , metric );
395+ }
391396
392397 public static StatsCollector getInstance () {
393398 return s_instance ;
@@ -410,6 +415,11 @@ public boolean start() {
410415 registerAll ("memory" , new MemoryUsageGaugeSet (), METRIC_REGISTRY );
411416 registerAll ("threads" , new ThreadStatesGaugeSet (), METRIC_REGISTRY );
412417 registerAll ("jvm" , new JvmAttributeGaugeSet (), METRIC_REGISTRY );
418+ try {
419+ JmxReporter .forRegistry (METRIC_REGISTRY ).inDomain ("vm-extra" ).build ().start ();
420+ } catch (Exception e ) {
421+ LOGGER .warn ("Failed to start JMX reporter for METRIC_REGISTRY; CloudOS metrics will not be visible via JMX: " + e .getMessage ());
422+ }
413423 return true ;
414424 }
415425 @ Override
0 commit comments