Ad Widget

Collapse

Monitor running time of a specific process

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • freestyler
    Junior Member
    • Jun 2009
    • 2

    #1

    Monitor running time of a specific process

    I have been searching for a while on how to monitor a single process.

    Basically, I wanna add an item that would be triggered when a specific process has been running for more than X time. (process duration time > 7h for eg.)

    Is that something doable on Zabbix?
    If not, is there any option?
  • Calimero
    Senior Member
    • Nov 2006
    • 481

    #2
    Have zabbix agent count the number of 'xyz' processes ? And then write a trigger like:

    proc.num[my_proc].min(3600)>0

    ==> trigger is true if there was always at least 1 'my_proc' process over the last hour.

    If you have processes 'my_proc' that are spawned every 2 minutes and last for 30 seconds, zabbix_agent will only check every X minutes (as defined in the GUI). So the trigger may think it was a single continuous run of my_proc while it was lots of shorter runs...

    Another option if you're monitoring a batch / cron job is to write a small wrapper script and use zabbix_sender to send a state value to zabbix_server:

    Code:
    #!/bin/bash
    
    $STATUS_STARTED=1
    $STATUS_STOPPED=0
    
    zabbix_sender ... -k myjob.status -o $STATUS_STARTED
    /path/to/real_script.sh
    zabbix_sender ... -k myjob.status -o $STATUS_STOPPED
    And then write a trigger on myjob.status (probably some combination of nodata() and last()).

    Comment

    • freestyler
      Junior Member
      • Jun 2009
      • 2

      #3
      Let's say I wanna trigger an alert when my process (my_proc) has been running for more than 4hours.

      I'll write something like :
      proc.num[my_proc].min(14400)>0

      1/ how can I point to my_proc ? pid number ? how can this be automated ?

      2/ Does this expression above work ? The way I see it is that it checks for the last 4 hours and see if my_proc is running (which is different since I wanna now that while I am checking that the process is running, and running for a while=4h )

      Comment

      • Calimero
        Senior Member
        • Nov 2006
        • 481

        #4
        Originally posted by freestyler
        1/ how can I point to my_proc ? pid number ? how can this be automated ?
        See documentation for proc.num.
        First argument is process name (as show by 'ps' or 'top'). It can also filter on user, process state and command arguments.

        Originally posted by freestyler
        2/ Does this expression above work ? The way I see it is that it checks for the last 4 hours and see if my_proc is running (which is different since I wanna now that while I am checking that the process is running, and running for a while=4h )

        As I don't know exactly what check you want to achieve, my (fake) trigger was just an example.

        If it's a scheduled task, you could also write a time based trigger ("if process is running and it's 10 o'clock" ...).

        Comment

        Working...