Written by The Jahia Team
 
Developers
Sysadmins
   Estimated reading time:

I want to integrate Jolokia with Jahia and use Telegraf as a client to get JVM metrics from Jahia. How can I do that?

Answer

Integrating Jolokia and Telegraf with Jahia is very easy. The next steps show how to integrate Jolokia with Jahia to get JVM metrics and also how to use Telegraf to consume metrics provided by Jolokia and store them in a server file.

Installing and Integrating Jolokia with Jahia

First download and decompress jolokia bins using this link.

Then go to the Jolokia folder and copy the file jolokia.war to your webapps directory in Jahia:

cp jolokia-1.6.2/agents/jolokia.war <JAHIA_FOLDER>/tomcat/webapps/

After that you should see the following logs from catalina:

20-Feb-2020 10:18:38.694 INFO [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/Users/wernernedel/Jahia/Public/JAHIA7340/tomcat/webapps/jolokia.war]
20-Feb-2020 10:18:38.783 INFO [Catalina-utility-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
20-Feb-2020 10:18:48.865 INFO [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/Users/wernernedel/Jahia/Public/JAHIA7340/tomcat/webapps/jolokia.war] has finished in [10,172] ms

Jolokia is now installed and running. If you access http://localhost:8080/jolokia/version you will be asked for Jolokia credentials. By now we are commenting out the authentication in file <JAHIA_FOLDER>/tomcat/webapps/jolokia/WEB-INF/web.xml

  <!--
  Security enabled by default. Please update to match you specific security setup (e.g. the auth-method)
  <login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>jolokia</realm-name>
  </login-config>

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Jolokia-Agent Access</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>jolokia</role-name>
    </auth-constraint>
  </security-constraint>

  <security-role>
    <role-name>jolokia</role-name>
  </security-role>
  -->

After saving the file you will see the following catalina logs:

20-Feb-2020 13:48:04.781 INFO [Catalina-utility-1] org.apache.catalina.startup.HostConfig.reload Reloading context [/jolokia]
20-Feb-2020 13:48:04.781 INFO [Catalina-utility-1] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/jolokia] has started
20-Feb-2020 13:48:04.845 INFO [Catalina-utility-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
20-Feb-2020 13:48:14.923 INFO [Catalina-utility-1] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/jolokia] is completed

And now when you access http://localhost:8080/jolokia/version you should get a response similar to this:

{"request":{"type":"version"},"value":{"agent":"1.6.2","protocol":"7.2","config":{"listenForHttpService":"true","maxCollectionSize":"0","authIgnoreCerts":"false","agentId":"192.168.1.167-34190-55cfe2ae-servlet","agentType":"servlet","policyLocation":"classpath:\/jolokia-access.xml","agentContext":"\/jolokia","mimeType":"text\/plain","discoveryEnabled":"false","streaming":"true","historyMaxEntries":"10","allowDnsReverseLookup":"true","maxObjects":"0","debug":"false","serializeException":"false","detectorOptions":"{}","dispatcherClasses":"org.jolokia.http.Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher","maxDepth":"15","authMode":"basic","authMatch":"any","canonicalNaming":"true","allowErrorDetails":"true","realm":"jolokia","includeStackTrace":"true","useRestrictorService":"false","debugMaxEntries":"100"},"info":{"product":"tomcat","vendor":"Apache","version":"9.0.24"}},"timestamp":1582224539,"status":200}

Jolokia is now up and running. This tutorial is based on Jolokia quick install tutorial. There you will see an example of a simple Java client to gather metrics from Jahia JVM using Jolokia.

Setting up Telegraf client

Telegraf is an agent written in Go for collecting metrics and writing them into InfluxDB or other possible outputs. Here we are going to show you how to set up a simple Telegraf configuration to receive metrics from Jolokia and output them into a file in the server.

First you need to install Telegraf in your server or any other place able to communicate with the host/ip from Jolokia by following the instructions in here.

Now we need to configure Telegraf to receive metrics from Jolokia as input and to store this data in a server file as output. The location of the default configuration file changes depending on the OS so please check this section.

If you are using linux for instance, then you should open the file /etc/telegraf/telegraf.conf and edit it like this:

  • Choose your agent configurations on section [agent]. The default configuration is ok though it is advised to choose at least the interval you want the metrics to be fetched:
[agent]
  ## Default data collection interval for all inputs
  interval = "10s"
  ## Rounds collection interval to 'interval'
  ## ie, if interval="10s" then always collect on :00, :10, :20, etc.
  round_interval = true
  • Telegraf configures influxdb as an output by default so let's comment it out by now:
# Configuration for sending metrics to InfluxDB
#[[outputs.influxdb]]
  • Now let's choose the plugin jolokia2_agent as an input:
# # Read JMX metrics from a Jolokia REST agent endpoint
 [[inputs.jolokia2_agent]]
#   # default_tag_prefix      = ""
#   # default_field_prefix    = ""
#   # default_field_separator = "."
#
#   # Add agents URLs to query
   urls = ["http://localhost:8080/jolokia"]
#   # username = ""
#   # password = ""
 response_timeout = "20s"
#
#   ## Optional TLS config
#   # tls_ca   = "/var/private/ca.pem"
#   # tls_cert = "/var/private/client.pem"
#   # tls_key  = "/var/private/client-key.pem"
#   # insecure_skip_verify = false
#
#   ## Add metrics to read
   [[inputs.jolokia2_agent.metric]]
     name  = "java_runtime"
     mbean = "java.lang:type=Runtime"
     paths = ["Uptime"]
  • And finally we set the output to a file in the server:
# # Send telegraf metrics to file(s)
 [[outputs.file]]
#   ## Files to write to, "stdout" is a specially handled file.
   files = ["stdout", "/Users/wernernedel/Jahia/Public/telegraf/metrics.out"]
#
#   ## Use batch serialization format instead of line based delimiting.  The
#   ## batch format allows for the production of non line based output formats and
#   ## may more effiently encode metric groups.
#   # use_batch_format = false
#
#   ## The file will be rotated after the time interval specified.  When set
#   ## to 0 no time based rotation is performed.
    rotation_interval = "1d"
#
#   ## The logfile will be rotated when it becomes larger than the specified
#   ## size.  When set to 0 no size based rotation is performed.
#   # rotation_max_size = "0MB"
#
#   ## Maximum number of rotated archives to keep, any older logs are deleted.
#   ## If set to -1, no archives are removed.
 rotation_max_archives = 5
#
#   ## Data format to output.
#   ## Each data format has its own unique set of configuration options, read
#   ## more about them here:
#   ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
   data_format = "influx"

 

Now we are ready to run Telegraf and start gathering metrics from Jahia by running the following command (please remember we are using Linux as an example):

telegraf --config /etc/telegraf/telegraf.conf

If everything is OK you should see the following logs:

2020-02-20T19:23:59Z I! Starting Telegraf 1.13.3
2020-02-20T19:23:59Z I! Loaded inputs: diskio mem system jolokia2_agent cpu disk swap kernel processes
2020-02-20T19:23:59Z I! Loaded aggregators: 
2020-02-20T19:23:59Z I! Loaded processors: 
2020-02-20T19:23:59Z I! Loaded outputs: file
2020-02-20T19:23:59Z I! Tags enabled: host=wnedel-macbook.local
2020-02-20T19:23:59Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"wnedel-macbook.local", Flush Interval:10s

So now you should see several metrics stored in the configured file /Users/wernernedel/Jahia/Public/telegraf/metrics.out every 10 seconds, the configured interval for Telegraf agent.

Related links