~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/logging_stats.cc

  • Committer: Monty Taylor
  • Date: 2010-11-24 19:33:25 UTC
  • mto: (1953.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1955.
  • Revision ID: mordred@inaugust.com-20101124193325-7rxjg5jwto3lfms9
protobuf requires pthread. It's just the way it is.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
 
103
103
static bool sysvar_logging_stats_enabled= true;
104
104
 
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;
 
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;
113
110
 
114
111
LoggingStats::LoggingStats(string name_arg) : Logging(name_arg)
115
112
{
154
151
 
155
152
  for (; v_of_scoreboard_v_begin_it != v_of_scoreboard_v_end_it; ++v_of_scoreboard_v_begin_it)
156
153
  {
157
 
    std::vector<ScoreboardSlot* > *scoreboard_vector= *v_of_scoreboard_v_begin_it;
 
154
    vector<ScoreboardSlot* > *scoreboard_vector= *v_of_scoreboard_v_begin_it;
158
155
 
159
 
    std::vector<ScoreboardSlot* >::iterator scoreboard_vector_it= scoreboard_vector->begin();
160
 
    std::vector<ScoreboardSlot* >::iterator scoreboard_vector_end= scoreboard_vector->end();
 
156
    vector<ScoreboardSlot* >::iterator scoreboard_vector_it= scoreboard_vector->begin();
 
157
    vector<ScoreboardSlot* >::iterator scoreboard_vector_end= scoreboard_vector->end();
161
158
    for (; scoreboard_vector_it != scoreboard_vector_end; ++scoreboard_vector_it)
162
159
    {
163
160
      ScoreboardSlot *scoreboard_slot= *scoreboard_vector_it;
210
207
       the scoreboard would be filled up quickly with invalid users. 
211
208
    */
212
209
    scoreboard_slot= new ScoreboardSlot();
213
 
    scoreboard_slot->setUser(session->user()->username());
214
 
    scoreboard_slot->setIp(session->user()->address());
 
210
    scoreboard_slot->setUser(session->getSecurityContext().getUser());
 
211
    scoreboard_slot->setIp(session->getSecurityContext().getIp());
215
212
  }
216
213
 
217
214
  scoreboard_slot->getStatusVars()->logStatusVar(session);
253
250
 
254
251
static ScoreboardStatsTool *scoreboard_stats_tool= NULL;
255
252
 
256
 
static void enable(Session *, sql_var_t)
 
253
static void enable(Session *,
 
254
                   drizzle_sys_var *,
 
255
                   void *var_ptr,
 
256
                   const void *save)
257
257
{
258
258
  if (logging_stats)
259
259
  {
260
 
    if (sysvar_logging_stats_enabled)
 
260
    if (*(bool *)save != false)
261
261
    {
262
262
      logging_stats->enable();
 
263
      *(bool *) var_ptr= (bool) true;
263
264
    }
264
265
    else
265
266
    {
266
267
      logging_stats->disable();
 
268
      *(bool *) var_ptr= (bool) false;
267
269
    }
268
270
  }
269
271
}
335
337
 
336
338
  sysvar_logging_stats_enabled= (vm.count("disable")) ? false : true;
337
339
 
 
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
 
338
368
  logging_stats= new LoggingStats("logging_stats");
339
369
 
340
370
  if (initTable())
357
387
    logging_stats->enable();
358
388
  }
359
389
 
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
 
 
365
390
  return 0;
366
391
}
367
392
 
 
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 */);
368
433
 
369
434
static void init_options(drizzled::module::option_context &context)
370
435
{
371
436
  context("max-user-count",
372
 
          po::value<max_user_count_constraint>(&sysvar_logging_stats_max_user_count)->default_value(500),
 
437
          po::value<uint32_t>(&sysvar_logging_stats_max_user_count)->default_value(500),
373
438
          N_("Max number of users that will be logged"));
374
439
  context("bucket-count",
375
 
          po::value<bucket_count_constraint>(&sysvar_logging_stats_bucket_count)->default_value(10),
 
440
          po::value<uint32_t>(&sysvar_logging_stats_bucket_count)->default_value(10),
376
441
          N_("Max number of range locks to use for Scoreboard"));
377
442
  context("scoreboard-size",
378
 
          po::value<scoreboard_size_constraint>(&sysvar_logging_stats_scoreboard_size)->default_value(2000),
 
443
          po::value<uint32_t>(&sysvar_logging_stats_scoreboard_size)->default_value(2000),
379
444
          N_("Max number of concurrent sessions that will be logged"));
380
445
  context("disable", N_("Enable Logging Statistics Collection"));
381
446
}
382
447
 
 
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
 
383
456
DRIZZLE_DECLARE_PLUGIN
384
457
{
385
458
  DRIZZLE_VERSION_ID,
389
462
  N_("User Statistics as DATA_DICTIONARY tables"),
390
463
  PLUGIN_LICENSE_BSD,
391
464
  init,   /* Plugin Init      */
392
 
  NULL, /* system variables */
 
465
  system_var, /* system variables */
393
466
  init_options    /* config options   */
394
467
}
395
468
DRIZZLE_DECLARE_PLUGIN_END;