Created
November 9, 2016 03:20
-
-
Save hashbrowncipher/d3ba84cf51912f9b4d61f7e538f1e691 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.josnyder; | |
import java.lang.management.ManagementFactory; | |
import javax.management.InstanceAlreadyExistsException; | |
import javax.management.MBeanServer; | |
import javax.management.ObjectName; | |
import org.apache.cassandra.service.CassandraDaemon; | |
class HotspotMBeanCassandraDaemon extends CassandraDaemon { | |
protected void setup() { | |
super.setup(); | |
Object runtimeMBean = null; | |
try { | |
runtimeMBean = Class.forName("sun.management.ManagementFactoryHelper") | |
.getMethod("getHotspotRuntimeMBean") | |
.invoke(null); | |
} catch(Exception e) { | |
System.err.println("Couldn't get mbean"); | |
} | |
if(runtimeMBean != null) { | |
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | |
try { | |
mbs.registerMBean(runtimeMBean, new ObjectName("com.josnyder.hotspot:type=RuntimeMBean")); | |
} catch(Exception e) { | |
System.err.println("Couldn't register mbean"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment