Check for two instances of Java on different ports

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
neworderfac33
Posts: 329
Joined: Fri Jul 24, 2015 11:04 am

Check for two instances of Java on different ports

Post by neworderfac33 »

Good afternoon, I have been tasked with monitoring if two instances of java.exe are running on a remote host - one on (for example) port 8888 and the other on port 9999.
From the command line, I get:

Code: Select all

./check_nt -H MyServer -p 12489 -v PROCSTATE -l java.exe -d SHOWALL
 java.exe: Running, java.exe: Running, java.exe: Running
./check_nt -H MyServer -p 8888 -v PROCSTATE -l java.exe -d SHOWALL
No data was received from host!
could not fetch information from server
./check_nt -H MyServer -p 9999 -v PROCSTATE -l java.exe -d SHOWALL
No data was received from host!
could not fetch information from server
My user insists that the port numbers are correct.
On RDPing to the machine in question, I can see that there are three instances of Jave.exe running, of which two (the ones I'm interested in) run under the same User Name. So, if I can't monitor on Port 8888 or 9999, is there any way in which I can check to see if there are two Jave.exe s running on the host under that user name with OK = 2 running instances and Critical = < 2 running instances?
[EDIT] I have added the password for the User name which is an internal service account, using the "-s" paramater, but the results are the same.

Thanks in advance for your help.
Pete
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Check for two instances of Java on different ports

Post by mcapra »

The -p argument of check_nt is specific to the NSClient server. This means that, when check_nt reaches out to an NSClient server, it will do so on port -p. As it does not have a concept of anything other than NSClient servers, check_nt isn't very useful for generically checking whether or not a particular port is listening.

This command works:

Code: Select all

./check_nt -H MyServer -p 12489 -v PROCSTATE -l java.exe -d SHOWALL
Because your NSClient server is likely bound to port 12489.

You could use check_tcp or check_udp to check if a tcp/udp connection can be established to a specific address via a specific port. Without knowing more about this specific Java application, my first recommendation would be a simple tcp/udp connection check. If it were something like a database, web server, or tcp server with specific behavior, a different plugin might be used.

If this Java application has complex behavior you'd like to monitor (beyond establishing a tcp/udp connection), we'd need to know more about that to make better recommendations.
Former Nagios employee
https://www.mcapra.com/
neworderfac33
Posts: 329
Joined: Fri Jul 24, 2015 11:04 am

Re: Check for two instances of Java on different ports

Post by neworderfac33 »

That's a really good response - I didn't realise that the port referred to NSClient++, so I've learned something valuable today - thank you!
I'll now read through the rest of your post and see if I can employ any of your suggestions or if I need to go back to my user to get more information. Watch this space!
Pete
neworderfac33
Posts: 329
Joined: Fri Jul 24, 2015 11:04 am

Re: Check for two instances of Java on different ports

Post by neworderfac33 »

OK, so from the command line, the following works:

Code: Select all

[nagioshost:/usr/local/nagios/libexec] > ./check_tcp -H MyServer -p 5555
TCP OK - 0.011 second response time on MyServer port 5555|time=0.010687s;;;0.000000;10.000000
but when I translate this into a service thus:

Code: Select all

define service{
       use                     generic-service
       #host_name              
       hostgroup_name          MyHostGroup
       service_description     Port_5555_TA
       check_command           check_tcp! -p 5555
       }
Nagios returns:

Code: Select all

check_tcp: Port must be a positive integer 
5555 was a positive integer the last time I looked - what wildly obscure parameter am I missing?
Cheers
Pete
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Check for two instances of Java on different ports

Post by tgriep »

I am guessing the check_tcp command already has the -p option and is causing the error. So change your check from

Code: Select all

check_command           check_tcp! -p 5555
to

Code: Select all

check_command           check_tcp!5555
Save it and see if that works.
Be sure to check out our Knowledgebase for helpful articles and solutions!
neworderfac33
Posts: 329
Joined: Fri Jul 24, 2015 11:04 am

Re: Check for two instances of Java on different ports

Post by neworderfac33 »

Good morning - with your help, I finally got around it like this:

Code: Select all

define command{
        command_name    check_tcp_ta
        command_line    $USER1$/check_tcp -H $HOSTNAME$ -p $ARG1$ -w $ARG2$ -c $ARG3$
}

define service{
       use                     generic-service
       #host_name            
       hostgroup_name          MyHostGroup
       service_description     Port_5556_TA
       check_command           check_tcp_ta!5556!5!10
       }
Thanks for your help!
This thread can now be closed.
Pete
Locked