From: Padraig O'Sullivan Date: Tue, 20 Oct 2009 18:07:07 +0000 (-0400) Subject: Added an initial version of getStats() to the C++ interface. X-Git-Tag: 0.35~9^2~2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=ede87e9f8c75bb6a5b0223f79d445028d1d99f85;p=m6w6%2Flibmemcached Added an initial version of getStats() to the C++ interface. --- diff --git a/libmemcached/memcached.hpp b/libmemcached/memcached.hpp index baf681ad..c1ca1bd2 100644 --- a/libmemcached/memcached.hpp +++ b/libmemcached/memcached.hpp @@ -920,6 +920,52 @@ public: return version; } + bool getStats(std::map< std::string, std::map > + &stats_map) + { + memcached_return rc; + memcached_stat_st *stats= memcached_stat(&memc, NULL, &rc); + + if (rc != MEMCACHED_SUCCESS && + rc != MEMCACHED_SOME_ERRORS) + { + return false; + } + + uint32_t server_count= memcached_server_count(&memc); + + /* + * For each memcached server, construct a std::map for its stats and add + * it to the std::map of overall stats. + */ + for (uint32_t x= 0; x < server_count; x++) + { + std::ostringstream strstm; + std::string server_name(memcached_server_name(&memc, servers[x])); + server_name.append(":"); + strstm << memcached_server_port(&memc, servers[x]); + server_name.append(strstm.str()); + + std::map server_stats; + char **list= NULL; + char **ptr= NULL; + + list= memcached_stat_get_keys(&memc, &stats[x], &rc); + for (ptr= list; *ptr; ptr++) + { + char *value= memcached_stat_get_value(&memc, &stats[x], *ptr, &rc); + server_stats[*ptr]= value; + free(value); + } + + stats_map[server_name]= server_stats; + free(list); + } + + memcached_stat_free(&memc, stats); + return true; + } + private: std::string servers_list;