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:


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

function numberOfRollbacks() {
    var command = "curl http://localhost:4848/monitoring/domain/server/transaction-service/rolledbackcount.json";
    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

See you at Java EE Workshops at MUC Airport!


If script is not working, make sure you have set monitoring-level to high in:
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