~jaypipes/drizzle/save-more-xa-work

« back to all changes in this revision

Viewing changes to plugin/memcached_stats/analysis_table.cc

  • Committer: Jay Pipes
  • Date: 2010-02-23 18:09:22 UTC
  • mfrom: (1273.1.33 staging)
  • Revision ID: jpipes@serialcoder-20100223180922-3km9cuep97eznug0
Merge trunk and fix conflicts.

Show diffs side-by-side

added added

removed removed

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