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.
30
#include "drizzled/server_includes.h"
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 *session,
49
const CHARSET_INFO * const scs= system_charset_info;
50
Table *table= tables->table;
51
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
52
const string servers_string= sysvar_holder.getServersString();
54
table->restoreRecordAsDefault();
57
memcached_st *serv= memcached_create(NULL);
58
memcached_server_st *tmp_serv=
59
memcached_servers_parse(servers_string.c_str());
60
memcached_server_push(serv, tmp_serv);
61
memcached_server_list_free(tmp_serv);
62
memcached_stat_st *stats= memcached_stat(serv, NULL, &rc);
63
memcached_server_st *servers= memcached_server_list(serv);
65
for (uint32_t i= 0; i < memcached_server_count(serv); i++)
67
char **list= memcached_stat_get_keys(serv, &stats[i], &rc);
70
table->field[0]->store(memcached_server_name(serv, servers[i]),
73
table->field[1]->store(memcached_server_port(serv, servers[i]));
75
for (ptr= list; *ptr; ptr++)
77
char *value= memcached_stat_get_value(serv, &stats[i], *ptr, &rc);
78
table->field[col]->store(value,
85
/* store the actual record now */
86
if (schema_table_store_record(session, table))
92
memcached_stat_free(serv, stats);
98
bool createMemcachedStatsColumns(vector<const plugin::ColumnInfo *> &cols)
101
* Create each column for the memcached stats table.
103
const plugin::ColumnInfo *name_col= new(std::nothrow) plugin::ColumnInfo("NAME",
105
DRIZZLE_TYPE_VARCHAR,
115
const plugin::ColumnInfo *port= new(std::nothrow) plugin::ColumnInfo("PORT_NUMBER",
117
DRIZZLE_TYPE_LONGLONG,
127
const plugin::ColumnInfo *pid= new(std::nothrow) plugin::ColumnInfo("PROCESS_ID",
129
DRIZZLE_TYPE_LONGLONG,
139
const plugin::ColumnInfo *uptime= new(std::nothrow) plugin::ColumnInfo("UPTIME",
141
DRIZZLE_TYPE_LONGLONG,
151
const plugin::ColumnInfo *time= new(std::nothrow) plugin::ColumnInfo("TIME",
153
DRIZZLE_TYPE_LONGLONG,
163
const plugin::ColumnInfo *version= new(std::nothrow) plugin::ColumnInfo("VERSION",
165
DRIZZLE_TYPE_VARCHAR,
175
const plugin::ColumnInfo *ptr_size= new(std::nothrow) plugin::ColumnInfo("POINTER_SIZE",
177
DRIZZLE_TYPE_LONGLONG,
187
const plugin::ColumnInfo *r_user= new(std::nothrow) plugin::ColumnInfo("RUSAGE_USER",
189
DRIZZLE_TYPE_LONGLONG,
199
const plugin::ColumnInfo *r_sys= new(std::nothrow) plugin::ColumnInfo("RUSAGE_SYSTEM",
201
DRIZZLE_TYPE_LONGLONG,
210
const plugin::ColumnInfo *curr_items= new(std::nothrow) plugin::ColumnInfo("CURRENT_ITEMS",
212
DRIZZLE_TYPE_LONGLONG,
222
const plugin::ColumnInfo *total_items= new(std::nothrow) plugin::ColumnInfo("TOTAL_ITEMS",
224
DRIZZLE_TYPE_LONGLONG,
234
const plugin::ColumnInfo *bytes= new(std::nothrow) plugin::ColumnInfo("BYTES",
236
DRIZZLE_TYPE_LONGLONG,
246
const plugin::ColumnInfo *curr_cons= new(std::nothrow) plugin::ColumnInfo("CURRENT_CONNECTIONS",
248
DRIZZLE_TYPE_LONGLONG,
251
"Current Connections",
258
const plugin::ColumnInfo *total_cons= new(std::nothrow) plugin::ColumnInfo("TOTAL_CONNECTIONS",
260
DRIZZLE_TYPE_LONGLONG,
270
const plugin::ColumnInfo *con_structs= new(std::nothrow) plugin::ColumnInfo("CONNECTION_STRUCTURES",
272
DRIZZLE_TYPE_LONGLONG,
275
"Connection Structures",
282
const plugin::ColumnInfo *cmd_gets= new(std::nothrow) plugin::ColumnInfo("GETS",
284
DRIZZLE_TYPE_LONGLONG,
294
const plugin::ColumnInfo *cmd_sets= new(std::nothrow) plugin::ColumnInfo("SETS",
296
DRIZZLE_TYPE_LONGLONG,
306
const plugin::ColumnInfo *hits= new(std::nothrow) plugin::ColumnInfo("HITS",
308
DRIZZLE_TYPE_LONGLONG,
318
const plugin::ColumnInfo *misses= new(std::nothrow) plugin::ColumnInfo("MISSES",
320
DRIZZLE_TYPE_LONGLONG,
330
const plugin::ColumnInfo *evicts= new(std::nothrow) plugin::ColumnInfo("EVICTIONS",
332
DRIZZLE_TYPE_LONGLONG,
342
const plugin::ColumnInfo *bytes_read= new(std::nothrow) plugin::ColumnInfo("BYTES_READ",
344
DRIZZLE_TYPE_LONGLONG,
354
const plugin::ColumnInfo *bytes_written= new(std::nothrow) plugin::ColumnInfo("BYTES_WRITTEN",
356
DRIZZLE_TYPE_LONGLONG,
366
const plugin::ColumnInfo *lim_max_bytes= new(std::nothrow) plugin::ColumnInfo("LIMIT_MAXBYTES",
368
DRIZZLE_TYPE_LONGLONG,
378
const plugin::ColumnInfo *threads= new(std::nothrow) plugin::ColumnInfo("THREADS",
380
DRIZZLE_TYPE_LONGLONG,
390
cols.push_back(name_col);
391
cols.push_back(port);
393
cols.push_back(uptime);
394
cols.push_back(time);
395
cols.push_back(version);
396
cols.push_back(ptr_size);
397
cols.push_back(r_user);
398
cols.push_back(r_sys);
399
cols.push_back(curr_items);
400
cols.push_back(total_items);
401
cols.push_back(bytes);
402
cols.push_back(curr_cons);
403
cols.push_back(total_cons);
404
cols.push_back(con_structs);
405
cols.push_back(cmd_gets);
406
cols.push_back(cmd_sets);
407
cols.push_back(hits);
408
cols.push_back(misses);
409
cols.push_back(evicts);
410
cols.push_back(bytes_read);
411
cols.push_back(bytes_written);
412
cols.push_back(lim_max_bytes);
413
cols.push_back(threads);
418
class DeleteMemcachedCols
422
inline void operator()(const T *ptr) const
428
void clearMemcachedColumns(vector<const plugin::ColumnInfo *> &cols)
430
for_each(cols.begin(), cols.end(), DeleteMemcachedCols());