Monitoring GlassFish With Java8 And Nashorn

GlassFish emits JSON monitoring data over HTTP. Java 8 comes with JavaScript "Nashorn" engine with shell scripting support. JSON stands for "JavaScript Object Notation" and is easily accessible from JavaScript:


#!/usr/bin/jjs

print("${numberOfRollbacks()} rollbacks");

function numberOfRollbacks() {
    var command = "curl http://localhost:4848/monitoring/domain/server/transaction-service/rolledbackcount.json";
    $EXEC(command)
    var result = $OUT;
    var elements = JSON.parse(result);
    return elements.extraProperties.entity.rolledbackcount.count;
}

Output is (hopefully): 0 rollbacks

The script above can be easily extended to monitor different aspects: from http, over JDBC connection pools, to even application specific performance metrics. See also: RESTful GlassFish Monitoring and Management and http://lightfish.adam-bien.com.

See you at Java EE Workshops at MUC Airport!

Comments:

If script is not working, make sure you have set monitoring-level to high in:
Configurations/server-config/Monitoring
Btw, I really like you lightFish presentation. I need to check the program out. Is deployment over the app also possible?

Posted by FilterPunk on March 06, 2014 at 11:02 AM CET #

Does glassfish supports JSONP, to integrate monitoring on websites?

Posted by Nikolai Alex on March 07, 2014 at 12:29 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License