94
94
#include <boost/program_options.hpp>
95
95
#include <drizzled/module/option_map.h>
96
96
#include <drizzled/session.h>
97
#include <drizzled/sql_lex.h>
98
#include <drizzled/statistics_variables.h>
98
100
namespace po= boost::program_options;
99
101
using namespace drizzled;
128
130
void LoggingStats::updateCurrentScoreboard(ScoreboardSlot *scoreboard_slot,
129
131
Session *session)
131
enum_sql_command sql_command= session->lex->sql_command;
133
enum_sql_command sql_command= session->lex().sql_command;
133
135
scoreboard_slot->getUserCommands()->logCommand(sql_command);
217
219
scoreboard_slot->getStatusVars()->logStatusVar(session);
218
scoreboard_slot->getStatusVars()->getStatusVarCounters()->connection_time= time(NULL) - session->start_time;
220
scoreboard_slot->getStatusVars()->getStatusVarCounters()->connection_time= session->getConnectSeconds();
220
222
cumulative_stats->logUserStats(scoreboard_slot, isInScoreboard);
221
223
cumulative_stats->logGlobalStats(scoreboard_slot);
271
static bool initTable()
273
current_commands_tool= new(nothrow)CurrentCommandsTool(logging_stats);
275
if (! current_commands_tool)
280
cumulative_commands_tool= new(nothrow)CumulativeCommandsTool(logging_stats);
282
if (! cumulative_commands_tool)
287
global_statements_tool= new(nothrow)GlobalStatementsTool(logging_stats);
289
if (! global_statements_tool)
294
session_statements_tool= new(nothrow)SessionStatementsTool(logging_stats);
296
if (! session_statements_tool)
301
session_status_tool= new(nothrow)StatusTool(logging_stats, true);
303
if (! session_status_tool)
308
global_status_tool= new(nothrow)StatusTool(logging_stats, false);
310
if (! global_status_tool)
315
cumulative_user_stats_tool= new(nothrow)CumulativeUserStatsTool(logging_stats);
317
if (! cumulative_user_stats_tool)
322
scoreboard_stats_tool= new(nothrow)ScoreboardStatsTool(logging_stats);
324
if (! scoreboard_stats_tool)
332
273
static int init(drizzled::module::Context &context)
334
275
const module::option_map &vm= context.getOptions();
336
sysvar_logging_stats_enabled= (vm.count("disable")) ? false : true;
276
sysvar_logging_stats_enabled= not vm.count("disable");
338
278
logging_stats= new LoggingStats("logging_stats");
279
current_commands_tool= new CurrentCommandsTool(logging_stats);
280
cumulative_commands_tool= new CumulativeCommandsTool(logging_stats);
281
global_statements_tool= new GlobalStatementsTool(logging_stats);
282
session_statements_tool= new SessionStatementsTool(logging_stats);
283
session_status_tool= new StatusTool(logging_stats, true);
284
global_status_tool= new StatusTool(logging_stats, false);
285
cumulative_user_stats_tool= new CumulativeUserStatsTool(logging_stats);
286
scoreboard_stats_tool= new ScoreboardStatsTool(logging_stats);
345
288
context.add(logging_stats);
346
289
context.add(current_commands_tool);
353
296
context.add(scoreboard_stats_tool);
355
298
if (sysvar_logging_stats_enabled)
357
299
logging_stats->enable();
360
301
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("max_user_count", sysvar_logging_stats_max_user_count));
361
302
context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("bucket_count", sysvar_logging_stats_bucket_count));
371
312
context("max-user-count",
372
313
po::value<max_user_count_constraint>(&sysvar_logging_stats_max_user_count)->default_value(500),
373
N_("Max number of users that will be logged"));
314
_("Max number of users that will be logged"));
374
315
context("bucket-count",
375
316
po::value<bucket_count_constraint>(&sysvar_logging_stats_bucket_count)->default_value(10),
376
N_("Max number of range locks to use for Scoreboard"));
317
_("Max number of range locks to use for Scoreboard"));
377
318
context("scoreboard-size",
378
319
po::value<scoreboard_size_constraint>(&sysvar_logging_stats_scoreboard_size)->default_value(2000),
379
N_("Max number of concurrent sessions that will be logged"));
380
context("disable", N_("Enable Logging Statistics Collection"));
320
_("Max number of concurrent sessions that will be logged"));
321
context("disable", _("Enable Logging Statistics Collection"));
383
324
DRIZZLE_DECLARE_PLUGIN
389
330
N_("User Statistics as DATA_DICTIONARY tables"),
390
331
PLUGIN_LICENSE_BSD,
391
332
init, /* Plugin Init */
392
NULL, /* system variables */
393
334
init_options /* config options */
395
336
DRIZZLE_DECLARE_PLUGIN_END;