2
* Copyright (C) 2009 Sun Microsystems
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
#include "drizzled/server_includes.h"
20
#include "drizzled/session.h"
21
#include "drizzled/show.h"
23
#include "stats_table.h"
25
#include <libmemcached/memcached.h>
32
int MemcachedStatsISMethods::fillTable(Session *session,
36
const CHARSET_INFO * const scs= system_charset_info;
37
Table *table= tables->table;
39
table->restoreRecordAsDefault();
42
memcached_st *serv= memcached_create(NULL);
43
memcached_server_st *tmp_serv=
44
memcached_servers_parse(servers_string.c_str());
45
memcached_server_push(serv, tmp_serv);
46
memcached_server_list_free(tmp_serv);
47
memcached_stat_st *stats= memcached_stat(serv, NULL, &rc);
48
memcached_server_st *servers= memcached_server_list(serv);
50
for (uint32_t i= 0; i < memcached_server_count(serv); i++)
52
char **list= memcached_stat_get_keys(serv, &stats[i], &rc);
55
table->field[0]->store(memcached_server_name(serv, servers[i]),
58
table->field[1]->store(memcached_server_port(serv, servers[i]));
60
for (ptr= list; *ptr; ptr++)
62
char *value= memcached_stat_get_value(serv, &stats[i], *ptr, &rc);
63
table->field[col]->store(value,
72
memcached_stat_free(serv, stats);
75
/* store the actual record now */
76
if (schema_table_store_record(session, table))
84
bool createMemcachedStatsColumns(vector<const ColumnInfo *> &cols)
87
* Create each column for the memcached stats table.
89
const ColumnInfo *name_col= new(std::nothrow) ColumnInfo("NAME",
101
const ColumnInfo *port= new(std::nothrow) ColumnInfo("PORT_NUMBER",
103
DRIZZLE_TYPE_LONGLONG,
113
const ColumnInfo *pid= new(std::nothrow) ColumnInfo("PROCESS_ID",
115
DRIZZLE_TYPE_LONGLONG,
125
const ColumnInfo *uptime= new(std::nothrow) ColumnInfo("UPTIME",
127
DRIZZLE_TYPE_LONGLONG,
137
const ColumnInfo *time= new(std::nothrow) ColumnInfo("TIME",
139
DRIZZLE_TYPE_LONGLONG,
149
const ColumnInfo *version= new(std::nothrow) ColumnInfo("VERSION",
151
DRIZZLE_TYPE_VARCHAR,
161
const ColumnInfo *ptr_size= new(std::nothrow) ColumnInfo("POINTER_SIZE",
163
DRIZZLE_TYPE_LONGLONG,
173
const ColumnInfo *r_user= new(std::nothrow) ColumnInfo("RUSAGE_USER",
175
DRIZZLE_TYPE_LONGLONG,
185
const ColumnInfo *r_sys= new(std::nothrow) ColumnInfo("RUSAGE_SYSTEM",
187
DRIZZLE_TYPE_LONGLONG,
196
const ColumnInfo *curr_items= new(std::nothrow) ColumnInfo("CURRENT_ITEMS",
198
DRIZZLE_TYPE_LONGLONG,
208
const ColumnInfo *total_items= new(std::nothrow) ColumnInfo("TOTAL_ITEMS",
210
DRIZZLE_TYPE_LONGLONG,
220
const ColumnInfo *bytes= new(std::nothrow) ColumnInfo("BYTES",
222
DRIZZLE_TYPE_LONGLONG,
232
const ColumnInfo *curr_cons= new(std::nothrow) ColumnInfo("CURRENT_CONNECTIONS",
234
DRIZZLE_TYPE_LONGLONG,
237
"Current Connections",
244
const ColumnInfo *total_cons= new(std::nothrow) ColumnInfo("TOTAL_CONNECTIONS",
246
DRIZZLE_TYPE_LONGLONG,
256
const ColumnInfo *con_structs= new(std::nothrow) ColumnInfo("CONNECTION_STRUCTURES",
258
DRIZZLE_TYPE_LONGLONG,
261
"Connection Structures",
268
const ColumnInfo *cmd_gets= new(std::nothrow) ColumnInfo("GETS",
270
DRIZZLE_TYPE_LONGLONG,
280
const ColumnInfo *cmd_sets= new(std::nothrow) ColumnInfo("SETS",
282
DRIZZLE_TYPE_LONGLONG,
292
const ColumnInfo *hits= new(std::nothrow) ColumnInfo("HITS",
294
DRIZZLE_TYPE_LONGLONG,
304
const ColumnInfo *misses= new(std::nothrow) ColumnInfo("MISSES",
306
DRIZZLE_TYPE_LONGLONG,
316
const ColumnInfo *evicts= new(std::nothrow) ColumnInfo("EVICTIONS",
318
DRIZZLE_TYPE_LONGLONG,
328
const ColumnInfo *bytes_read= new(std::nothrow) ColumnInfo("BYTES_READ",
330
DRIZZLE_TYPE_LONGLONG,
340
const ColumnInfo *bytes_written= new(std::nothrow) ColumnInfo("BYTES_WRITTEN",
342
DRIZZLE_TYPE_LONGLONG,
352
const ColumnInfo *lim_max_bytes= new(std::nothrow) ColumnInfo("LIMIT_MAXBYTES",
354
DRIZZLE_TYPE_LONGLONG,
364
const ColumnInfo *threads= new(std::nothrow) ColumnInfo("THREADS",
366
DRIZZLE_TYPE_LONGLONG,
376
cols.push_back(name_col);
377
cols.push_back(port);
379
cols.push_back(uptime);
380
cols.push_back(time);
381
cols.push_back(version);
382
cols.push_back(ptr_size);
383
cols.push_back(r_user);
384
cols.push_back(r_sys);
385
cols.push_back(curr_items);
386
cols.push_back(total_items);
387
cols.push_back(bytes);
388
cols.push_back(curr_cons);
389
cols.push_back(total_cons);
390
cols.push_back(con_structs);
391
cols.push_back(cmd_gets);
392
cols.push_back(cmd_sets);
393
cols.push_back(hits);
394
cols.push_back(misses);
395
cols.push_back(evicts);
396
cols.push_back(bytes_read);
397
cols.push_back(bytes_written);
398
cols.push_back(lim_max_bytes);
399
cols.push_back(threads);
404
class DeleteMemcachedCols
408
inline void operator()(const T *ptr) const
414
void clearMemcachedColumns(vector<const ColumnInfo *> &cols)
416
for_each(cols.begin(), cols.end(), DeleteMemcachedCols());