Unfortunately, you cannot directly access JMX from languages ββother than Java; which means you cannot write.
There are two ways to pull MBean data from other languages, although not very intuitively.
Bridge method
This method involves creating a Java client bridge to extract the MBeans JMX and then exchange it back to Go.
Fortunately, I really did it; specially for Go; you can get the code here . If you need recording capabilities, feel free to change this code and send me a PR.
Then you can use a tool like go-bindata to insert the jar into the Go binary; you would use os.Exec to run; for example (obviously, you first need to read go-bindata docs first on how to manage these assets):
// RunJar runs the embedded mjb.jar returning the output from STDOUT func RunJar(host string, port int) (string, error) { nport := strconv.Itoa(port) _, err := os.Stat("/tmp/mjb.jar") if err != nil { return "", err } // Check that /usr/bin/java exists _, err = os.Stat("/usr/bin/java") if err != nil { return "", err } cmd := exec.Command("/usr/bin/java", "-jar", "/tmp/mjb.jar", host, nport) var out bytes.Buffer var erro bytes.Buffer cmd.Stdout = &out cmd.Stderr = &erro err = cmd.Run() if err != nil { return "", fmt.Errorf("%s %s", err.Error(), out.String()) } return out.String(), nil }
Jolokia Method
This method includes embedding Jolokia in your Java application; obviously this only works for the java applications you support; and will not work for Java applications such as Cassandra or Kafka.
source share