~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memcached_stats/analysis_table.cc

  • Committer: Brian Aker
  • Date: 2008-08-16 15:41:14 UTC
  • mto: This revision was merged to the branch mainline in revision 346.
  • Revision ID: brian@tangent.org-20080816154114-eufmwf31p6ie1nd6
Cleaned up depend in Proto utils. Modified int to bool. Put TmpTable class
into play.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * Copyright (c) 2009, Padraig O'Sullivan
3
 
 * All rights reserved.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions are met:
7
 
 *
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.
16
 
 *
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.
28
 
 */
29
 
 
30
 
#include "drizzled/server_includes.h"
31
 
#include "drizzled/session.h"
32
 
#include "drizzled/show.h"
33
 
 
34
 
#include "analysis_table.h"
35
 
#include "sysvar_holder.h"
36
 
 
37
 
#include <libmemcached/memcached.h>
38
 
 
39
 
#include <string>
40
 
#include <vector>
41
 
 
42
 
using namespace std;
43
 
using namespace drizzled;
44
 
 
45
 
int MemcachedAnalysisISMethods::fillTable(Session *,
46
 
                                          Table *table,
47
 
                                          plugin::InfoSchemaTable *schema_table)
48
 
{
49
 
  const CHARSET_INFO * const scs= system_charset_info;
50
 
  SysvarHolder &sysvar_holder= SysvarHolder::singleton();
51
 
  const string servers_string= sysvar_holder.getServersString();
52
 
 
53
 
  memcached_return rc;
54
 
  memcached_st *serv= memcached_create(NULL);
55
 
  memcached_server_st *tmp_serv=
56
 
    memcached_servers_parse(servers_string.c_str());
57
 
  memcached_server_push(serv, tmp_serv);
58
 
  memcached_server_list_free(tmp_serv);
59
 
  memcached_stat_st *stats= memcached_stat(serv, NULL, &rc);
60
 
  memcached_server_st *servers= memcached_server_list(serv);
61
 
 
62
 
  uint32_t server_count= memcached_server_count(serv);
63
 
 
64
 
  if (server_count > 1)
65
 
  {
66
 
    memcached_analysis_st *report= memcached_analyze(serv, stats, &rc);
67
 
    table->restoreRecordAsDefault();
68
 
 
69
 
    table->field[0]->store(server_count);
70
 
    table->field[1]->store(report->average_item_size);
71
 
 
72
 
    table->field[2]->store(memcached_server_name(serv, 
73
 
                                                 servers[report->most_consumed_server]),
74
 
                           64,
75
 
                           scs);
76
 
    table->field[3]->store(report->most_used_bytes);
77
 
    table->field[4]->store(memcached_server_name(serv, 
78
 
                                                 servers[report->least_free_server]),
79
 
                           64,
80
 
                           scs);
81
 
    table->field[5]->store(report->least_remaining_bytes);
82
 
    table->field[6]->store(memcached_server_name(serv, 
83
 
                                                 servers[report->oldest_server]),
84
 
                           64,
85
 
                           scs);
86
 
    table->field[7]->store(report->longest_uptime);
87
 
    table->field[8]->store(report->pool_hit_ratio);
88
 
 
89
 
    /* store the actual record now */
90
 
    schema_table->addRow(table->record[0], table->s->reclength);
91
 
    free(report);
92
 
  }
93
 
 
94
 
  memcached_stat_free(serv, stats);
95
 
  memcached_free(serv);
96
 
  return 0;
97
 
}
98
 
 
99
 
bool createMemcachedAnalysisColumns(vector<const plugin::ColumnInfo *> &cols)
100
 
{
101
 
  /*
102
 
   * Create each column for the memcached analysis table.
103
 
   */
104
 
  const plugin::ColumnInfo *num_analyzed= new(std::nothrow) plugin::ColumnInfo("SERVERS_ANALYZED",
105
 
                                                               4,
106
 
                                                               DRIZZLE_TYPE_LONGLONG,
107
 
                                                               0,
108
 
                                                               0, 
109
 
                                                               "Num of Servers Analyzed");
110
 
  if (! num_analyzed)
111
 
  {
112
 
    return true;
113
 
  }
114
 
 
115
 
  const plugin::ColumnInfo *avg_size= new(std::nothrow) plugin::ColumnInfo("AVERAGE_ITEM_SIZE",
116
 
                                                           4,
117
 
                                                           DRIZZLE_TYPE_LONGLONG,
118
 
                                                           0,
119
 
                                                           0, 
120
 
                                                           "Average Item Size");
121
 
  if (! avg_size)
122
 
  {
123
 
    return true;
124
 
  }
125
 
 
126
 
  const plugin::ColumnInfo *mem_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_MOST_MEM_CONSUMPTION",
127
 
                                                           32,
128
 
                                                           DRIZZLE_TYPE_VARCHAR,
129
 
                                                           0,
130
 
                                                           0,
131
 
                                                           "Node with Most Memory Consumption");
132
 
  if (! mem_node)
133
 
  {
134
 
    return true;
135
 
  }
136
 
 
137
 
  const plugin::ColumnInfo *used_bytes= new(std::nothrow) plugin::ColumnInfo("USED_BYTES",
138
 
                                                             4,
139
 
                                                             DRIZZLE_TYPE_LONGLONG,
140
 
                                                             0,
141
 
                                                             0,
142
 
                                                             "Used Bytes");
143
 
  if (! used_bytes)
144
 
  {
145
 
    return true;
146
 
  }
147
 
 
148
 
  const plugin::ColumnInfo *free_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LEAST_FREE_SPACE",
149
 
                                                            32,
150
 
                                                            DRIZZLE_TYPE_VARCHAR,
151
 
                                                            0,
152
 
                                                            0,
153
 
                                                            "Node with Least Free Space");
154
 
  if (! free_node)
155
 
  {
156
 
    return true;
157
 
  }
158
 
 
159
 
  const plugin::ColumnInfo *free_bytes= new(std::nothrow) plugin::ColumnInfo("FREE_BYTES",
160
 
                                                             4,
161
 
                                                             DRIZZLE_TYPE_LONGLONG,
162
 
                                                             0,
163
 
                                                             0,
164
 
                                                             "Free Bytes");
165
 
  if (! free_bytes)
166
 
  {
167
 
    return true;
168
 
  }
169
 
 
170
 
  const plugin::ColumnInfo *up_node= new(std::nothrow) plugin::ColumnInfo("NODE_WITH_LONGEST_UPTIME",
171
 
                                                          32,
172
 
                                                          DRIZZLE_TYPE_VARCHAR,
173
 
                                                          0,
174
 
                                                          0,
175
 
                                                          "Node with Longest Uptime");
176
 
  if (! up_node)
177
 
  {
178
 
    return true;
179
 
  }
180
 
 
181
 
  const plugin::ColumnInfo *uptime= new(std::nothrow) plugin::ColumnInfo("LONGEST_UPTIME",
182
 
                                                         4,
183
 
                                                         DRIZZLE_TYPE_LONGLONG,
184
 
                                                         0,
185
 
                                                         0,
186
 
                                                         "Longest Uptime");
187
 
  if (! uptime)
188
 
  {
189
 
    return true;
190
 
  }
191
 
 
192
 
  const plugin::ColumnInfo *hit_ratio= new(std::nothrow) plugin::ColumnInfo("POOL_WIDE_HIT_RATIO",
193
 
                                                            4,
194
 
                                                            DRIZZLE_TYPE_LONGLONG,
195
 
                                                            0,
196
 
                                                            0,
197
 
                                                            "Pool-wide Hit Ratio");
198
 
  if (! hit_ratio)
199
 
  {
200
 
    return true;
201
 
  }
202
 
 
203
 
 
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);
213
 
 
214
 
  return false;
215
 
}
216