Skip to content

Instantly share code, notes, and snippets.

@sysdig-blog
Created April 23, 2019 17:22
Show Gist options
  • Save sysdig-blog/a68c82593a0c28f892c04baa5d4dc405 to your computer and use it in GitHub Desktop.
Save sysdig-blog/a68c82593a0c28f892c04baa5d4dc405 to your computer and use it in GitHub Desktop.
Create MBean and register in the MBean server
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();
}
}
}
@besza
Copy link

besza commented May 3, 2019

Hi Sysdig! Could you please include the correct Github gist in your "JMX monitoring + Java custom metrics" article?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment