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.
32
#include "analysis_table.h"
33
#include "sysvar_holder.h"
35
#include "drizzled/error.h"
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));
83
memcached_st *serv= memcached_create(NULL);
84
memcached_server_st *tmp_serv=
85
memcached_servers_parse(servers_string.c_str());
86
memcached_server_push(serv, tmp_serv);
87
memcached_server_list_free(tmp_serv);
88
memcached_stat_st *stats= memcached_stat(serv, NULL, &rc);
89
memcached_server_st *servers= memcached_server_list(serv);
91
uint32_t server_count= memcached_server_count(serv);
95
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));
109
memcached_stat_free(serv, stats);
110
memcached_free(serv);
115
} /* namespace drizzle_plugin */