30
30
#include "config.h"
31
#include "drizzled/session.h"
32
#include "drizzled/show.h"
32
34
#include "stats_table.h"
34
#include "drizzled/error.h"
35
#include <libmemcached/server.h>
37
#if !defined(HAVE_MEMCACHED_SERVER_FN)
38
typedef memcached_server_function memcached_server_fn;
41
namespace drizzle_plugin
45
memcached_return server_function(const memcached_st *ptr,
46
memcached_server_st *server,
49
struct server_function_context
51
StatsTableTool::Generator* generator;
52
server_function_context(StatsTableTool::Generator *generator_arg)
53
: generator(generator_arg)
59
memcached_return server_function(const memcached_st *memc,
60
memcached_server_st *server,
63
server_function_context *ctx= static_cast<server_function_context *>(context);
65
const char *server_name= memcached_server_name(*memc, *server);
66
in_port_t server_port= memcached_server_port(*memc, *server);
68
memcached_stat_st stats;
69
memcached_return ret= memcached_stat_servername(&stats, NULL,
70
server_name, server_port);
72
if (ret != MEMCACHED_SUCCESS)
74
my_printf_error(ER_UNKNOWN_ERROR, _("Unable get stats from memcached server %s. Got error from memcached_stat_servername()."), MYF(0), server_name);
78
char **list= memcached_stat_get_keys((memcached_st *)memc, &stats, &ret);
81
ctx->generator->push(server_name);
82
ctx->generator->push(static_cast<uint64_t>(server_port));
84
for (ptr= list; *ptr; ptr++)
86
char *value= memcached_stat_get_value((memcached_st *)memc, &stats, *ptr, &ret);
87
ctx->generator->push(value);
92
return MEMCACHED_SUCCESS;
96
StatsTableTool::StatsTableTool() :
97
plugin::TableFunction("DATA_DICTIONARY", "MEMCACHED_STATS")
100
add_field("PORT_NUMBER", plugin::TableFunction::NUMBER);
101
add_field("PROCESS_ID", plugin::TableFunction::NUMBER);
102
add_field("UPTIME", plugin::TableFunction::NUMBER);
103
add_field("TIME", plugin::TableFunction::NUMBER);
104
add_field("VERSION");
105
add_field("POINTER_SIZE", plugin::TableFunction::NUMBER);
106
add_field("RUSAGE_USER", plugin::TableFunction::NUMBER);
107
add_field("RUSAGE_SYSTEM", plugin::TableFunction::NUMBER);
108
add_field("CURRENT_ITEMS", plugin::TableFunction::NUMBER);
109
add_field("TOTAL_ITEMS", plugin::TableFunction::NUMBER);
110
add_field("BYTES", plugin::TableFunction::NUMBER);
111
add_field("CURRENT_CONNECTIONS", plugin::TableFunction::NUMBER);
112
add_field("TOTAL_CONNECTIONS", plugin::TableFunction::NUMBER);
113
add_field("CONNECTION_STRUCTURES", plugin::TableFunction::NUMBER);
114
add_field("GETS", plugin::TableFunction::NUMBER);
115
add_field("SETS", plugin::TableFunction::NUMBER);
116
add_field("HITS", plugin::TableFunction::NUMBER);
117
add_field("MISSES", plugin::TableFunction::NUMBER);
118
add_field("EVICTIONS", plugin::TableFunction::NUMBER);
119
add_field("BYTES_READ", plugin::TableFunction::NUMBER);
120
add_field("BYTES_WRITTEN", plugin::TableFunction::NUMBER);
121
add_field("LIMIT_MAXBYTES", plugin::TableFunction::NUMBER);
122
add_field("THREADS", plugin::TableFunction::NUMBER);
126
StatsTableTool::Generator::Generator(drizzled::Field **arg) :
127
plugin::TableFunction::Generator(arg)
129
/* This will be set to the real number if we initialize properly below */
134
/* set to NULL if we are not able to init we dont want to call delete on this */
137
drizzled::sys_var *servers_var= drizzled::find_sys_var("memcached_stats_servers");
138
assert(servers_var != NULL);
140
const string servers_string(static_cast<char *>(servers_var.value_ptr(NULL, 0, NULL)));
142
if (servers_string.empty())
144
my_printf_error(ER_UNKNOWN_ERROR, _("No value in MEMCACHED_STATS_SERVERS variable."), MYF(0));
148
memc= memcached_create(NULL);
151
my_printf_error(ER_UNKNOWN_ERROR, _("Unable to create memcached struct. Got error from memcached_create()."), MYF(0));
35
#include "sysvar_holder.h"
37
#include <libmemcached/memcached.h>
43
using namespace drizzled;
45
int MemcachedStatsISMethods::fillTable(Session *,
47
plugin::InfoSchemaTable *schema_table)
49
const CHARSET_INFO * const scs= system_charset_info;
50
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
51
const string servers_string= sysvar_holder.getServersString();
53
table->restoreRecordAsDefault();
56
memcached_st *serv= memcached_create(NULL);
155
57
memcached_server_st *tmp_serv=
156
58
memcached_servers_parse(servers_string.c_str());
157
if (tmp_serv == NULL)
159
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());
163
memcached_server_push(memc, tmp_serv);
59
memcached_server_push(serv, tmp_serv);
164
60
memcached_server_list_free(tmp_serv);
166
number_of_hosts= memc->number_of_hosts;
170
StatsTableTool::Generator::~Generator()
174
memcached_free(memc);
179
bool StatsTableTool::Generator::populate()
181
if (host_number == number_of_hosts)
186
server_function_context context(this);
188
memcached_server_function callbacks[1];
189
callbacks[0]= server_function;
191
unsigned int iferror;
192
iferror= (*callbacks[0])(memc, &memc->servers[host_number], (void *)&context);
204
} /* namespace drizzle_plugin */
61
memcached_stat_st *stats= memcached_stat(serv, NULL, &rc);
62
memcached_server_st *servers= memcached_server_list(serv);
64
for (uint32_t i= 0; i < memcached_server_count(serv); i++)
66
char **list= memcached_stat_get_keys(serv, &stats[i], &rc);
69
table->setWriteSet(0);
70
table->setWriteSet(1);
72
table->field[0]->store(memcached_server_name(serv, servers[i]),
75
table->field[1]->store(memcached_server_port(serv, servers[i]));
77
for (ptr= list; *ptr; ptr++)
79
char *value= memcached_stat_get_value(serv, &stats[i], *ptr, &rc);
81
table->setWriteSet(col);
82
table->field[col]->store(value,
89
/* store the actual record now */
90
schema_table->addRow(table->record[0], table->s->reclength);
93
memcached_stat_free(serv, stats);
99
bool createMemcachedStatsColumns(vector<const plugin::ColumnInfo *> &cols)
102
* Create each column for the memcached stats table.
104
const plugin::ColumnInfo *name_col= new(std::nothrow) plugin::ColumnInfo("NAME",
106
DRIZZLE_TYPE_VARCHAR,
115
const plugin::ColumnInfo *port= new(std::nothrow) plugin::ColumnInfo("PORT_NUMBER",
117
DRIZZLE_TYPE_LONGLONG,
126
const plugin::ColumnInfo *pid= new(std::nothrow) plugin::ColumnInfo("PROCESS_ID",
128
DRIZZLE_TYPE_LONGLONG,
137
const plugin::ColumnInfo *uptime= new(std::nothrow) plugin::ColumnInfo("UPTIME",
139
DRIZZLE_TYPE_LONGLONG,
148
const plugin::ColumnInfo *time= new(std::nothrow) plugin::ColumnInfo("TIME",
150
DRIZZLE_TYPE_LONGLONG,
159
const plugin::ColumnInfo *version= new(std::nothrow) plugin::ColumnInfo("VERSION",
161
DRIZZLE_TYPE_VARCHAR,
170
const plugin::ColumnInfo *ptr_size= new(std::nothrow) plugin::ColumnInfo("POINTER_SIZE",
172
DRIZZLE_TYPE_LONGLONG,
181
const plugin::ColumnInfo *r_user= new(std::nothrow) plugin::ColumnInfo("RUSAGE_USER",
183
DRIZZLE_TYPE_LONGLONG,
192
const plugin::ColumnInfo *r_sys= new(std::nothrow) plugin::ColumnInfo("RUSAGE_SYSTEM",
194
DRIZZLE_TYPE_LONGLONG,
202
const plugin::ColumnInfo *curr_items= new(std::nothrow) plugin::ColumnInfo("CURRENT_ITEMS",
204
DRIZZLE_TYPE_LONGLONG,
213
const plugin::ColumnInfo *total_items= new(std::nothrow) plugin::ColumnInfo("TOTAL_ITEMS",
215
DRIZZLE_TYPE_LONGLONG,
224
const plugin::ColumnInfo *bytes= new(std::nothrow) plugin::ColumnInfo("BYTES",
226
DRIZZLE_TYPE_LONGLONG,
235
const plugin::ColumnInfo *curr_cons= new(std::nothrow) plugin::ColumnInfo("CURRENT_CONNECTIONS",
237
DRIZZLE_TYPE_LONGLONG,
240
"Current Connections");
246
const plugin::ColumnInfo *total_cons= new(std::nothrow) plugin::ColumnInfo("TOTAL_CONNECTIONS",
248
DRIZZLE_TYPE_LONGLONG,
251
"Total Connections");
257
const plugin::ColumnInfo *con_structs= new(std::nothrow) plugin::ColumnInfo("CONNECTION_STRUCTURES",
259
DRIZZLE_TYPE_LONGLONG,
262
"Connection Structures");
268
const plugin::ColumnInfo *cmd_gets= new(std::nothrow) plugin::ColumnInfo("GETS",
270
DRIZZLE_TYPE_LONGLONG,
279
const plugin::ColumnInfo *cmd_sets= new(std::nothrow) plugin::ColumnInfo("SETS",
281
DRIZZLE_TYPE_LONGLONG,
290
const plugin::ColumnInfo *hits= new(std::nothrow) plugin::ColumnInfo("HITS",
292
DRIZZLE_TYPE_LONGLONG,
301
const plugin::ColumnInfo *misses= new(std::nothrow) plugin::ColumnInfo("MISSES",
303
DRIZZLE_TYPE_LONGLONG,
312
const plugin::ColumnInfo *evicts= new(std::nothrow) plugin::ColumnInfo("EVICTIONS",
314
DRIZZLE_TYPE_LONGLONG,
323
const plugin::ColumnInfo *bytes_read= new(std::nothrow) plugin::ColumnInfo("BYTES_READ",
325
DRIZZLE_TYPE_LONGLONG,
334
const plugin::ColumnInfo *bytes_written= new(std::nothrow) plugin::ColumnInfo("BYTES_WRITTEN",
336
DRIZZLE_TYPE_LONGLONG,
345
const plugin::ColumnInfo *lim_max_bytes= new(std::nothrow) plugin::ColumnInfo("LIMIT_MAXBYTES",
347
DRIZZLE_TYPE_LONGLONG,
356
const plugin::ColumnInfo *threads= new(std::nothrow) plugin::ColumnInfo("THREADS",
358
DRIZZLE_TYPE_LONGLONG,
367
cols.push_back(name_col);
368
cols.push_back(port);
370
cols.push_back(uptime);
371
cols.push_back(time);
372
cols.push_back(version);
373
cols.push_back(ptr_size);
374
cols.push_back(r_user);
375
cols.push_back(r_sys);
376
cols.push_back(curr_items);
377
cols.push_back(total_items);
378
cols.push_back(bytes);
379
cols.push_back(curr_cons);
380
cols.push_back(total_cons);
381
cols.push_back(con_structs);
382
cols.push_back(cmd_gets);
383
cols.push_back(cmd_sets);
384
cols.push_back(hits);
385
cols.push_back(misses);
386
cols.push_back(evicts);
387
cols.push_back(bytes_read);
388
cols.push_back(bytes_written);
389
cols.push_back(lim_max_bytes);
390
cols.push_back(threads);
395
class DeleteMemcachedCols
399
inline void operator()(const T *ptr) const
405
void clearMemcachedColumns(vector<const plugin::ColumnInfo *> &cols)
407
for_each(cols.begin(), cols.end(), DeleteMemcachedCols());