⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.23
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
local
/
src
/
libmemcached-1.0.18
/
libmemcached
/
View File Name :
analyze.cc
#include <libmemcached/common.h> static void calc_largest_consumption(memcached_analysis_st *result, const uint32_t server_num, const uint64_t nbytes) { if (result->most_used_bytes < nbytes) { result->most_used_bytes= nbytes; result->most_consumed_server= server_num; } } static void calc_oldest_node(memcached_analysis_st *result, const uint32_t server_num, const uint32_t uptime) { if (result->longest_uptime < uptime) { result->longest_uptime= uptime; result->oldest_server= server_num; } } static void calc_least_free_node(memcached_analysis_st *result, const uint32_t server_num, const uint64_t max_allowed_bytes, const uint64_t used_bytes) { uint64_t remaining_bytes= max_allowed_bytes - used_bytes; if (result->least_remaining_bytes == 0 || remaining_bytes < result->least_remaining_bytes) { result->least_remaining_bytes= remaining_bytes; result->least_free_server= server_num; } } static void calc_average_item_size(memcached_analysis_st *result, const uint64_t total_items, const uint64_t total_bytes) { if (total_items > 0 && total_bytes > 0) { result->average_item_size= (uint32_t) (total_bytes / total_items); } } static void calc_hit_ratio(memcached_analysis_st *result, const uint64_t total_get_hits, const uint64_t total_get_cmds) { if (total_get_hits == 0 || total_get_cmds == 0) { result->pool_hit_ratio= 0; return; } double temp= double(total_get_hits) / total_get_cmds; result->pool_hit_ratio= temp * 100; } memcached_analysis_st *memcached_analyze(memcached_st *shell, memcached_stat_st *memc_stat, memcached_return_t *error) { Memcached* memc= memcached2Memcached(shell); uint64_t total_items= 0, total_bytes= 0; uint64_t total_get_cmds= 0, total_get_hits= 0; if (memc == NULL or memc_stat == NULL) { return NULL; } memcached_return_t not_used; if (error == NULL) { error= ¬_used; } *error= MEMCACHED_SUCCESS; uint32_t server_count= memcached_server_count(memc); memcached_analysis_st *result= (memcached_analysis_st*)libmemcached_xcalloc(memc, memcached_server_count(memc), memcached_analysis_st); if (result == NULL) { *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; } result->root= memc; for (uint32_t x= 0; x < server_count; x++) { calc_largest_consumption(result, x, memc_stat[x].bytes); calc_oldest_node(result, x, uint32_t(memc_stat[x].uptime)); calc_least_free_node(result, x, memc_stat[x].limit_maxbytes, memc_stat[x].bytes); total_get_hits+= memc_stat[x].get_hits; total_get_cmds+= memc_stat[x].cmd_get; total_items+= memc_stat[x].curr_items; total_bytes+= memc_stat[x].bytes; } calc_average_item_size(result, total_items, total_bytes); calc_hit_ratio(result, total_get_hits, total_get_cmds); return result; } void memcached_analyze_free(memcached_analysis_st *ptr) { libmemcached_free(ptr->root, ptr); }