1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/*
* Copyright (c) 2009, Padraig O'Sullivan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Padraig O'Sullivan nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "drizzled/server_includes.h"
#include "drizzled/session.h"
#include "drizzled/show.h"
#include "analysis_table.h"
#include "sysvar_holder.h"
#include <libmemcached/memcached.h>
#include <string>
#include <vector>
using namespace std;
using namespace drizzled;
int MemcachedAnalysisISMethods::fillTable(Session *,
Table *table,
plugin::InfoSchemaTable *schema_table)
{
const CHARSET_INFO * const scs= system_charset_info;
SysvarHolder &sysvar_holder= SysvarHolder::singleton();
const string servers_string= sysvar_holder.getServersString();
memcached_return rc;
memcached_st *serv= memcached_create(NULL);
memcached_server_st *tmp_serv=
memcached_servers_parse(servers_string.c_str());
memcached_server_push(serv, tmp_serv);
memcached_server_list_free(tmp_serv);
memcached_stat_st *stats= memcached_stat(serv, NULL, &rc);
memcached_server_st *servers= memcached_server_list(serv);
uint32_t server_count= memcached_server_count(serv);
if (server_count > 1)
{
memcached_analysis_st *report= memcached_analyze(serv, stats, &rc);
table->restoreRecordAsDefault();
table->field[0]->store(server_count);
table->field[1]->store(report->average_item_size);
table->field[2]->store(memcached_server_name(serv,
servers[report->most_consumed_server]),
64,
scs);
table->field[3]->store(report->most_used_bytes);
table->field[4]->store(memcached_server_name(serv,
servers[report->least_free_server]),
64,
scs);
table->field[5]->store(report->least_remaining_bytes);
table->field[6]->store(memcached_server_name(serv,
servers[report->oldest_server]),
64,
scs);
table->field[7]->store(report->longest_uptime);
table->field[8]->store(report->pool_hit_ratio);
/* store the actual record now */
schema_table->addRow(table->record[0], table->s->reclength);
free(report);
}
memcached_stat_free(serv, stats);
memcached_free(serv);
return 0;
}
bool createMemcachedAnalysisColumns(vector<const plugin::ColumnInfo *> &cols)
{
/*
* Create each column for the memcached analysis table.
*/
const plugin::ColumnInfo *num_analyzed= new(std::nothrow) plugin::ColumnInfo("SERVERS_ANALYZED",
4,
DRIZZLE_TYPE_LONGLONG,
0,
0,
"Num of Servers Analyzed");
if (! num_analyzed)
{
return true;
}
const plugin::ColumnInfo *avg_size= new(std::nothrow) plugin::ColumnInfo("AVERAGE_ITEM_SIZE",
4,
DRIZZLE_TYPE_LONGLONG,
0,
0,
"Average Item Size");
if (! avg_size)
{
return true;
}
const plugin::ColumnInfo *mem_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_MOST_MEM_CONSUMPTION",
32,
DRIZZLE_TYPE_VARCHAR,
0,
0,
"Node with Most Memory Consumption");
if (! mem_node)
{
return true;
}
const plugin::ColumnInfo *used_bytes= new(std::nothrow) plugin::ColumnInfo("USED_BYTES",
4,
DRIZZLE_TYPE_LONGLONG,
0,
0,
"Used Bytes");
if (! used_bytes)
{
return true;
}
const plugin::ColumnInfo *free_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LEAST_FREE_SPACE",
32,
DRIZZLE_TYPE_VARCHAR,
0,
0,
"Node with Least Free Space");
if (! free_node)
{
return true;
}
const plugin::ColumnInfo *free_bytes= new(std::nothrow) plugin::ColumnInfo("FREE_BYTES",
4,
DRIZZLE_TYPE_LONGLONG,
0,
0,
"Free Bytes");
if (! free_bytes)
{
return true;
}
const plugin::ColumnInfo *up_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LONGEST_UPTIME",
32,
DRIZZLE_TYPE_VARCHAR,
0,
0,
"Node with Longest Uptime");
if (! up_node)
{
return true;
}
const plugin::ColumnInfo *uptime= new(std::nothrow) plugin::ColumnInfo("LONGEST_UPTIME",
4,
DRIZZLE_TYPE_LONGLONG,
0,
0,
"Longest Uptime");
if (! uptime)
{
return true;
}
const plugin::ColumnInfo *hit_ratio= new(std::nothrow) plugin::ColumnInfo("POOL_WIDE_HIT_RATIO",
4,
DRIZZLE_TYPE_LONGLONG,
0,
0,
"Pool-wide Hit Ratio");
if (! hit_ratio)
{
return true;
}
cols.push_back(num_analyzed);
cols.push_back(avg_size);
cols.push_back(mem_node);
cols.push_back(used_bytes);
cols.push_back(free_node);
cols.push_back(free_bytes);
cols.push_back(up_node);
cols.push_back(uptime);
cols.push_back(hit_ratio);
return false;
}
|