From 6dabe5409bf7fb88f17b4580d7bcf0d3151f67fc Mon Sep 17 00:00:00 2001 From: wadam Date: Thu, 1 Dec 2011 11:40:18 -0500 Subject: [PATCH 1/2] Fixed Bug#2018 - The threshold of cpu warning message should be increased --- libs/freetdm/src/ftdm_io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 0205ab36b1..8ec6a3344f 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -5594,15 +5594,15 @@ static void *ftdm_cpu_monitor_run(ftdm_thread_t *me, void *obj) if (monitor->alarm) { if ((int)time >= (100 - monitor->set_alarm_threshold)) { - ftdm_log(FTDM_LOG_DEBUG, "CPU alarm OFF (idle:%d)\n", (int) time); + ftdm_log(FTDM_LOG_DEBUG, "CPU alarm is OFF (cpu usage:%d)\n", (int) (100-time)); monitor->alarm = 0; } - if (monitor->alarm_action_flags & FTDM_CPU_ALARM_ACTION_WARN) { + if (monitor->alarm && (monitor->alarm_action_flags & FTDM_CPU_ALARM_ACTION_WARN)) { ftdm_log(FTDM_LOG_WARNING, "CPU alarm is ON (cpu usage:%d)\n", (int) (100-time)); } } else { if ((int)time <= (100-monitor->reset_alarm_threshold)) { - ftdm_log(FTDM_LOG_DEBUG, "CPU alarm ON (idle:%d)\n", (int) time); + ftdm_log(FTDM_LOG_DEBUG, "CPU alarm is ON (cpu usage:%d)\n", (int) (100-time)); monitor->alarm = 1; } } From 3432dccfc2b01b095e561d5467c76d20a094bc69 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Thu, 1 Dec 2011 12:13:12 -0500 Subject: [PATCH 2/2] freetdm: fix cpu monitor inconsistent messages, variable names etc changed parameter name from cpu_reset_alarm_threshold to cpu_clear_alarm_threshold (old parameter name still valid for backwards compatibility in configuration files) --- libs/freetdm/conf/freetdm.conf | 2 +- libs/freetdm/src/ftdm_io.c | 51 ++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/libs/freetdm/conf/freetdm.conf b/libs/freetdm/conf/freetdm.conf index eb506bef8d..0d53992979 100644 --- a/libs/freetdm/conf/freetdm.conf +++ b/libs/freetdm/conf/freetdm.conf @@ -13,7 +13,7 @@ cpu_monitoring_interval => 1000 cpu_set_alarm_threshold => 80 ; At what CPU percentage stop the CPU alarm -cpu_reset_alarm_threshold => 70 +cpu_clear_alarm_threshold => 70 ; Which action to take when the CPU alarm is raised ; it can be warn and/or reject calls diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 8ec6a3344f..bb866610a2 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -223,7 +223,7 @@ typedef struct { uint32_t interval; uint8_t alarm_action_flags; uint8_t set_alarm_threshold; - uint8_t reset_alarm_threshold; + uint8_t clear_alarm_threshold; ftdm_interrupt_t *interrupt; } cpu_monitor_t; @@ -4834,14 +4834,15 @@ static ftdm_status_t load_config(void) } else { ftdm_log(FTDM_LOG_ERROR, "Invalid cpu alarm set threshold %s\n", val); } - } else if (!strncasecmp(var, "cpu_reset_alarm_threshold", sizeof("cpu_reset_alarm_threshold")-1)) { + } else if (!strncasecmp(var, "cpu_reset_alarm_threshold", sizeof("cpu_reset_alarm_threshold")-1) || + !strncasecmp(var, "cpu_clear_alarm_threshold", sizeof("cpu_clear_alarm_threshold")-1)) { intparam = atoi(val); if (intparam > 0 && intparam < 100) { - globals.cpu_monitor.reset_alarm_threshold = (uint8_t)intparam; - if (globals.cpu_monitor.reset_alarm_threshold > globals.cpu_monitor.set_alarm_threshold) { - globals.cpu_monitor.reset_alarm_threshold = globals.cpu_monitor.set_alarm_threshold - 10; - ftdm_log(FTDM_LOG_ERROR, "Cpu alarm reset threshold must be lower than set threshold" - ", setting threshold to %d\n", globals.cpu_monitor.reset_alarm_threshold); + globals.cpu_monitor.clear_alarm_threshold = (uint8_t)intparam; + if (globals.cpu_monitor.clear_alarm_threshold > globals.cpu_monitor.set_alarm_threshold) { + globals.cpu_monitor.clear_alarm_threshold = globals.cpu_monitor.set_alarm_threshold - 10; + ftdm_log(FTDM_LOG_ERROR, "Cpu alarm clear threshold must be lower than set threshold, " + "setting clear threshold to %d\n", globals.cpu_monitor.clear_alarm_threshold); } } else { ftdm_log(FTDM_LOG_ERROR, "Invalid cpu alarm reset threshold %s\n", val); @@ -5581,28 +5582,32 @@ static void *ftdm_cpu_monitor_run(ftdm_thread_t *me, void *obj) { cpu_monitor_t *monitor = (cpu_monitor_t *)obj; struct ftdm_cpu_monitor_stats *cpu_stats = ftdm_new_cpu_monitor(); + + ftdm_log(FTDM_LOG_DEBUG, "CPU monitor thread is now running\n"); if (!cpu_stats) { - return NULL; + goto done; } monitor->running = 1; - while(ftdm_running()) { - double time; - if (ftdm_cpu_get_system_idle_time(cpu_stats, &time)) { + while (ftdm_running()) { + double idle_time = 0.0; + int cpu_usage = 0; + + if (ftdm_cpu_get_system_idle_time(cpu_stats, &idle_time)) { break; } + cpu_usage = (int)(100 - idle_time); if (monitor->alarm) { - if ((int)time >= (100 - monitor->set_alarm_threshold)) { - ftdm_log(FTDM_LOG_DEBUG, "CPU alarm is OFF (cpu usage:%d)\n", (int) (100-time)); + if (cpu_usage <= monitor->clear_alarm_threshold) { + ftdm_log(FTDM_LOG_DEBUG, "CPU alarm is now OFF (cpu usage: %d)\n", cpu_usage); monitor->alarm = 0; - } - if (monitor->alarm && (monitor->alarm_action_flags & FTDM_CPU_ALARM_ACTION_WARN)) { - ftdm_log(FTDM_LOG_WARNING, "CPU alarm is ON (cpu usage:%d)\n", (int) (100-time)); + } else if (monitor->alarm_action_flags & FTDM_CPU_ALARM_ACTION_WARN) { + ftdm_log(FTDM_LOG_WARNING, "CPU alarm is still ON (cpu usage: %d)\n", cpu_usage); } } else { - if ((int)time <= (100-monitor->reset_alarm_threshold)) { - ftdm_log(FTDM_LOG_DEBUG, "CPU alarm is ON (cpu usage:%d)\n", (int) (100-time)); + if (cpu_usage >= monitor->set_alarm_threshold) { + ftdm_log(FTDM_LOG_WARNING, "CPU alarm is now ON (cpu usage: %d)\n", cpu_usage); monitor->alarm = 1; } } @@ -5611,7 +5616,11 @@ static void *ftdm_cpu_monitor_run(ftdm_thread_t *me, void *obj) ftdm_delete_cpu_monitor(cpu_stats); monitor->running = 0; + +done: + ftdm_log(FTDM_LOG_DEBUG, "CPU monitor thread is now terminating\n"); return NULL; + #ifdef __WINDOWS__ UNREFERENCED_PARAMETER(me); #endif @@ -5714,7 +5723,7 @@ FT_DECLARE(ftdm_status_t) ftdm_global_configuration(void) globals.cpu_monitor.interval = 1000; globals.cpu_monitor.alarm_action_flags = 0; globals.cpu_monitor.set_alarm_threshold = 80; - globals.cpu_monitor.reset_alarm_threshold = 70; + globals.cpu_monitor.clear_alarm_threshold = 70; if (load_config() != FTDM_SUCCESS) { globals.running = 0; @@ -5723,10 +5732,10 @@ FT_DECLARE(ftdm_status_t) ftdm_global_configuration(void) } if (globals.cpu_monitor.enabled) { - ftdm_log(FTDM_LOG_INFO, "CPU Monitor is running interval:%d lo-thres:%d hi-thres:%d\n", + ftdm_log(FTDM_LOG_INFO, "CPU Monitor is running interval:%d set-thres:%d clear-thres:%d\n", globals.cpu_monitor.interval, globals.cpu_monitor.set_alarm_threshold, - globals.cpu_monitor.reset_alarm_threshold); + globals.cpu_monitor.clear_alarm_threshold); if (ftdm_cpu_monitor_start() != FTDM_SUCCESS) { return FTDM_FAIL;