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>
38
#include <libmemcached/server.h>
40
namespace drizzle_plugin
43
AnalysisTableTool::AnalysisTableTool() :
44
plugin::TableFunction("DATA_DICTIONARY", "MEMCACHED_ANALYSIS")
46
add_field("SERVERS_ANALYZED", plugin::TableFunction::NUMBER);
47
add_field("AVERAGE_ITEM_SIZE", plugin::TableFunction::NUMBER);
48
add_field("NODE_WITH_MOST_MEM_CONSUMPTION");
49
add_field("USED_BYTES", plugin::TableFunction::NUMBER);
50
add_field("NODE_WITH_LEAST_FREE_SPACE");
51
add_field("FREE_BYTES", plugin::TableFunction::NUMBER);
52
add_field("NODE_WITH_LONGEST_UPTIME");
53
add_field("LONGEST_UPTIME", plugin::TableFunction::NUMBER);
54
add_field("POOL_WIDE_HIT_RATIO", plugin::TableFunction::NUMBER);
57
AnalysisTableTool::Generator::Generator(Field **arg) :
58
plugin::TableFunction::Generator(arg)
63
bool AnalysisTableTool::Generator::populate()
71
drizzled::sys_var *servers_var= drizzled::find_sys_var("memcached_stats_servers");
72
assert(servers_var != NULL);
74
const string servers_string(static_cast<char *>(servers_var.value_ptr(NULL, 0, NULL)));
76
if (servers_string.empty())
78
my_printf_error(ER_UNKNOWN_ERROR, _("No value in MEMCACHED_STATS_SERVERS variable."), MYF(0));
43
using namespace drizzled;
45
int MemcachedAnalysisISMethods::fillTable(Session *session,
48
const CHARSET_INFO * const scs= system_charset_info;
49
Table *table= tables->table;
50
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
51
const string servers_string= sysvar_holder.getServersString();
82
53
memcached_return rc;
83
54
memcached_st *serv= memcached_create(NULL);
93
64
if (server_count > 1)
95
66
memcached_analysis_st *report= memcached_analyze(serv, stats, &rc);
97
push(static_cast<uint64_t>(server_count));
98
push(static_cast<uint64_t>(report->average_item_size));
99
push(memcached_server_name(serv, servers[report->most_consumed_server]));
100
push(report->most_used_bytes);
101
push(memcached_server_name(serv, servers[report->least_free_server]));
102
push(report->least_remaining_bytes);
103
push(memcached_server_name(serv, servers[report->oldest_server]));
104
push(static_cast<uint64_t>(report->longest_uptime));
105
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
if (schema_table_store_record(session, table))
109
97
memcached_stat_free(serv, stats);
110
98
memcached_free(serv);
115
} /* namespace drizzle_plugin */
102
bool createMemcachedAnalysisColumns(vector<const plugin::ColumnInfo *> &cols)
105
* Create each column for the memcached analysis table.
107
const plugin::ColumnInfo *num_analyzed= new(std::nothrow) plugin::ColumnInfo("SERVERS_ANALYZED",
109
DRIZZLE_TYPE_LONGLONG,
112
"Num of Servers Analyzed",
119
const plugin::ColumnInfo *avg_size= new(std::nothrow) plugin::ColumnInfo("AVERAGE_ITEM_SIZE",
121
DRIZZLE_TYPE_LONGLONG,
131
const plugin::ColumnInfo *mem_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_MOST_MEM_CONSUMPTION",
133
DRIZZLE_TYPE_VARCHAR,
136
"Node with Most Memory Consumption",
143
const plugin::ColumnInfo *used_bytes= new(std::nothrow) plugin::ColumnInfo("USED_BYTES",
145
DRIZZLE_TYPE_LONGLONG,
155
const plugin::ColumnInfo *free_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LEAST_FREE_SPACE",
157
DRIZZLE_TYPE_VARCHAR,
160
"Node with Least Free Space",
167
const plugin::ColumnInfo *free_bytes= new(std::nothrow) plugin::ColumnInfo("FREE_BYTES",
169
DRIZZLE_TYPE_LONGLONG,
179
const plugin::ColumnInfo *up_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LONGEST_UPTIME",
181
DRIZZLE_TYPE_VARCHAR,
184
"Node with Longest Uptime",
191
const plugin::ColumnInfo *uptime= new(std::nothrow) plugin::ColumnInfo("LONGEST_UPTIME",
193
DRIZZLE_TYPE_LONGLONG,
203
const plugin::ColumnInfo *hit_ratio= new(std::nothrow) plugin::ColumnInfo("POOL_WIDE_HIT_RATIO",
205
DRIZZLE_TYPE_LONGLONG,
208
"Pool-wide Hit Ratio",
216
cols.push_back(num_analyzed);
217
cols.push_back(avg_size);
218
cols.push_back(mem_node);
219
cols.push_back(used_bytes);
220
cols.push_back(free_node);
221
cols.push_back(free_bytes);
222
cols.push_back(up_node);
223
cols.push_back(uptime);
224
cols.push_back(hit_ratio);