[LINUX] Monitor Tomcat process with Zabbix-agent

how can I do?

I will make a monitoring item for the startup process of Tomcat. First, check the operation with zabbix_get.

$ zabbix_get -s 192.168.200.24 -k proc.num[httpd]
6
$ zabbix_get -s 192.168.200.24 -k proc.num[tomcat]
0

How do I get tomcat ...?

The answer is this

$ zabbix_get -s 192.168.200.24 -k proc.num[java,,,"org.apache.catalina.startup.Bootstrap start"]
1

environment

Read the reference properly

Zabbix Documentation 2.2 had a usage, so if you look it up, you need to know the process name. Know that.

proc.num[<name>,<user>,<state>,<cmdline>]

--name --Process name (default is "all processes") --user --User name (default is "all users") --state --possible values: all (default), run, sleep, zomb --cmdline --Command line filter (regular expression)

Look up the tomcat process name

Check the status of running tomcat.

$ systemctl status tomcat
● tomcat.service - Apache Tomcat 8
   Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: disabled)
   Active: active (exited)since tree 2020-02-06 15:01:19 JST; 1h 29min ago
  Process: 844 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 844 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/tomcat.service
           └─875 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.prot...

February 06 15:01:19 192.168.200.24 systemd[1]: Starting Apache Tomcat 8...
February 06 15:01:19 192.168.200.24 systemd[1]: Started Apache Tomcat 8.

Examine PID875 further.

$ cat /proc/875/stat 
875 (java) S 1 844 844 0 -1 1077944320 19379 0 124 0 937 64 0 0 20 0 41 0 752 2357014528 21813 18446744073709551615 4194304 4196524 140724105374304 140724105356960 140023800299543 0 0 2 16800973 18446744073709551615 0 0 17 0 0 0 5 0 0 6294912 6295604 12607488 140724105383058 140724105383592 140724105383592 140724105383914 0

The part enclosed in () is the process name. The name of the process running tomcat seems to be java.

Solution (wrong)

$ zabbix_get -s 192.168.200.24 -k proc.num[java]
1

I got it!

... but suddenly notice. This is just a Java process, and it cannot be determined whether it is a tomcat process.

Check the process again

$ ps aux | grep java
tomcat     875  0.1  8.6 2301772 87452 ?       Sl   15:01   0:10 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat -Dcatalina.home=/opt/tomcat -Djava.io.tmpdir=/opt/tomcat/temp org.apache.catalina.startup.Bootstrap start

Apparently this process is being run by tomcat.

$ zabbix_get -s 192.168.200.24 -k proc.num[java,tomcat]
1

I got it.

However, if you think about it carefully, the tomcat user is just executing the java command. I noticed that I'm not monitoring the ** Tomcat startup process **.

Check again

I checked the process and noticed. The option was long and difficult to understand, but there is a description of the startup process (ʻorg.apache.catalina.startup.Bootstrap start`).

$ ps aux | grep java
tomcat    2023 83.6  7.3 2299724 74204 ?       Sl   17:26   0:02 

/usr/bin/java 
  -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties 
  -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 
  -Djdk.tls.ephemeralDHKeySize=2048 
  -Djava.protocol.handler.pkgs=org.apache.catalina.webresources 
  -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 
  -Dignore.endorsed.dirs= 
  -classpath /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar 
  -Dcatalina.base=/opt/tomcat 
  -Dcatalina.home=/opt/tomcat 
  -Djava.io.tmpdir=/opt/tomcat/temp 
  org.apache.catalina.startup.Bootstrap start

proc.num[<name>,<user>,<state>,<cmdline>] It seems that it can be extracted by using the command line of the 4th argument.

$ zabbix_get -s 192.168.200.24 -k proc.num[java,,,"org.apache.catalina.startup.Bootstrap start"]
1

I was able to get the count of the startup process safely. I didn't write it because I thought it didn't make much sense to be a tomcat user.

At the end

I wrote it for a long time. I also saw a description that says proc.num [java, tomcat], so I introduced this.

Supplement

Depending on how you install Tomcat, it may differ from the above method, but if you know how to check it, the application will work. In my case, I downloaded and expanded the source and installed it. Reference: I tried to link Apache and Tomcat

Recommended Posts

Monitor Tomcat process with Zabbix-agent
Gaussian process with pymc3
[blackbird-redis] Monitor Redis with blackbird
[blackbird-rabbitmq] Monitor rabbitmq with blackbird
Kill the process with sudo kill -9
[blackbird-nginx] Monitor Nginx with blackbird
[blackbird-aerospike] Monitor Aerospike with blackbird
[blackbird-xfs] Monitor xfs with blackbird
ShinobiLayer: Process monitoring with Advanced Monitoring
[blackbird-mysql] Monitor mysql with blackbird
[blackbird-memcached] Monitor Memcached with blackbird
Process feedly xml with Python.
Authentication process with gRPC and Firebase Authentication
[blackbird-fio-status] Monitor ioDrive (Fusion-IO) with blackbird
Monitor Python web apps with Prometheus
Monitor Python application performance with Dynatrace ♪
Monitor ISC DHCP status with ZABBIX
[blackbird-named] Monitor Bind (named) with blackbird
Process Pubmed .xml data with python