0

I'm a total noob to Zabbix and this is my first assignment... I need to build a monitor using Zabbix and monitor how long one script runs. The script looks like that:

device0="/home/build/aggregator/scripts/aggregator.lock"
if [ -e "$device0" ]
then
echo process is already running
else

touch $device0
java -Xms6g  -Xmx6g -jar /home/build/aggregator/aggregator-1.0-SNAPSHOT-jar-with-dependencies.jar
rm $device0
fi

The script creates a file called aggregator.lock which makes sure the script runs only once, the script is configured in Crontab to run every minute. I've created the next Items: enter image description here enter image description here While the aggregator.lock file exists, Zabbix vfs.file.exists returns: 1.

[root@zabbix ~]# zabbix_get -s 10.200.X.X -k vfs.file.exists[/home/build/aggregator/scripts/aggregator.lock]
1
[root@zabbix ~]#

And vfs.file.time check returns: 1400057821 (Unix time).

While the aggregator.lock file doesn't exist, Zabbix returns: 0. And vfs.file.time check returns: ZBX_NOTSUPPORTED .

The check runs every 30 secs in order to minimize traffic in the network but the script runs for about 10-20 seconds every time. So I need to find the best way to monitor the run time of the script, what would be the best way to achieve this aim?

1 Answer 1

3

Do you need to monitor how long a process runs or do you need to alert if the process is taking too long?

If it is the former, you might wish to modify the script so that it sends information about the run time using zabbix_sender, like this:

#!/bin/bash

date1=$(date '+%s')
sleep 5
date2=$(date '+%s')

duration=$(($date2-$date1))

zabbix_sender -z 127.0.0.1 -s 'my host' -k duration -o $duration

Here, "sleep 5" is your "java" command.

If it is the latter, you might wish to modify the script so that it sends a value of "1" when the script starts and a value of "0" when it ends, like this:

#!/bin/bash

zabbix_sender -z 127.0.0.1 -s 'my host' -k started -o 1
sleep 5
zabbix_sender -z 127.0.0.1 -s 'my host' -k started -o 0

Then, you could create a trigger similar to the following to alert if the process is taking too long:

{my host:started.last()}=1 & {my host:started.nodata(45)}=1

If modifying the script is not an option, you might then wish to use proc.num[] item:

proc.num[java,,,aggregator-1.0-SNAPSHOT-jar-with-dependencies.jar]

Make it check every 15 seconds and alert is the last three values (spanning 30 seconds) show that the process is running:

{my host:proc.num[java,,,aggregator-1.0-SNAPSHOT-jar-with-dependencies.jar].min(#3)}=1

This might also be the simplest solution.

3
  • Thanks for your answer, I actually need to know if the process run takes too long, but my manager doesn't approve your second solution as it's not accurate enough.. I am now trying to build a trigger which will calculate the delta time between the creation time of the lock file and it's deletion. if you have any more suggestions, I would love to hear them.
    – Itai Ganot
    May 14, 2014 at 11:31
  • @ItaiGanot: Another idea would be to create a user parameter (see zabbix.com/documentation/2.2/manual/config/items/userparameters) that would return the PID of the aggregator process if it is running and zero otherwise. Then, you could use the same idea as the last trigger in my original answer where you would check whether the last N PIDs are the same. The expression could be like this: {host:item.last()}#0 & {host:item.last(3)}={host:item.last(#3)}.
    – asaveljevs
    May 15, 2014 at 11:51
  • Alternatively, you could use the lock file's inode instead of the PID.
    – asaveljevs
    May 15, 2014 at 11:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .