Created
April 23, 2019 17:22
-
-
Save sysdig-blog/a68c82593a0c28f892c04baa5d4dc405 to your computer and use it in GitHub Desktop.
Create MBean and register in the MBean server
This file contains 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
import javax.management.*; | |
import java.lang.management.ManagementFactory; | |
public class Main { | |
public static void main(String[] args) { | |
try { | |
String programName = (args.length == 0) ? "Java" : args[0]; | |
// Initialize the object | |
SystemStatus systemStatus = new SystemStatus(programName); | |
// Register the object in the MBeanServer | |
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); | |
ObjectName objectName = new ObjectName("com.sysdig.app:name=SystemStatusExample"); | |
platformMBeanServer.registerMBean(systemStatus, objectName); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Sysdig! Could you please include the correct Github gist in your "JMX monitoring + Java custom metrics" article?