{"id":448,"date":"2014-08-08T21:25:47","date_gmt":"2014-08-08T19:25:47","guid":{"rendered":"http:\/\/blog.johannes-beck.name\/?p=448"},"modified":"2014-08-10T18:27:59","modified_gmt":"2014-08-10T16:27:59","slug":"monitoring-jboss-wildfly-with-jolokia-and-graphite","status":"publish","type":"post","link":"https:\/\/blog.johannes-beck.name\/?p=448","title":{"rendered":"Monitoring JBoss Wildfly with Jolokia and Graphite"},"content":{"rendered":"<p>Once you have a running Java application server (in production), you are need of some kind of monitoring of the JVM&#8217;s main parameter (Memory, Threads), the datasources, queues, calls and different metrics provided by the applications. In this post I&#8217;ll show how to set up a monitoring chain for JBoss Wildfly. The main ingredients are the JMX subsystem of the Java Virtual Machine, Jolokia, collectd and Graphite.<\/p>\n<p><a href=\"http:\/\/graphite.readthedocs.org\/en\/latest\/\">Graphite<\/a> is a widely used monitoring system. There are many good tutorials which show how to set it up and running, so in this tutorial you have already a graphite server running at a server <b>graphite.example.com<\/b>. I also assume that the JBoss server is already installed, so I&#8217;ll skip this too. The JBoss server shall be running at jboss01.example.com<\/p>\n<p>First you need to download the WAR provided by <a href=\"http:\/\/jolokia.org\">Jolokia<\/a> and deploy it to JBoss Wildfly. Jolokia is a JMX agent which allows you to query all JMX Beans over HTTP.<\/p>\n<p><code><br \/>\n\/opt\/wildfly\/bin\/jboss-cli.sh --connect \"deploy jolokia.war\"<br \/>\n<\/code><\/p>\n<p>Now you can check <a href=\"http:\/\/jboss01.example.com:8080\/jolokia\/\">http:\/\/jboss01.example.com:8080\/jolokia\/<\/a> that Jolokia is deployed. The response will return some basic information about Jolokia as JSON.<\/p>\n<p>Next we&#8217;ll need to install collectd, a general monitoring agent which can retrieve monitoring data from many services through its plugins. We will install collectd and the JSON-curl plugin which is needed to read the data from Jolokia on jboss01.example.com. In Fedora Linux this can be done with<\/p>\n<p><code><br \/>\nyum install collectd collectd_json-curl<br \/>\nsystemctl enable collectd<br \/>\n<\/code><\/p>\n<p>Before we start the collecd agent we need some configuration. In \/etc\/collectd.conf you need to enable the plugins for graphite and curl_json.<\/p>\n<p><code><br \/>\n#<br \/>\n# Config file for collectd(1).<br \/>\n# Please read collectd.conf(5) for a list of options.<br \/>\n# http:\/\/collectd.org\/<br \/>\n#<br \/>\n...<br \/>\nLoadPlugin curl_json<br \/>\n...<br \/>\nLoadPlugin write_graphite<br \/>\n...<br \/>\n&lt;Plugin write_graphite&gt;<br \/>\n  &lt;Node \"jboss01\"&gt;<br \/>\n    Host \"graphite.example.com\"<br \/>\n    Port \"2003\"<br \/>\n    Protocol \"tcp\"<br \/>\n    LogSendErrors true<br \/>\n#    Prefix \"collectd\"<br \/>\n#    Postfix \"collectd\"<br \/>\n#    StoreRates true<br \/>\n#    AlwaysAppendDS false<br \/>\n#    EscapeCharacter \"_\"<br \/>\n  &lt;\/Node><br \/>\n&lt;\/Plugin&gt;<br \/>\n...<br \/>\nInclude \"\/etc\/collectd.d\"<br \/>\n<\/code><\/p>\n<p>and for specifying the JMX values which we want to monitor we set up a new file \/etc\/collectd.d\/wildfly.conf with <\/p>\n<p><code><br \/>\n&lt;Plugin curl_json&gt;<br \/>\n    &lt;URL \"http:\/\/jboss01.example.com:8080\/jolokia\/read\/java.lang:type=Memory\"&gt;<br \/>\n        Instance \"Memory\"<br \/>\n        &lt;Key \"value\/NonHeapMemoryUsage\/*\"&gt;<br \/>\n            Type \"memory\"<br \/>\n        &lt;\/Key><br \/>\n        &lt;Key \"value\/HeapMemoryUsage\/*\"&gt;<br \/>\n            Type \"memory\"<br \/>\n        &lt;\/Key><br \/>\n    &lt;\/URL><br \/>\n    &lt;URL \"http:\/\/jboss01.example.com:8080\/jolokia\/read\/java.lang:type=Threading\/ThreadCount\"&gt;<br \/>\n        Instance \"ThreadCount\"<br \/>\n        &;ltKey \"value\"&gt;<br \/>\n            Type \"gauge\"<br \/>\n        &lt;\/Key&gt;<br \/>\n    &lt;\/URL&gt;<br \/>\n    &lt;URL \"http:\/\/jboss01.example.com:8080\/jolokia\/read\/java.lang:type=OperatingSystem\/OpenFileDescriptorCount\"&gt;<br \/>\n        Instance \"OpenFiles\"<br \/>\n        &lt;Key \"value\"&gt;<br \/>\n            Type \"gauge\"<br \/>\n        &lt;\/Key&gt;<br \/>\n    &lt;\/URL><br \/>\n    &lt;URL \"http:\/\/jboss01.example.com:8080\/jolokia\/read\/jboss.as:subsystem=datasources,data-source=ExampleDS,statistics=pool\"&gt;<br \/>\n        Instance \"ExampleDS\"<br \/>\n        &lt;Key \"value\/ActiveCount\"&gt;<br \/>\n            Type \"gauge\"<br \/>\n        &lt;\/Key&gt;<br \/>\n        &lt;Key \"value\/AvailableCount\"&gt;<br \/>\n            Type \"gauge\"<br \/>\n        &lt;\/Key&gt;<br \/>\n    &lt;\/URL&gt;<br \/>\n&lt;\/Plugin><br \/>\n<\/code><\/p>\n<p>The syntax is pretty straightforward. Each JMX bean you want to query is specified with the URL with which it will be retrieved from Jolokia. Each attribute from the JSON result set is defined by the Key. You can use wildcards within the keys. This example retrieves the JVM parameters for Memory, Threads and Open Files as well as the key values of the DataSource ExampleDS. If you want to monitor different values you need to provide the name of the JMX bean. jvisualvm is a great tool to inspect JMX beans. JBoss Wildfly provides a lot of JMX beans out of the box (e.g. for JMS queues) and if you enable the statistics for EJBs, Transactions, Servlets etc. all of those can be retrieved like this. You can also write your own JMX beans and deploy it with your application code.<\/p>\n<p>Now you can start the collectd service with<\/p>\n<p><code>systemctl start collectd<\/code> <\/p>\n<p>and should the the values appear at jboss01_example_com.curl_json-INSTANCE, with the name of the instance you have defined in the configuration file above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once you have a running Java application server (in production), you are need of some kind of monitoring of the JVM&#8217;s main parameter (Memory, Threads), the datasources, queues, calls and different metrics provided by the applications. In this post I&#8217;ll show how to set up a monitoring chain for JBoss Wildfly. The main ingredients are [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,43,36],"tags":[47,24],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-java","category-jboss-as7","category-linux","tag-jboss-wildfly","tag-jmx"],"_links":{"self":[{"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=448"}],"version-history":[{"count":5,"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=\/wp\/v2\/posts\/448\/revisions"}],"predecessor-version":[{"id":453,"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=\/wp\/v2\/posts\/448\/revisions\/453"}],"wp:attachment":[{"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.johannes-beck.name\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}