/****************************************************************************** * * * Function: main_discoverer_loop * * * * Purpose: periodically try to find new hosts and services * * * * Author: Alexei Vladishev * * * * Comments: executes once per 30 seconds (hardcoded) * * * ******************************************************************************/ void main_discoverer_loop() { int now, nextcheck, sleeptime; double sec; zabbix_log(LOG_LEVEL_DEBUG, "In main_discoverer_loop() process_num:%d", process_num); zbx_setproctitle("%s [connecting to the database]", get_process_type_string(process_type)); DBconnect(ZBX_DB_CONNECT_NORMAL); for (;;) { zbx_setproctitle("%s [performing discovery]", get_process_type_string(process_type)); now = time(NULL); sec = zbx_time(); process_discovery(now); sec = zbx_time() - sec; zabbix_log(LOG_LEVEL_DEBUG, "%s #%d spent " ZBX_FS_DBL " seconds while processing rules", get_process_type_string(process_type), process_num, sec); nextcheck = get_minnextcheck(now); sleeptime = calculate_sleeptime(nextcheck, DISCOVERER_DELAY); zbx_sleep_loop(sleeptime); } }
/****************************************************************************** * * * Function: main_httppoller_loop * * * * Purpose: main loop of processing of httptests * * * * Parameters: * * * * Return value: * * * * Author: Alexei Vladishev * * * * Comments: never returns * * * ******************************************************************************/ void main_httppoller_loop() { int now, nextcheck, sleeptime; double sec; zabbix_log(LOG_LEVEL_DEBUG, "In main_httppoller_loop() process_num:%d", process_num); zbx_setproctitle("%s [connecting to the database]", get_process_type_string(process_type)); DBconnect(ZBX_DB_CONNECT_NORMAL); for (;;) { zbx_setproctitle("%s [getting values]", get_process_type_string(process_type)); now = time(NULL); sec = zbx_time(); process_httptests(process_num, now); sec = zbx_time() - sec; zabbix_log(LOG_LEVEL_DEBUG, "%s #%d spent " ZBX_FS_DBL " seconds while updating HTTP tests", get_process_type_string(process_type), process_num, sec); nextcheck = get_minnextcheck(now); sleeptime = calculate_sleeptime(nextcheck, POLLER_DELAY); zbx_sleep_loop(sleeptime); } }
/****************************************************************************** * * * Function: main_discoverer_loop * * * * Purpose: periodically try to find new hosts and services * * * * Author: Alexei Vladishev * * * * Comments: executes once per 30 seconds (hardcoded) * * * ******************************************************************************/ void main_discoverer_loop(void) { int now, nextcheck, sleeptime = -1, rule_count = 0, old_rule_count = 0; double sec, total_sec = 0.0, old_total_sec = 0.0; time_t last_stat_time; #define STAT_INTERVAL 5 /* if a process is busy and does not sleep then update status not faster than */ /* once in STAT_INTERVAL seconds */ zbx_setproctitle("%s #%d [connecting to the database]", get_process_type_string(process_type), process_num); last_stat_time = time(NULL); DBconnect(ZBX_DB_CONNECT_NORMAL); for (;;) { if (0 != sleeptime) { zbx_setproctitle("%s #%d [processed %d rules in " ZBX_FS_DBL " sec, performing discovery]", get_process_type_string(process_type), process_num, old_rule_count, old_total_sec); } now = time(NULL); sec = zbx_time(); rule_count += process_discovery(now); total_sec += zbx_time() - sec; nextcheck = get_minnextcheck(now); sleeptime = calculate_sleeptime(nextcheck, DISCOVERER_DELAY); if (0 != sleeptime || STAT_INTERVAL <= time(NULL) - last_stat_time) { if (0 == sleeptime) { zbx_setproctitle("%s #%d [processed %d rules in " ZBX_FS_DBL " sec, performing " "discovery]", get_process_type_string(process_type), process_num, rule_count, total_sec); } else { zbx_setproctitle("%s #%d [processed %d rules in " ZBX_FS_DBL " sec, idle %d sec]", get_process_type_string(process_type), process_num, rule_count, total_sec, sleeptime); old_rule_count = rule_count; old_total_sec = total_sec; } rule_count = 0; total_sec = 0.0; last_stat_time = time(NULL); } zbx_sleep_loop(sleeptime); } #undef STAT_INTERVAL }