CPU usage 0.0% just after process start.

Issue #676 resolved
mschriber
created an issue

If a process has a minimum CPU usage defined ("if cpu < 5% then alert"), the check will fail just after the process has been started, because the cpu usage seems to be always 0.0% for the first check.

Having the option to define a minimum CPU usage, would allow to monitor certain processes in greater detail.

[EDT Oct  8 17:46:01] info     : 'cpu_test' start on user request
[EDT Oct  8 17:46:01] info     : Monit daemon with PID 10411 awakened
[EDT Oct  8 17:46:01] info     : Awakened by User defined signal 1
[EDT Oct  8 17:46:01] info     : 'cpu_test' start: '...'
[EDT Oct  8 17:46:01] info     : 'cpu_test' start action done
[EDT Oct  8 17:46:01] error    : 'cpu_test' cpu usage of 0.0% matches resource limit [cpu usage<5.0%]

Comments (6)

  1. mschriber reporter

    Output of the test:

    Adding 'allow localhost' -- host resolved to [::ffff:127.0.0.1]
    Runtime constants:
     Control file       = /home/mschriber/monit/cpu_test/monitrc
     Log file           = /home/mschriber/monit/cpu_test/monit.log
     Pid file           = /home/mschriber/.monit.pid
     Id file            = /home/mschriber/.monit.id
     State file         = /home/mschriber/.monit.state
     Debug              = True
     Log                = True
     Use syslog         = False
     Is Daemon          = True
     Use process engine = True
     Limits             = {
                        =   programOutput:     512 B
                        =   sendExpectBuffer:  256 B
                        =   fileContentBuffer: 512 B
                        =   httpContentBuffer: 1024 kB
                        =   networkTimeout:    5 s
                        =   programTimeout:    5 m
                        =   stopTimeout:       30 s
                        =   startTimeout:      30 s
                        =   restartTimeout:    30 s
                        = }
     On reboot          = start
     Poll time          = 3 seconds with start delay 0 seconds
     Start monit httpd  = True
     httpd bind address = localhost
     httpd portnumber   = 2813
     httpd ssl          = Disabled
     httpd signature    = Enabled
     httpd auth. style  = Host/Net allow list
    
    The service list contains the following entries:
    
    Process Name          = cpu_test
     Pid file             = /home/mschriber/monit/cpu_test/pid
     Monitoring mode      = active
     On reboot            = start
     Start program        = '/bin/bash -c /home/mschriber/monit/cpu_test/run.py &' timeout 30 s
     Stop program         = '/bin/bash -c kill `cat /home/mschriber/monit/cpu_test/pid`; sleep 1' timeout 30 s
     Existence            = if does not exist then restart
     CPU usage limit      = if less than 5.0% then alert
    
    System Name           = h01
     Monitoring mode      = active
     On reboot            = start
    
    -------------------------------------------------------------------------------
    pidfile '/home/mschriber/.monit.pid' does not exist
    Starting Monit 5.20.0 daemon with http interface at [localhost]:2813
    Starting Monit HTTP server at [localhost]:2813
    Monit HTTP server started
    'h01' Monit 5.20.0 started
    
    'cpu_test' start on user request
    Monit daemon with PID 24795 awakened
    Awakened by User defined signal 1
    pidfile '/home/mschriber/monit/cpu_test/pid' does not exist
    'cpu_test' start: '/bin/bash -c /home/mschriber/monit/cpu_test/run.py &'
    'cpu_test' started
    'cpu_test' monitoring enabled
    'cpu_test' start action done
    'cpu_test' process is running with pid 24801
    'cpu_test' zombie check succeeded
    'cpu_test' cpu usage of 0.0% matches resource limit [cpu usage<5.0%]
    'cpu_test' process is running with pid 24801
    'cpu_test' zombie check succeeded
    'cpu_test' cpu usage check succeeded [current cpu usage=99.9%]
    'cpu_test' process is running with pid 24801
    'cpu_test' zombie check succeeded
    'cpu_test' cpu usage check succeeded [current cpu usage=99.9%]
    'cpu_test' process is running with pid 24801
    'cpu_test' zombie check succeeded
    'cpu_test' cpu usage check succeeded [current cpu usage=100.0%]
    
    'cpu_test' stop on user request
    Monit daemon with PID 24795 awakened
    Awakened by User defined signal 1
    'cpu_test' stop: '/bin/bash -c kill `cat /home/mschriber/monit/cpu_test/pid`; sleep 1'
    'cpu_test' stopped
    'cpu_test' monitoring disabled
    'cpu_test' stop action done
    

    The script goes into an infinite loop right away after the PID-file was created.

    Log file part with time-stamps and log severity:

    [EDT Oct 10 04:12:36] info     : 'cpu_test' start on user request
    [EDT Oct 10 04:12:36] info     : Monit daemon with PID 24795 awakened
    [EDT Oct 10 04:12:36] info     : Awakened by User defined signal 1
    [EDT Oct 10 04:12:36] debug    : pidfile '/home/mschriber/monit/cpu_test/pid' does not exist
    [EDT Oct 10 04:12:36] info     : 'cpu_test' start: '/bin/bash -c /home/mschriber/monit/cpu_test/run.py &'
    [EDT Oct 10 04:12:36] debug    : 'cpu_test' started
    [EDT Oct 10 04:12:36] debug    : 'cpu_test' monitoring enabled
    [EDT Oct 10 04:12:36] info     : 'cpu_test' start action done
    [EDT Oct 10 04:12:36] debug    : 'cpu_test' process is running with pid 24801
    [EDT Oct 10 04:12:36] debug    : 'cpu_test' zombie check succeeded
    [EDT Oct 10 04:12:36] error    : 'cpu_test' cpu usage of 0.0% matches resource limit [cpu usage<5.0%]
    [EDT Oct 10 04:12:39] debug    : 'cpu_test' process is running with pid 24801
    

    Many thanks.

  2. Tildeslash repo owner

    Thanks for data, the problem is fixed.

    If you want to test the development version snapshot:

    wget https://bitbucket.org/tildeslash/monit/get/master.tar.gz
    tar -xzf master.tar.gz
    cd tildeslash*
    ./bootstrap
    ./configure
    make
    
  3. Log in to comment