2
* Copyright (c) 2009, Padraig O'Sullivan
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* * Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* * Neither the name of Padraig O'Sullivan nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27
* THE POSSIBILITY OF SUCH DAMAGE.
31
#include "drizzled/session.h"
32
#include "drizzled/show.h"
34
#include "stats_table.h"
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);
57
memcached_server_st *tmp_serv=
58
memcached_servers_parse(servers_string.c_str());
59
memcached_server_push(serv, tmp_serv);
60
memcached_server_list_free(tmp_serv);
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());