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>
40
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()
70
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
71
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));
80
memcached_st *serv= memcached_create(NULL);
81
memcached_server_st *tmp_serv=
82
memcached_servers_parse(servers_string.c_str());
83
memcached_server_push(serv, tmp_serv);
84
memcached_server_list_free(tmp_serv);
85
memcached_stat_st *stats= memcached_stat(serv, NULL, &rc);
86
memcached_server_st *servers= memcached_server_list(serv);
88
uint32_t server_count= memcached_server_count(serv);
92
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));
106
memcached_stat_free(serv, stats);
107
memcached_free(serv);