<?php

require_once "monitor_common.php";
#-----------------------
#check step1:
$expected_count = 16;
if (FALSE == CheckProcessCount(16, $accutual_count)) {
    SendWarning("The midbuilder process count={$accutual_count}, but we expected {$expected_count}!!");
    die;
}
Trace("Monitor OK!");
####################################################################################
### Functions
####################################################################################
function CheckProcessCount($expected_count, &$accutual_count)
{
    $cmd = "ps aux | grep midbuilder | grep -v grep | grep -v php | wc -l";
    $ret = exec($cmd, $output_arr);
    #var_dump($output_arr);
    $accutual_count = (int) trim($output_arr[0]);
    if ($accutual_count != $expected_count) {
        return FALSE;
    }
    return TRUE;
}
?>



<?php

require_once "monitor_common.php";
#-----------------------
$MAX_INTERVAL = 15 * 60;
//seconds
#check step1:
$latest_file = FindLatestFile('../logs/scan.all.log.*');
if ($latest_file != False) {
    $latest_log_time = GetTimeStampFromLogFile($latest_file);
    if (time() - $latest_log_time > $MAX_INTERVAL) {
        SendWarning('Build stop, 15 minutes no log produced!!', 'MID build stop!');
        die;
    } else {
        //Trace(time().' '.$latest_log_time);
    }
}
#check step2:
$inc_file = '/home/s/apps/statdata/midtag/input/Inc_*';
$latest_file = FindLatestFile($inc_file);
$latest_inc_time = GetTimeStampFromIncFile($latest_file);
if (time() - $latest_inc_time > $MAX_INTERVAL) {
    SendWarning("Build stop, 15 minutes no {$inc_file} produced!!", 'MID no command input!');
    die;
}
Trace('Monitor OK!');
?>