• About this blog

    This blog features updates, opinions, and technical notes from Caucho engineers about Caucho products, the enterprise Java industry, and PHP. Caucho Technology is the creator of the Resin Application Server and the Quercus PHP in Java engine. A leader in Java performance since 1998, Caucho is a Sun JavaEE licensee with over 9000 customers worldwide.
  • Follow Caucho on Twitter

    • Tell us your thoughts about using IDEs with Resin: http://forum.caucho.com/showthread.php?t=16022 2010/08/26
    • Wondering if a CDI-based alternative to grails/roo has appeared. A groovy/CDI framework would be interesting. 2010/08/24
    • By open source experience, I mean contributions 2010/08/17
  • Tags

    ajaxworld apache bam candi cdi cloud cluster comet deploy devoxx eclipse embedded facebook flash flex google app engine hessian hmtp ioc javaone javazone jms marakana messaging mule newsletter nyjug osgi php pomegranate quercus resin resin 4.0 REST servlet sfjug silicon valley code camp training tssjs watchdog webbeans web profile websockets wordcamp wordpress
  • Meta

    • Register
    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
« replacing env-entry with CanDI @Named
ResinBeanContainer: embedding CDI for testing »

Put Resin statistics graphs into anything using REST

Sample JVM Graph from Resin Admin

Sample JVM Graph from Resin Admin

We’ve been doing a lot of work on our Resin administration application over the last few releases, adding features like statistic graphs, postmortem reports, and REST. The framework we’re building for these features is also quite extensible and easy to use. One of the in-house extensions we developed combines the REST and graph features so that you can export and embed user-defined graphs. We’ve added this extension to the main application for the upcoming 4.0.4 release so it’s available without any coding. In this blog post, I’ll show you how to embed Resin statistics graphs in your own monitoring tools, how the underlying graph API works, and give some tips on how to write your own similar extensions.

Introducing Resin statistics graphs

We’ve recently added graphs to the Resin administration application using the HTML5 <canvas> tag. Firefox 3.5 and Google Chrome support this feature, but many (most?) other browsers don’t, so you’ll need to use one of them to see the graphs. The graph feature works by selecting a set of metrics (gathered from JMX) to plot, then saving that set of metrics. For example, you could select the JVM’s heap metrics (total size and free memory), then plot those on a graph you called “JVM Heap”. In fact, that’s exactly what I’ve done below:

Creating a new graph

Creating a new graph

JVM Heap Graph

JVM Heap Graph

Creating a new graph JVM Heap Graph

Notice that when I saved the graph, I selected servers ‘00′ and ‘01′. I’m actually running a cluster of two servers in this example, but I’m collecting statistics for both of them and plotting them on the same chart.

Embedding the graph in other pages

If you notice on the graph screenshot above, you can see a link at the bottom, “Embedded graph URL”. If you click on it, you should get a raw graph directly in your browser and see the URL. You can copy that URL and embed it into any page you like, such as a custom monitoring page or even as a plugin to a framework like WordPress.

Raw REST Graph

Raw REST Graph

Raw REST Graph

For example, I’ve created 4 graphs and put them into a static HTML page with <iframe>s as such:

Custom Monitoring Page

Custom Monitoring Page

Custom Graph Layout

Behind the scenes

The graphs in this example are generated through our administration REST interface, which gives us access to JMX data including these statistics. Resin 4.0 has a new statistics gathering infrastructure which is constantly keeping track of server data for these graphs and other purposes. These data are available through a StatService MBean in Resin. The REST resources we’ve implemented in this case just graphs these statistics in an HTML5 <canvas>. In REST-speak, you’re actually creating resources each time you create a new graph and this script just retrieves them.

If you’d like to do something similar, we actually have a PHP graphing API that takes the statistics and plots them. The basic call is:

stat_graph($canvas, $width, $height, $start, $end, $names);

The $canvas argument is the id of the <canvas> element, the width and height should be obvious, $start and $end are the start and end sample boundaries (in epoch time), and the $names (an array) describe which statistics to plot. The names of the statistics need a little more description. They are string-based descriptors with a basic format:

<Server>|<Domain>|<Type>|<Attribute>

For example, Server 00’s physical memory free statistic would be encoded:

“00|OS|Memory|Physical Memory Free”

This encoding lets you do interesting things like pass in regular expressions for the names of the statistics you want to graph using this function:

stat_graph($canvas, $width, $height, $start, $end, $pattern);

The REST graph interface uses the saved graphs (which are essentially a set of statistics names) from the Resin administration application, but you can generate graphs from any set of names you like.

Conclusion

There are a lot of possibilities with the new features in the administration application, especially integration with other tools via REST. You can integrate with traditional monitoring frameworks like Nagios or even some unconventional frameworks like WordPress or Drupal. Let us know if you develop any useful patterns!

Tags: administration, canvas, graphs, html5, quercus, resin, REST

This entry was posted on Friday, January 15th, 2010 at 7:27 pm and is filed under Engineering. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.


Caucho Technology is proudly powered by WordPress and Quercus®
Entries (RSS) and Comments (RSS).