~drizzle-trunk/drizzle/development

1144.5.4 by Padraig O'Sullivan
Updated the licence to be BSD since I don't see why this would need to be GPL.
1
/* 
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
2
 * Copyright (C) 2009, Padraig O'Sullivan
1144.5.4 by Padraig O'Sullivan
Updated the licence to be BSD since I don't see why this would need to be GPL.
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.
1144.5.7 by Padraig O'Sullivan
Updated the BSD header to actually have my name instead of capttofu's!
13
 *   * Neither the name of Padraig O'Sullivan nor the names of its contributors
1144.5.4 by Padraig O'Sullivan
Updated the licence to be BSD since I don't see why this would need to be GPL.
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.
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
28
 */
29
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
30
#include <config.h>
1273.13.94 by Brian Aker
Lint fixes.
31
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
32
#include "analysis_table.h"
33
#include "sysvar_holder.h"
34
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
35
#include <drizzled/error.h>
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
36
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
37
#include <libmemcached/memcached.h>
1452.2.5 by Monty Taylor
Fixed the memcached_stats plugin to work with the latest libmemcached, now
38
#include <libmemcached/server.h>
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
39
1964.2.8 by Monty Taylor
Updated memcached_stats plugin.
40
namespace drizzle_plugin
41
{
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
42
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
43
AnalysisTableTool::AnalysisTableTool() :
44
  plugin::TableFunction("DATA_DICTIONARY", "MEMCACHED_ANALYSIS")
45
{
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); 
55
}
56
57
AnalysisTableTool::Generator::Generator(Field **arg) :
58
  plugin::TableFunction::Generator(arg)
59
{
60
  is_done= false;
61
}
62
63
bool AnalysisTableTool::Generator::populate()
64
{
65
  if (is_done)
66
  {
67
    return false;
68
  }
69
  is_done= true;
70
1964.2.8 by Monty Taylor
Updated memcached_stats plugin.
71
  drizzled::sys_var *servers_var= drizzled::find_sys_var("memcached_stats_servers");
72
  assert(servers_var != NULL);
73
74
  const string servers_string(static_cast<char *>(servers_var.value_ptr(NULL, 0, NULL)));
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
75
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
76
  if (servers_string.empty()) 
77
  {       
78
    my_printf_error(ER_UNKNOWN_ERROR, _("No value in MEMCACHED_STATS_SERVERS variable."), MYF(0));
79
    return false;
80
  }    
81
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
82
  memcached_return rc;
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);
90
91
  uint32_t server_count= memcached_server_count(serv);
92
93
  if (server_count > 1)
94
  {
1144.5.9 by Padraig O'Sullivan
Added a test suite for the memcached stats I_S tables. The test suite is
95
    memcached_analysis_st *report= memcached_analyze(serv, stats, &rc);
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
96
1368 by Brian Aker
Fix build issues, disabled tests (someone needs to go through them... who is
97
    push(static_cast<uint64_t>(server_count));
98
    push(static_cast<uint64_t>(report->average_item_size));
1452.2.5 by Monty Taylor
Fixed the memcached_stats plugin to work with the latest libmemcached, now
99
    push(memcached_server_name(serv, servers[report->most_consumed_server]));
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
100
    push(report->most_used_bytes);
1452.2.5 by Monty Taylor
Fixed the memcached_stats plugin to work with the latest libmemcached, now
101
    push(memcached_server_name(serv, servers[report->least_free_server]));
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
102
    push(report->least_remaining_bytes);
1452.2.5 by Monty Taylor
Fixed the memcached_stats plugin to work with the latest libmemcached, now
103
    push(memcached_server_name(serv, servers[report->oldest_server]));
1368 by Brian Aker
Fix build issues, disabled tests (someone needs to go through them... who is
104
    push(static_cast<uint64_t>(report->longest_uptime));
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
105
    push(static_cast<int64_t>(report->pool_hit_ratio));
1144.5.9 by Padraig O'Sullivan
Added a test suite for the memcached stats I_S tables. The test suite is
106
    free(report);
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
107
  } 
1144.5.3 by Padraig O'Sullivan
Added support for system variables to set the memcached servers whose
108
109
  memcached_stat_free(serv, stats);
110
  memcached_free(serv);
1300.2.2 by Joe Daly
port memcached stats plugin to use data_dictionary
111
112
  return true;
113
}
1964.2.8 by Monty Taylor
Updated memcached_stats plugin.
114
115
} /* namespace drizzle_plugin */