diff --git a/ChangeLog.d/bugfix/ZBX-19517 b/ChangeLog.d/bugfix/ZBX-19517 new file mode 100644 index 00000000000..06a7686f716 --- /dev/null +++ b/ChangeLog.d/bugfix/ZBX-19517 @@ -0,0 +1 @@ +...G...... [ZBX-19517] added new value 'pc' (number of physical processors consumed) to 'type' parameter for system.cpu.util[] item key on AIX servers (arimdjonoks) diff --git a/include/sysinfo.h b/include/sysinfo.h index 0a0d4dd6415..9e8cf57c77f 100644 --- a/include/sysinfo.h +++ b/include/sysinfo.h @@ -156,7 +156,12 @@ extern int CONFIG_UNSAFE_USER_PARAMETERS; #define ZBX_CPU_STATE_STEAL 7 #define ZBX_CPU_STATE_GCPU 8 #define ZBX_CPU_STATE_GNICE 9 +#if defined(_AIX) +#define ZBX_CPU_STATE_AIX_PC 10 /* number of physical CPUs consumed (AIX specific, not a CPU state) */ +#define ZBX_CPU_STATE_COUNT 11 +#else #define ZBX_CPU_STATE_COUNT 10 +#endif #define ZBX_PROC_STAT_ALL 0 #define ZBX_PROC_STAT_RUN 1 diff --git a/src/libs/zbxsysinfo/aix/cpu.c b/src/libs/zbxsysinfo/aix/cpu.c index 609bad6df6d..e3b61c5fcbc 100644 --- a/src/libs/zbxsysinfo/aix/cpu.c +++ b/src/libs/zbxsysinfo/aix/cpu.c @@ -90,6 +90,8 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result) state = ZBX_CPU_STATE_IDLE; else if (0 == strcmp(tmp, "iowait")) state = ZBX_CPU_STATE_IOWAIT; + else if (0 == strcmp(tmp, "pc")) + state = ZBX_CPU_STATE_AIX_PC; else { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); @@ -114,6 +116,13 @@ int SYSTEM_CPU_UTIL(AGENT_REQUEST *request, AGENT_RESULT *result) if (NULL == tmp || '\0' == *tmp || 0 == strcmp(tmp, "logical")) { + if (ZBX_CPU_STATE_AIX_PC == state) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "The second parameter 'pc' is supported only" + " with the fourth parameter 'physical'.")); + return SYSINFO_RET_FAIL; + } + res = get_cpustat(result, cpu_num, state, mode); } else if (0 == strcmp(tmp, "physical")) diff --git a/src/zabbix_agent/cpustat.c b/src/zabbix_agent/cpustat.c index 5ad3f595c85..7289488b208 100644 --- a/src/zabbix_agent/cpustat.c +++ b/src/zabbix_agent/cpustat.c @@ -801,6 +801,7 @@ static void insert_phys_util_into_collector(ZBX_CPUS_UTIL_DATA_AIX *cpus_phys_ut p->kern_pct = util_data[i].kern_pct; p->idle_pct = util_data[i].idle_pct; p->wait_pct = util_data[i].wait_pct; + p->physical_consumed = util_data[i].physical_consumed; p++; } @@ -826,6 +827,7 @@ static void insert_phys_util_into_collector(ZBX_CPUS_UTIL_DATA_AIX *cpus_phys_ut p->kern_pct = prev->kern_pct + util_data[i].kern_pct; p->idle_pct = prev->idle_pct + util_data[i].idle_pct; p->wait_pct = prev->wait_pct + util_data[i].wait_pct; + p->physical_consumed = prev->physical_consumed + util_data[i].physical_consumed; p++; prev++; } @@ -905,6 +907,7 @@ static void update_cpustats_physical(ZBX_CPUS_UTIL_DATA_AIX *cpus_phys_util) util_data[0].kern_pct = convert_pct_to_uint64(cpu_util[0].kern_pct); util_data[0].idle_pct = convert_pct_to_uint64(cpu_util[0].idle_pct); util_data[0].wait_pct = convert_pct_to_uint64(cpu_util[0].wait_pct); + util_data[0].physical_consumed = convert_pct_to_uint64(cpu_util[0].physical_consumed); /* get utilization for individual CPUs in one batch */ @@ -976,12 +979,15 @@ static void update_cpustats_physical(ZBX_CPUS_UTIL_DATA_AIX *cpus_phys_util) /* of utilization and physical counters do not change in this case. */ if (0 == isnan(cpu_util[i].user_pct) && 0 == isnan(cpu_util[i].kern_pct) && - 0 == isnan(cpu_util[i].idle_pct) && 0 == isnan(cpu_util[i].wait_pct)) + 0 == isnan(cpu_util[i].idle_pct) && 0 == isnan(cpu_util[i].wait_pct) && + 0 == isnan(cpu_util[i].physical_consumed)) { util_data[i + 1].user_pct = convert_pct_to_uint64(cpu_util[i].user_pct); util_data[i + 1].kern_pct = convert_pct_to_uint64(cpu_util[i].kern_pct); util_data[i + 1].idle_pct = convert_pct_to_uint64(cpu_util[i].idle_pct); util_data[i + 1].wait_pct = convert_pct_to_uint64(cpu_util[i].wait_pct); + util_data[i + 1].physical_consumed = + convert_pct_to_uint64(cpu_util[i].physical_consumed); } else if (old_cpu_stats[i].puser == new_cpu_stats[i].puser && old_cpu_stats[i].psys == new_cpu_stats[i].psys && @@ -997,12 +1003,13 @@ static void update_cpustats_physical(ZBX_CPUS_UTIL_DATA_AIX *cpus_phys_util) { zabbix_log(LOG_LEVEL_DEBUG, "%s(): unexpected case:" " i=%d name=%s puser=%llu psys=%llu pidle=%llu pwait=%llu" - " user_pct=%f kern_pct=%f idle_pct=%f wait_pct=%f", + " user_pct=%f kern_pct=%f idle_pct=%f wait_pct=%f pc=%f", __func__, i, new_cpu_stats[i].name, new_cpu_stats[i].puser, new_cpu_stats[i].psys, new_cpu_stats[i].pidle, new_cpu_stats[i].pwait, cpu_util[i].user_pct, cpu_util[i].kern_pct, - cpu_util[i].idle_pct, cpu_util[i].wait_pct); + cpu_util[i].idle_pct, cpu_util[i].wait_pct, + cpu_util[i].physical_consumed); insert_error_status_into_collector(cpus_phys_util, 0, max_cpu_count); goto copy_to_old; } @@ -1236,6 +1243,9 @@ int get_cpustat_physical(AGENT_RESULT *result, int cpu_num, int state, int mode) case ZBX_CPU_STATE_IOWAIT: SET_DBL_RESULT(result, convert_uint64_to_pct(p->counters[offset].wait_pct)); break; + case ZBX_CPU_STATE_AIX_PC: + SET_DBL_RESULT(result, convert_uint64_to_pct(p->counters[offset].physical_consumed)); + break; default: UNLOCK_CPUSTATS; SET_MSG_RESULT(result, zbx_strdup(NULL, "Statistics for invalid CPU state requested.")); @@ -1284,6 +1294,10 @@ int get_cpustat_physical(AGENT_RESULT *result, int cpu_num, int state, int mode) SET_DBL_RESULT(result, convert_uint64_to_pct(p->counters[offset].wait_pct - p->counters[prev_offset].wait_pct) / time_interval); break; + case ZBX_CPU_STATE_AIX_PC: + SET_DBL_RESULT(result, convert_uint64_to_pct(p->counters[offset].physical_consumed - + p->counters[prev_offset].physical_consumed) / time_interval); + break; default: UNLOCK_CPUSTATS; SET_MSG_RESULT(result, zbx_strdup(NULL, "Statistics for invalid CPU state requested.")); diff --git a/src/zabbix_agent/cpustat.h b/src/zabbix_agent/cpustat.h index a96a7235799..dd340b8028e 100644 --- a/src/zabbix_agent/cpustat.h +++ b/src/zabbix_agent/cpustat.h @@ -71,6 +71,9 @@ typedef struct zbx_uint64_t kern_pct; /* kernel mode */ zbx_uint64_t idle_pct; /* idle mode */ zbx_uint64_t wait_pct; /* wait mode */ + /* Although 'physical_consumed' is not a number of percents converting it to uint64_t with */ + /* convert_pct_to_uint64() could be useful to preserve precision. */ + zbx_uint64_t physical_consumed; } ZBX_CPU_UTIL_PCT_AIX;