Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a long[] parameter? #15

Open
flaviolsousa opened this issue Oct 27, 2017 · 2 comments
Open

Use a long[] parameter? #15

flaviolsousa opened this issue Oct 27, 2017 · 2 comments

Comments

@flaviolsousa
Copy link

Code:

"use strict";
var jmx = require("jmx");

var client = jmx.createClient({
  host: "localhost",
  port: 9011
});

client.connect();
client.on("connect", function () {

  client.getAttribute("java.lang:type=Memory", "HeapMemoryUsage", function (data) {
    var used = data.getSync('used').longValue;
    var max = data.getSync('max').longValue;
    var percent = used / max;
    console.log("Threads used: " + used + " / " + max + " = " + percent.toFixed(2) + "%");
  });

  client.getAttribute("java.lang:type=Threading", "AllThreadIds", function (data) {
    console.log('data: ' + JSON.stringify(data));

    var ids = [data[0].longValueSync(), data[1].longValueSync()];
    console.log(Object.prototype.toString.call(ids) === "[object Array]"); // true
    console.log('ids[0].longValue: ', JSON.stringify(ids[0].longValue));
    console.log('ids: ', JSON.stringify(ids));

    client.invoke("java.lang:type=Threading", "getThreadInfo", [ids], ['long[]'], function (data) { // ????????????????
      console.log("Threading.getThreadInfo", JSON.stringify(data));
    });
  });

  client.setAttribute("java.lang:type=Memory", "Verbose", true, function () {
    console.log("Memory verbose on"); // callback is optional 
  });
});

Output:

PS C:\tmp\watch-jmx> node index.js
Threads used: 923329448 / 1048576000 = 0.88%
data: [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},
{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{
},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}
,{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},
{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
true
ids.longValue:  "30285"
ids:  [30285,30284]
C:\tmp\watch-jmx\node_modules\jmx\lib\javaJmx.js:116
          value = java.newInstanceSync(className, value);
                       ^

Error: Could not create class long[]
java.lang.NoClassDefFoundError: long[]
Caused by: java.lang.ClassNotFoundException: long[]
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

    at Error (native)
    at C:\tmp\watch-jmx\node_modules\jmx\lib\javaJmx.js:116:24
    at Array.forEach (native)
    at JavaJmx.jsParams2JavaParams (C:\tmp\watch-jmx\node_modules\jmx\lib\javaJmx.js:111:15)
    at JavaJmx.invoke (C:\tmp\watch-jmx\node_modules\jmx\lib\javaJmx.js:133:40)
    at Client.invoke (C:\tmp\watch-jmx\node_modules\jmx\lib\client.js:61:16)
    at C:\tmp\watch-jmx\index.js:31:12
    at C:\tmp\watch-jmx\node_modules\jmx\lib\adapters\javaReflection.js:49:7
    at C:\tmp\watch-jmx\node_modules\jmx\lib\adapters\javaReflection.js:43:7
@zuazo
Copy link
Owner

zuazo commented Oct 30, 2017

@flaviolsousa thanks for the report.

If you have a fix, PRs are welcome 😃

@flaviolsousa
Copy link
Author

Although it is slower and consuming more of the VM I am doing:

var jmx = require("jmx");

var client = jmx.createClient({
  host: "localhost",
  port: 9011
});

client.connect();
client.on("connect", function () {
  client.getAttribute("java.lang:type=Threading", "AllThreadIds", function (data) {
    for (var i = 0; i < data.length; i++) {
      var id = 0 + data[i].longValueSync();

      client.invoke("java.lang:type=Threading", "getThreadInfo", [id], ['long'], function (data) {
        console.log("threadName: ", data.getSync('threadName'));
      });
    }
  });
});

Output:

threadName:  JMX server connection timeout 29948
threadName:  [ACTIVE] ExecuteThread: '113' for queue: 'weblogic.kernel.Default (self-tuning)'
threadName:  pool-2-thread-5
threadName:  [ACTIVE] ExecuteThread: '106' for queue: 'weblogic.kernel.Default (self-tuning)'
threadName:  [ACTIVE] ExecuteThread: '104' for queue: 'weblogic.kernel.Default (self-tuning)'
threadName:  pool-2-thread-4
threadName:  [ACTIVE] ExecuteThread: '103' for queue: 'weblogic.kernel.Default (self-tuning)'
threadName:  [ACTIVE] ExecuteThread: '102' for queue: 'weblogic.kernel.Default (self-tuning)'
threadName:  pool-2-thread-3
threadName:  DynamicListenThread[Default]
threadName:  pool-2-thread-2

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

No branches or pull requests

2 participants