27
27
* THE POSSIBILITY OF SUCH DAMAGE.
30
#include "drizzled/server_includes.h"
31
#include "drizzled/session.h"
32
#include "drizzled/show.h"
32
34
#include "analysis_table.h"
33
35
#include "sysvar_holder.h"
35
#include "drizzled/error.h"
37
37
#include <libmemcached/memcached.h>
39
42
using namespace std;
40
43
using namespace drizzled;
42
AnalysisTableTool::AnalysisTableTool() :
43
plugin::TableFunction("DATA_DICTIONARY", "MEMCACHED_ANALYSIS")
45
add_field("SERVERS_ANALYZED", plugin::TableFunction::NUMBER);
46
add_field("AVERAGE_ITEM_SIZE", plugin::TableFunction::NUMBER);
47
add_field("NODE_WITH_MOST_MEM_CONSUMPTION");
48
add_field("USED_BYTES", plugin::TableFunction::NUMBER);
49
add_field("NODE_WITH_LEAST_FREE_SPACE");
50
add_field("FREE_BYTES", plugin::TableFunction::NUMBER);
51
add_field("NODE_WITH_LONGEST_UPTIME");
52
add_field("LONGEST_UPTIME", plugin::TableFunction::NUMBER);
53
add_field("POOL_WIDE_HIT_RATIO", plugin::TableFunction::NUMBER);
56
AnalysisTableTool::Generator::Generator(Field **arg) :
57
plugin::TableFunction::Generator(arg)
62
bool AnalysisTableTool::Generator::populate()
45
int MemcachedAnalysisISMethods::fillTable(Session *,
47
plugin::InfoSchemaTable *schema_table)
49
const CHARSET_INFO * const scs= system_charset_info;
70
50
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
71
51
const string servers_string= sysvar_holder.getServersString();
73
if (servers_string.empty())
75
my_printf_error(ER_UNKNOWN_ERROR, _("No value in MEMCACHED_STATS_SERVERS variable."), MYF(0));
79
53
memcached_return rc;
80
54
memcached_st *serv= memcached_create(NULL);
81
55
memcached_server_st *tmp_serv=
90
64
if (server_count > 1)
92
66
memcached_analysis_st *report= memcached_analyze(serv, stats, &rc);
94
push(static_cast<uint64_t>(server_count));
95
push(static_cast<uint64_t>(report->average_item_size));
96
push(memcached_server_name(serv, servers[report->most_consumed_server]));
97
push(report->most_used_bytes);
98
push(memcached_server_name(serv, servers[report->least_free_server]));
99
push(report->least_remaining_bytes);
100
push(memcached_server_name(serv, servers[report->oldest_server]));
101
push(static_cast<uint64_t>(report->longest_uptime));
102
push(static_cast<int64_t>(report->pool_hit_ratio));
67
table->restoreRecordAsDefault();
69
table->field[0]->store(server_count);
70
table->field[1]->store(report->average_item_size);
72
table->field[2]->store(memcached_server_name(serv,
73
servers[report->most_consumed_server]),
76
table->field[3]->store(report->most_used_bytes);
77
table->field[4]->store(memcached_server_name(serv,
78
servers[report->least_free_server]),
81
table->field[5]->store(report->least_remaining_bytes);
82
table->field[6]->store(memcached_server_name(serv,
83
servers[report->oldest_server]),
86
table->field[7]->store(report->longest_uptime);
87
table->field[8]->store(report->pool_hit_ratio);
89
/* store the actual record now */
90
schema_table->addRow(table->record[0], table->s->reclength);
106
94
memcached_stat_free(serv, stats);
107
95
memcached_free(serv);
99
bool createMemcachedAnalysisColumns(vector<const plugin::ColumnInfo *> &cols)
102
* Create each column for the memcached analysis table.
104
const plugin::ColumnInfo *num_analyzed= new(std::nothrow) plugin::ColumnInfo("SERVERS_ANALYZED",
106
DRIZZLE_TYPE_LONGLONG,
109
"Num of Servers Analyzed");
115
const plugin::ColumnInfo *avg_size= new(std::nothrow) plugin::ColumnInfo("AVERAGE_ITEM_SIZE",
117
DRIZZLE_TYPE_LONGLONG,
120
"Average Item Size");
126
const plugin::ColumnInfo *mem_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_MOST_MEM_CONSUMPTION",
128
DRIZZLE_TYPE_VARCHAR,
131
"Node with Most Memory Consumption");
137
const plugin::ColumnInfo *used_bytes= new(std::nothrow) plugin::ColumnInfo("USED_BYTES",
139
DRIZZLE_TYPE_LONGLONG,
148
const plugin::ColumnInfo *free_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LEAST_FREE_SPACE",
150
DRIZZLE_TYPE_VARCHAR,
153
"Node with Least Free Space");
159
const plugin::ColumnInfo *free_bytes= new(std::nothrow) plugin::ColumnInfo("FREE_BYTES",
161
DRIZZLE_TYPE_LONGLONG,
170
const plugin::ColumnInfo *up_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LONGEST_UPTIME",
172
DRIZZLE_TYPE_VARCHAR,
175
"Node with Longest Uptime");
181
const plugin::ColumnInfo *uptime= new(std::nothrow) plugin::ColumnInfo("LONGEST_UPTIME",
183
DRIZZLE_TYPE_LONGLONG,
192
const plugin::ColumnInfo *hit_ratio= new(std::nothrow) plugin::ColumnInfo("POOL_WIDE_HIT_RATIO",
194
DRIZZLE_TYPE_LONGLONG,
197
"Pool-wide Hit Ratio");
204
cols.push_back(num_analyzed);
205
cols.push_back(avg_size);
206
cols.push_back(mem_node);
207
cols.push_back(used_bytes);
208
cols.push_back(free_node);
209
cols.push_back(free_bytes);
210
cols.push_back(up_node);
211
cols.push_back(uptime);
212
cols.push_back(hit_ratio);