~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/logging_stats.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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
102
102
 
103
103
static bool sysvar_logging_stats_enabled= true;
104
104
 
105
 
static uint32_t sysvar_logging_stats_scoreboard_size= 2000;
106
 
 
107
 
static uint32_t sysvar_logging_stats_max_user_count= 500;
108
 
 
109
 
static uint32_t sysvar_logging_stats_bucket_count= 10;
 
105
typedef constrained_check<uint32_t, 50000, 10> scoreboard_size_constraint;
 
106
static scoreboard_size_constraint sysvar_logging_stats_scoreboard_size;
 
107
 
 
108
typedef constrained_check<uint32_t, 50000, 100> max_user_count_constraint;
 
109
static max_user_count_constraint sysvar_logging_stats_max_user_count;
 
110
 
 
111
typedef constrained_check<uint32_t, 500, 5> bucket_count_constraint;
 
112
static bucket_count_constraint sysvar_logging_stats_bucket_count;
110
113
 
111
114
LoggingStats::LoggingStats(string name_arg) : Logging(name_arg)
112
115
{
151
154
 
152
155
  for (; v_of_scoreboard_v_begin_it != v_of_scoreboard_v_end_it; ++v_of_scoreboard_v_begin_it)
153
156
  {
154
 
    vector<ScoreboardSlot* > *scoreboard_vector= *v_of_scoreboard_v_begin_it;
 
157
    std::vector<ScoreboardSlot* > *scoreboard_vector= *v_of_scoreboard_v_begin_it;
155
158
 
156
 
    vector<ScoreboardSlot* >::iterator scoreboard_vector_it= scoreboard_vector->begin();
157
 
    vector<ScoreboardSlot* >::iterator scoreboard_vector_end= scoreboard_vector->end();
 
159
    std::vector<ScoreboardSlot* >::iterator scoreboard_vector_it= scoreboard_vector->begin();
 
160
    std::vector<ScoreboardSlot* >::iterator scoreboard_vector_end= scoreboard_vector->end();
158
161
    for (; scoreboard_vector_it != scoreboard_vector_end; ++scoreboard_vector_it)
159
162
    {
160
163
      ScoreboardSlot *scoreboard_slot= *scoreboard_vector_it;
207
210
       the scoreboard would be filled up quickly with invalid users. 
208
211
    */
209
212
    scoreboard_slot= new ScoreboardSlot();
210
 
    scoreboard_slot->setUser(session->getSecurityContext().getUser());
211
 
    scoreboard_slot->setIp(session->getSecurityContext().getIp());
 
213
    scoreboard_slot->setUser(session->user()->username());
 
214
    scoreboard_slot->setIp(session->user()->address());
212
215
  }
213
216
 
214
217
  scoreboard_slot->getStatusVars()->logStatusVar(session);
215
 
  scoreboard_slot->getStatusVars()->getStatusVarCounters()->connection_time= time(NULL) - session->start_time; 
 
218
  scoreboard_slot->getStatusVars()->getStatusVarCounters()->connection_time= session->getConnectSeconds(); 
216
219
 
217
220
  cumulative_stats->logUserStats(scoreboard_slot, isInScoreboard);
218
221
  cumulative_stats->logGlobalStats(scoreboard_slot);
250
253
 
251
254
static ScoreboardStatsTool *scoreboard_stats_tool= NULL;
252
255
 
253
 
static void enable(Session *,
254
 
                   drizzle_sys_var *,
255
 
                   void *var_ptr,
256
 
                   const void *save)
 
256
static void enable(Session *, sql_var_t)
257
257
{
258
258
  if (logging_stats)
259
259
  {
260
 
    if (*(bool *)save != false)
 
260
    if (sysvar_logging_stats_enabled)
261
261
    {
262
262
      logging_stats->enable();
263
 
      *(bool *) var_ptr= (bool) true;
264
263
    }
265
264
    else
266
265
    {
267
266
      logging_stats->disable();
268
 
      *(bool *) var_ptr= (bool) false;
269
267
    }
270
268
  }
271
269
}
337
335
 
338
336
  sysvar_logging_stats_enabled= (vm.count("disable")) ? false : true;
339
337
 
340
 
  if (vm.count("max-user-count"))
341
 
  {
342
 
    if (sysvar_logging_stats_max_user_count < 100 || sysvar_logging_stats_max_user_count > 50000)
343
 
    {
344
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for max-user-count\n"));
345
 
      return 1;
346
 
    }
347
 
  }
348
 
  if (vm.count("bucket-count"))
349
 
  {
350
 
    if (sysvar_logging_stats_bucket_count < 5 || sysvar_logging_stats_bucket_count > 500)
351
 
    {
352
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for bucket-count\n"));
353
 
      return 1;
354
 
    }
355
 
  }
356
 
 
357
 
  if (vm.count("scoreboard-size"))
358
 
  {
359
 
    if (sysvar_logging_stats_scoreboard_size < 10 || sysvar_logging_stats_scoreboard_size > 50000)
360
 
    {
361
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for scoreboard-size\n"));
362
 
      return 1;
363
 
    }
364
 
    else
365
 
      sysvar_logging_stats_scoreboard_size= vm["scoreboard-size"].as<uint32_t>(); 
366
 
  }
367
 
 
368
338
  logging_stats= new LoggingStats("logging_stats");
369
339
 
370
340
  if (initTable())
387
357
    logging_stats->enable();
388
358
  }
389
359
 
 
360
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("max_user_count", sysvar_logging_stats_max_user_count));
 
361
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("bucket_count", sysvar_logging_stats_bucket_count));
 
362
  context.registerVariable(new sys_var_constrained_value_readonly<uint32_t>("scoreboard_size", sysvar_logging_stats_scoreboard_size));
 
363
  context.registerVariable(new sys_var_bool_ptr("enable", &sysvar_logging_stats_enabled, enable));
 
364
 
390
365
  return 0;
391
366
}
392
367
 
393
 
static DRIZZLE_SYSVAR_UINT(max_user_count,
394
 
                           sysvar_logging_stats_max_user_count,
395
 
                           PLUGIN_VAR_RQCMDARG,
396
 
                           N_("Max number of users that will be logged"),
397
 
                           NULL, /* check func */
398
 
                           NULL, /* update func */
399
 
                           500, /* default */
400
 
                           100, /* minimum */
401
 
                           50000,
402
 
                           0);
403
 
 
404
 
static DRIZZLE_SYSVAR_UINT(bucket_count,
405
 
                           sysvar_logging_stats_bucket_count,
406
 
                           PLUGIN_VAR_RQCMDARG,
407
 
                           N_("Max number of range locks to use for Scoreboard"),
408
 
                           NULL, /* check func */
409
 
                           NULL, /* update func */
410
 
                           10, /* default */
411
 
                           5, /* minimum */
412
 
                           500,
413
 
                           0);
414
 
 
415
 
static DRIZZLE_SYSVAR_UINT(scoreboard_size,
416
 
                           sysvar_logging_stats_scoreboard_size,
417
 
                           PLUGIN_VAR_RQCMDARG,
418
 
                           N_("Max number of concurrent sessions that will be logged"),
419
 
                           NULL, /* check func */
420
 
                           NULL, /* update func */
421
 
                           2000, /* default */
422
 
                           10, /* minimum */
423
 
                           50000, 
424
 
                           0);
425
 
 
426
 
static DRIZZLE_SYSVAR_BOOL(enable,
427
 
                           sysvar_logging_stats_enabled,
428
 
                           PLUGIN_VAR_NOCMDARG,
429
 
                           N_("Enable Logging Statistics Collection"),
430
 
                           NULL, /* check func */
431
 
                           enable, /* update func */
432
 
                           true /* default */);
433
368
 
434
369
static void init_options(drizzled::module::option_context &context)
435
370
{
436
371
  context("max-user-count",
437
 
          po::value<uint32_t>(&sysvar_logging_stats_max_user_count)->default_value(500),
438
 
          N_("Max number of users that will be logged"));
 
372
          po::value<max_user_count_constraint>(&sysvar_logging_stats_max_user_count)->default_value(500),
 
373
          _("Max number of users that will be logged"));
439
374
  context("bucket-count",
440
 
          po::value<uint32_t>(&sysvar_logging_stats_bucket_count)->default_value(10),
441
 
          N_("Max number of range locks to use for Scoreboard"));
 
375
          po::value<bucket_count_constraint>(&sysvar_logging_stats_bucket_count)->default_value(10),
 
376
          _("Max number of range locks to use for Scoreboard"));
442
377
  context("scoreboard-size",
443
 
          po::value<uint32_t>(&sysvar_logging_stats_scoreboard_size)->default_value(2000),
444
 
          N_("Max number of concurrent sessions that will be logged"));
445
 
  context("disable", N_("Enable Logging Statistics Collection"));
 
378
          po::value<scoreboard_size_constraint>(&sysvar_logging_stats_scoreboard_size)->default_value(2000),
 
379
          _("Max number of concurrent sessions that will be logged"));
 
380
  context("disable", _("Enable Logging Statistics Collection"));
446
381
}
447
382
 
448
 
static drizzle_sys_var* system_var[]= {
449
 
  DRIZZLE_SYSVAR(max_user_count),
450
 
  DRIZZLE_SYSVAR(bucket_count),
451
 
  DRIZZLE_SYSVAR(scoreboard_size),
452
 
  DRIZZLE_SYSVAR(enable),
453
 
  NULL
454
 
};
455
 
 
456
383
DRIZZLE_DECLARE_PLUGIN
457
384
{
458
385
  DRIZZLE_VERSION_ID,
462
389
  N_("User Statistics as DATA_DICTIONARY tables"),
463
390
  PLUGIN_LICENSE_BSD,
464
391
  init,   /* Plugin Init      */
465
 
  system_var, /* system variables */
 
392
  NULL, /* depends */
466
393
  init_options    /* config options   */
467
394
}
468
395
DRIZZLE_DECLARE_PLUGIN_END;