Telegraf - how to monitor multiple Tomcat instances?

Viewed 3631

I managed to gather data from single Tomcat instance to Telegraf as follows.

[[inputs.tomcat]]
  ## URL of the Tomcat server status
   url = "http://127.0.0.1:19090/manager/status/all?XML=true"

  ## HTTP Basic Auth Credentials
   username = "admin"
   password = "fD*(*DSS"

  ## Request timeout
  # timeout = "5s"

  ## Optional SSL Config
  # ssl_ca = "/etc/telegraf/ca.pem"
  # ssl_cert = "/etc/telegraf/cert.pem"
  # ssl_key = "/etc/telegraf/key.pem"
  ## Use SSL but skip chain & host verification
  # insecure_skip_verify = false

Now, I want to monitor multiple Tomcat instances, but there does not seem to be an example of how to monitor multiple. Does anybody know?

2 Answers

The answer turned out to be very simple. Just declare the inputs.tomcat block multiple times as follows.

[[inputs.tomcat]]
  ## URL of the Tomcat server status
   url = "http://127.0.0.1:19090/manager/status/all?XML=true"

  ## HTTP Basic Auth Credentials
   username = "admin"
   password = "fD*(*DSS"

[[inputs.tomcat]]
  ## URL of the Tomcat server status
   url = "http://127.0.0.1:29090/manager/status/all?XML=true"

  ## HTTP Basic Auth Credentials
   username = "admin"
   password = "fD*(*DSS"

So as far as I recall there are couple of ways.

1) Easiest way is to create, use and try via using different configuration files where you may create tomcat1.conf place it under /etc/telegraf/telegraf.d/tomcat1.conf folder where you'd end up using the same plugin that you have mentioned above (inputs.tomcat) and similarly, create another configuration file for tomcat2.conf etc.. for all Tomcat instances. This way you may be able to monitor multiple Tomcat instances. See if that helps! Con of this approach is, you have to create N no. of tomcatXX.conf files under telegrad.d folder (Which can be easily fixed if you create these files on the fly while provisioning a machine using Ansible/similar tools - templating the file and iterating over the tomcatXX list).

2) Other way, which which may help as well using just one configuration file. In one configuration file, use the following plugins together to capture what you are looking for. PS: If you use inputs.exec plugin, then the output you'll generate from your custom script (which you'll call in inputs.exec plugin) must generate the output in a known format (InfluxDB/Line Protocol) that Telegraf and InfluxDB can understand / store or you'll see some minor errors for which you can see few of my posts.

exec plugin: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/exec http_* plugin (especially http_response): https://github.com/influxdata/telegraf/tree/master/plugins/inputs/exec filestat plugin: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/filestat logparser plugin: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/logparser procstat plugin: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/procstat

Look at the plugin links mentioned above for what they do and how to set them up in Telegraf and that'd get you most of what you are looking at if you don't want to have multiple conf files for each Tomcat instance.

https://github.com/influxdata/telegraf/tree/master/plugins/inputs contains all input plugins (see if there are some that you may be interested in).

See if you can utilize how to use prefix property efficiently to distinguish between various metrics/events coming from using these plugin(s).

Related