diff --git a/include/common.h b/include/common.h index c67527063c..ace32007d4 100644 --- a/include/common.h +++ b/include/common.h @@ -425,6 +425,7 @@ zbx_graph_yaxis_types_t; #define ZBX_HOUSEKEEPER_EXECUTE "housekeeper_execute" #define ZBX_LOG_LEVEL_INCREASE "log_level_increase" #define ZBX_LOG_LEVEL_DECREASE "log_level_decrease" +#define ZBX_WCACHE_DUMP "wcache_dump" /* value for not supported items */ #define ZBX_NOTSUPPORTED "ZBX_NOTSUPPORTED" @@ -892,6 +893,7 @@ zbx_task_t; #define ZBX_RTC_LOG_LEVEL_DECREASE 2 #define ZBX_RTC_HOUSEKEEPER_EXECUTE 3 #define ZBX_RTC_CONFIG_CACHE_RELOAD 8 +#define ZBX_RTC_WCACHE_DUMP 9 typedef enum { diff --git a/src/libs/zbxdbcache/dbcache.c b/src/libs/zbxdbcache/dbcache.c index 5b15d5cffc..3820dd4a6b 100644 --- a/src/libs/zbxdbcache/dbcache.c +++ b/src/libs/zbxdbcache/dbcache.c @@ -4007,6 +4007,52 @@ static void hc_add_item_values(dc_item_value_t *values, int values_num) } } +void wcache_dump(int threshold) +{ + zbx_hc_item_t *item; + zbx_hashset_iter_t iter; + int i, total = 0; + zbx_vector_uint64_pair_t items; + + zbx_vector_uint64_pair_create(&items); + + LOCK_CACHE; + + zbx_hashset_iter_reset(&cache->history_items, &iter); + + while (NULL != (item = (zbx_hc_item_t *)zbx_hashset_iter_next(&iter))) + { + zbx_hc_data_t *data; + zbx_uint64_pair_t pair; + + for (data = item->tail, i = 0; NULL != data; data = data->next, i++); + + pair.first = i; + pair.second = item->itemid; + + zbx_vector_uint64_pair_append(&items, pair); + total += i; + } + + UNLOCK_CACHE; + + zbx_vector_uint64_pair_sort(&items, ZBX_DEFAULT_UINT64_COMPARE_FUNC); + + for (i = 0; i < items.values_num; i++) + { + if (threshold > items.values[i].first) + continue; + + zabbix_log(LOG_LEVEL_INFORMATION, "count:" ZBX_FS_UI64 " itemid:" ZBX_FS_UI64 + " perc:" ZBX_FS_DBL "%%", items.values[i].first, items.values[i].second, + 100 * (double)items.values[i].first / total); + } + + zbx_vector_uint64_pair_destroy(&items); + + zabbix_log(LOG_LEVEL_INFORMATION, "total in write cache:%d", total); +} + /****************************************************************************** * * * Function: hc_copy_history_data * diff --git a/src/libs/zbxnix/control.c b/src/libs/zbxnix/control.c index 486dde5c84..547f43b8cf 100644 --- a/src/libs/zbxnix/control.c +++ b/src/libs/zbxnix/control.c @@ -106,6 +106,39 @@ static int parse_log_level_options(const char *opt, size_t len, unsigned int *sc return SUCCEED; } +static int parse_cache_dump_options(const char *opt, size_t len, unsigned int *scope, unsigned int *data) +{ + unsigned short num; + const char *rtc_options; + + rtc_options = opt + len; + + if ('\0' == *rtc_options) + { + *scope = 0; + *data = 0; + + return SUCCEED; + } + + if ('=' != *rtc_options) + { + zbx_error("invalid runtime control option: %s", opt); + return FAIL; + } + + if (FAIL == is_ushort(rtc_options + 1, &num)) + { + zbx_error("invalid wcache dump parameter: must be unsigned short"); + return FAIL; + } + + *scope = 0; + *data = num; + + return SUCCEED; +} + /****************************************************************************** * * * Function: parse_rtc_options * @@ -154,6 +187,13 @@ int parse_rtc_options(const char *opt, unsigned char program_type, int *message) scope = 0; data = 0; } + else if (0 == strncmp(opt, ZBX_WCACHE_DUMP, ZBX_CONST_STRLEN(ZBX_WCACHE_DUMP))) + { + if (SUCCEED != parse_cache_dump_options(opt, ZBX_CONST_STRLEN(ZBX_WCACHE_DUMP), &scope, &data)) + return FAIL; + + command = ZBX_RTC_WCACHE_DUMP; + } else { zbx_error("invalid runtime control option: %s", opt); diff --git a/src/libs/zbxnix/daemon.c b/src/libs/zbxnix/daemon.c index efa58d7450..89a34835a7 100644 --- a/src/libs/zbxnix/daemon.c +++ b/src/libs/zbxnix/daemon.c @@ -234,6 +234,9 @@ static void user1_signal_handler(int sig, siginfo_t *siginfo, void *context) else zbx_signal_process_by_type(ZBX_RTC_GET_SCOPE(flags), ZBX_RTC_GET_DATA(flags), flags); break; + case ZBX_RTC_WCACHE_DUMP: + wcache_dump(ZBX_RTC_GET_DATA(flags)); + break; } #endif } diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c index 25181b4f85..592bb6f92a 100644 --- a/src/zabbix_agent/zabbix_agentd.c +++ b/src/zabbix_agent/zabbix_agentd.c @@ -1304,3 +1304,8 @@ int main(int argc, char **argv) exit(EXIT_SUCCESS); } + +void wcache_dump(int threshold) +{ + ZBX_UNUSED(threshold); +}