~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/logging_stats.cc

  • Committer: patrick crews
  • Date: 2011-06-08 03:02:27 UTC
  • mto: This revision was merged to the branch mainline in revision 2329.
  • Revision ID: gleebix@gmail.com-20110608030227-updkyv2652zvfajc
Initial voodoo worked to give us a crashme mode.  Need docs still

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2010, Joseph Daly <skinny.moey@gmail.com>
 
2
 * Copyright (C) 2010 Joseph Daly <skinny.moey@gmail.com>
3
3
 * All rights reserved.
4
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
84
84
 * 
85
85
 */
86
86
 
87
 
#include "config.h"
 
87
#include <config.h>
88
88
#include "user_commands.h"
89
89
#include "status_vars.h"
90
90
#include "global_stats.h"
94
94
#include <boost/program_options.hpp>
95
95
#include <drizzled/module/option_map.h>
96
96
#include <drizzled/session.h>
 
97
#include <drizzled/session/times.h>
 
98
#include <drizzled/sql_lex.h>
 
99
#include <drizzled/statistics_variables.h>
97
100
 
98
101
namespace po= boost::program_options;
99
102
using namespace drizzled;
128
131
void LoggingStats::updateCurrentScoreboard(ScoreboardSlot *scoreboard_slot,
129
132
                                           Session *session)
130
133
{
131
 
  enum_sql_command sql_command= session->lex->sql_command;
 
134
  enum_sql_command sql_command= session->lex().sql_command;
132
135
 
133
136
  scoreboard_slot->getUserCommands()->logCommand(sql_command);
134
137
 
210
213
       the scoreboard would be filled up quickly with invalid users. 
211
214
    */
212
215
    scoreboard_slot= new ScoreboardSlot();
213
 
    scoreboard_slot->setUser(session->getSecurityContext().getUser());
214
 
    scoreboard_slot->setIp(session->getSecurityContext().getIp());
 
216
    scoreboard_slot->setUser(session->user()->username());
 
217
    scoreboard_slot->setIp(session->user()->address());
215
218
  }
216
219
 
217
220
  scoreboard_slot->getStatusVars()->logStatusVar(session);
218
 
  scoreboard_slot->getStatusVars()->getStatusVarCounters()->connection_time= time(NULL) - session->start_time; 
 
221
  boost::posix_time::ptime end(boost::posix_time::microsec_clock::universal_time());
 
222
  uint64_t end_time= (end - session->times.epoch()).total_seconds();
 
223
  scoreboard_slot->getStatusVars()->getStatusVarCounters()->connection_time= end_time - session->times.getConnectSeconds();
219
224
 
220
225
  cumulative_stats->logUserStats(scoreboard_slot, isInScoreboard);
221
226
  cumulative_stats->logGlobalStats(scoreboard_slot);
268
273
  }
269
274
}
270
275
 
271
 
static bool initTable()
272
 
{
273
 
  current_commands_tool= new(nothrow)CurrentCommandsTool(logging_stats);
274
 
 
275
 
  if (! current_commands_tool)
276
 
  {
277
 
    return true;
278
 
  }
279
 
 
280
 
  cumulative_commands_tool= new(nothrow)CumulativeCommandsTool(logging_stats);
281
 
 
282
 
  if (! cumulative_commands_tool)
283
 
  {
284
 
    return true;
285
 
  }
286
 
 
287
 
  global_statements_tool= new(nothrow)GlobalStatementsTool(logging_stats);
288
 
 
289
 
  if (! global_statements_tool)
290
 
  {
291
 
    return true;
292
 
  }
293
 
 
294
 
  session_statements_tool= new(nothrow)SessionStatementsTool(logging_stats);
295
 
 
296
 
  if (! session_statements_tool)
297
 
  {
298
 
    return true;
299
 
  }
300
 
 
301
 
  session_status_tool= new(nothrow)StatusTool(logging_stats, true);
302
 
 
303
 
  if (! session_status_tool)
304
 
  {
305
 
    return true;
306
 
  }
307
 
 
308
 
  global_status_tool= new(nothrow)StatusTool(logging_stats, false);
309
 
 
310
 
  if (! global_status_tool)
311
 
  {
312
 
    return true;
313
 
  }
314
 
 
315
 
  cumulative_user_stats_tool= new(nothrow)CumulativeUserStatsTool(logging_stats);
316
 
 
317
 
  if (! cumulative_user_stats_tool)
318
 
  {
319
 
    return true;
320
 
  }
321
 
 
322
 
  scoreboard_stats_tool= new(nothrow)ScoreboardStatsTool(logging_stats);
323
 
  
324
 
  if (! scoreboard_stats_tool)
325
 
  {
326
 
    return true;
327
 
  }
328
 
 
329
 
  return false;
330
 
}
331
 
 
332
276
static int init(drizzled::module::Context &context)
333
277
{
334
278
  const module::option_map &vm= context.getOptions();
335
 
 
336
 
  sysvar_logging_stats_enabled= (vm.count("disable")) ? false : true;
 
279
  sysvar_logging_stats_enabled= not vm.count("disable");
337
280
 
338
281
  logging_stats= new LoggingStats("logging_stats");
339
 
 
340
 
  if (initTable())
341
 
  {
342
 
    return 1;
343
 
  }
 
282
  current_commands_tool= new CurrentCommandsTool(logging_stats);
 
283
  cumulative_commands_tool= new CumulativeCommandsTool(logging_stats);
 
284
  global_statements_tool= new GlobalStatementsTool(logging_stats);
 
285
  session_statements_tool= new SessionStatementsTool(logging_stats);
 
286
  session_status_tool= new StatusTool(logging_stats, true);
 
287
  global_status_tool= new StatusTool(logging_stats, false);
 
288
  cumulative_user_stats_tool= new CumulativeUserStatsTool(logging_stats);
 
289
  scoreboard_stats_tool= new ScoreboardStatsTool(logging_stats);
344
290
 
345
291
  context.add(logging_stats);
346
292
  context.add(current_commands_tool);
353
299
  context.add(scoreboard_stats_tool);
354
300
 
355
301
  if (sysvar_logging_stats_enabled)
356
 
  {
357
302
    logging_stats->enable();
358
 
  }
359
303
 
360
304
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("max_user_count", sysvar_logging_stats_max_user_count));
361
305
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("bucket_count", sysvar_logging_stats_bucket_count));
370
314
{
371
315
  context("max-user-count",
372
316
          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"));
 
317
          _("Max number of users that will be logged"));
374
318
  context("bucket-count",
375
319
          po::value<bucket_count_constraint>(&sysvar_logging_stats_bucket_count)->default_value(10),
376
 
          N_("Max number of range locks to use for Scoreboard"));
 
320
          _("Max number of range locks to use for Scoreboard"));
377
321
  context("scoreboard-size",
378
322
          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"));
 
323
          _("Max number of concurrent sessions that will be logged"));
 
324
  context("disable", _("Enable Logging Statistics Collection"));
381
325
}
382
326
 
383
327
DRIZZLE_DECLARE_PLUGIN
389
333
  N_("User Statistics as DATA_DICTIONARY tables"),
390
334
  PLUGIN_LICENSE_BSD,
391
335
  init,   /* Plugin Init      */
392
 
  NULL, /* system variables */
 
336
  NULL, /* depends */
393
337
  init_options    /* config options   */
394
338
}
395
339
DRIZZLE_DECLARE_PLUGIN_END;