adam bien's blog

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!