32#include "stats_table.h"
34#include <drizzled/error.h>
35#include <libmemcached/server.h>
42memcached_return server_function(
const memcached_st *ptr,
43 memcached_server_st *server,
46struct server_function_context
50 : generator(generator_arg)
56memcached_return server_function(
const memcached_st *memc,
57 memcached_server_st *server,
62 const char *server_name= memcached_server_name(*memc, *server);
63 in_port_t server_port= memcached_server_port(*memc, *server);
65 memcached_stat_st stats;
66 memcached_return ret= memcached_stat_servername(&stats, NULL,
67 server_name, server_port);
69 if (ret != MEMCACHED_SUCCESS)
71 my_printf_error(ER_UNKNOWN_ERROR, _(
"Unable get stats from memcached server %s. Got error from memcached_stat_servername()."), MYF(0), server_name);
75 char **list= memcached_stat_get_keys((memcached_st *)memc, &stats, &ret);
78 ctx->generator->push(server_name);
79 ctx->generator->push(
static_cast<uint64_t
>(server_port));
81 for (ptr= list; *ptr; ptr++)
83 char *value= memcached_stat_get_value((memcached_st *)memc, &stats, *ptr, &ret);
84 ctx->generator->push(value);
89 return MEMCACHED_SUCCESS;
93StatsTableTool::StatsTableTool() :
94 plugin::TableFunction(
"DATA_DICTIONARY",
"MEMCACHED_STATS")
97 add_field(
"PORT_NUMBER", plugin::TableFunction::NUMBER);
98 add_field(
"PROCESS_ID", plugin::TableFunction::NUMBER);
99 add_field(
"UPTIME", plugin::TableFunction::NUMBER);
100 add_field(
"TIME", plugin::TableFunction::NUMBER);
101 add_field(
"VERSION");
102 add_field(
"POINTER_SIZE", plugin::TableFunction::NUMBER);
103 add_field(
"RUSAGE_USER", plugin::TableFunction::NUMBER);
104 add_field(
"RUSAGE_SYSTEM", plugin::TableFunction::NUMBER);
105 add_field(
"CURRENT_ITEMS", plugin::TableFunction::NUMBER);
106 add_field(
"TOTAL_ITEMS", plugin::TableFunction::NUMBER);
107 add_field(
"BYTES", plugin::TableFunction::NUMBER);
108 add_field(
"CURRENT_CONNECTIONS", plugin::TableFunction::NUMBER);
109 add_field(
"TOTAL_CONNECTIONS", plugin::TableFunction::NUMBER);
110 add_field(
"CONNECTION_STRUCTURES", plugin::TableFunction::NUMBER);
111 add_field(
"GETS", plugin::TableFunction::NUMBER);
112 add_field(
"SETS", plugin::TableFunction::NUMBER);
113 add_field(
"HITS", plugin::TableFunction::NUMBER);
114 add_field(
"MISSES", plugin::TableFunction::NUMBER);
115 add_field(
"EVICTIONS", plugin::TableFunction::NUMBER);
116 add_field(
"BYTES_READ", plugin::TableFunction::NUMBER);
117 add_field(
"BYTES_WRITTEN", plugin::TableFunction::NUMBER);
118 add_field(
"LIMIT_MAXBYTES", plugin::TableFunction::NUMBER);
119 add_field(
"THREADS", plugin::TableFunction::NUMBER);
124 plugin::TableFunction::Generator(arg)
135 assert(servers_var != NULL);
137 const string servers_string(
static_cast<char *
>(servers_var.value_ptr(NULL, 0)));
139 if (servers_string.empty())
141 my_printf_error(ER_UNKNOWN_ERROR, _(
"No value in MEMCACHED_STATS_SERVERS variable."), MYF(0));
145 memc= memcached_create(NULL);
148 my_printf_error(ER_UNKNOWN_ERROR, _(
"Unable to create memcached struct. Got error from memcached_create()."), MYF(0));
152 memcached_server_st *tmp_serv= memcached_servers_parse(servers_string.c_str());
153 if (tmp_serv == NULL)
155 my_printf_error(ER_UNKNOWN_ERROR, _(
"Unable to create memcached server list. Got error from memcached_servers_parse(%s)."), MYF(0), servers_string.c_str());
159 memcached_server_push(memc, tmp_serv);
160 memcached_server_list_free(tmp_serv);
162 number_of_hosts= memc->number_of_hosts;
166StatsTableTool::Generator::~Generator()
170 memcached_free(memc);
175bool StatsTableTool::Generator::populate()
177 if (host_number == number_of_hosts)
182 server_function_context context(
this);
184 memcached_server_function callbacks[1];
185 callbacks[0]= server_function;
187 unsigned int iferror;
188 iferror= (*callbacks[0])(memc, &memc->servers[host_number], (
void *)&context);
sys_var * find_sys_var(const std::string &name)