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 "analysis_table.h"
35
#include "sysvar_holder.h"
37
#include <libmemcached/memcached.h>
43
using namespace drizzled;
45
int MemcachedAnalysisISMethods::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();
54
memcached_st *serv= memcached_create(NULL);
55
memcached_server_st *tmp_serv=
56
memcached_servers_parse(servers_string.c_str());
57
memcached_server_push(serv, tmp_serv);
58
memcached_server_list_free(tmp_serv);
59
memcached_stat_st *stats= memcached_stat(serv, NULL, &rc);
60
memcached_server_st *servers= memcached_server_list(serv);
62
uint32_t server_count= memcached_server_count(serv);
66
memcached_analysis_st *report= memcached_analyze(serv, stats, &rc);
67
table->restoreRecordAsDefault();
69
table->setWriteSet(0);
70
table->setWriteSet(1);
71
table->setWriteSet(2);
72
table->setWriteSet(3);
73
table->setWriteSet(4);
74
table->setWriteSet(5);
75
table->setWriteSet(6);
76
table->setWriteSet(7);
77
table->setWriteSet(8);
79
table->field[0]->store(server_count);
80
table->field[1]->store(report->average_item_size);
82
table->field[2]->store(memcached_server_name(serv,
83
servers[report->most_consumed_server]),
86
table->field[3]->store(report->most_used_bytes);
87
table->field[4]->store(memcached_server_name(serv,
88
servers[report->least_free_server]),
91
table->field[5]->store(report->least_remaining_bytes);
92
table->field[6]->store(memcached_server_name(serv,
93
servers[report->oldest_server]),
96
table->field[7]->store(report->longest_uptime);
97
table->field[8]->store(report->pool_hit_ratio);
99
/* store the actual record now */
100
schema_table->addRow(table->record[0], table->s->reclength);
104
memcached_stat_free(serv, stats);
105
memcached_free(serv);
109
bool createMemcachedAnalysisColumns(vector<const plugin::ColumnInfo *> &cols)
112
* Create each column for the memcached analysis table.
114
const plugin::ColumnInfo *num_analyzed= new(std::nothrow) plugin::ColumnInfo("SERVERS_ANALYZED",
116
DRIZZLE_TYPE_LONGLONG,
119
"Num of Servers Analyzed");
125
const plugin::ColumnInfo *avg_size= new(std::nothrow) plugin::ColumnInfo("AVERAGE_ITEM_SIZE",
127
DRIZZLE_TYPE_LONGLONG,
130
"Average Item Size");
136
const plugin::ColumnInfo *mem_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_MOST_MEM_CONSUMPTION",
138
DRIZZLE_TYPE_VARCHAR,
141
"Node with Most Memory Consumption");
147
const plugin::ColumnInfo *used_bytes= new(std::nothrow) plugin::ColumnInfo("USED_BYTES",
149
DRIZZLE_TYPE_LONGLONG,
158
const plugin::ColumnInfo *free_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LEAST_FREE_SPACE",
160
DRIZZLE_TYPE_VARCHAR,
163
"Node with Least Free Space");
169
const plugin::ColumnInfo *free_bytes= new(std::nothrow) plugin::ColumnInfo("FREE_BYTES",
171
DRIZZLE_TYPE_LONGLONG,
180
const plugin::ColumnInfo *up_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LONGEST_UPTIME",
182
DRIZZLE_TYPE_VARCHAR,
185
"Node with Longest Uptime");
191
const plugin::ColumnInfo *uptime= new(std::nothrow) plugin::ColumnInfo("LONGEST_UPTIME",
193
DRIZZLE_TYPE_LONGLONG,
202
const plugin::ColumnInfo *hit_ratio= new(std::nothrow) plugin::ColumnInfo("POOL_WIDE_HIT_RATIO",
204
DRIZZLE_TYPE_LONGLONG,
207
"Pool-wide Hit Ratio");
214
cols.push_back(num_analyzed);
215
cols.push_back(avg_size);
216
cols.push_back(mem_node);
217
cols.push_back(used_bytes);
218
cols.push_back(free_node);
219
cols.push_back(free_bytes);
220
cols.push_back(up_node);
221
cols.push_back(uptime);
222
cols.push_back(hit_ratio);