~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_stats/logging_stats.cc

  • Committer: patrick crews
  • Date: 2010-09-29 15:15:19 UTC
  • mfrom: (1099.4.188 drizzle)
  • Revision ID: gleebix@gmail.com-20100929151519-6mrmzd1ciw2p9nws
Tags: 2010.09.1802
Update translations

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
 
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
{
140
137
  scoreboard_slot->getStatusVars()->logStatusVar(session);
141
138
}
142
139
 
143
 
bool LoggingStats::resetGlobalScoreboard()
144
 
{
145
 
  cumulative_stats->getGlobalStatusVars()->reset();
146
 
  cumulative_stats->getGlobalStats()->getUserCommands()->reset();
147
 
 
148
 
  ScoreBoardVectors *vector_of_scoreboard_vectors=
149
 
    current_scoreboard->getVectorOfScoreboardVectors();
150
 
 
151
 
  ScoreBoardVectors::iterator v_of_scoreboard_v_begin_it= vector_of_scoreboard_vectors->begin();
152
 
 
153
 
  ScoreBoardVectors::iterator v_of_scoreboard_v_end_it= vector_of_scoreboard_vectors->end();
154
 
 
155
 
  for (; v_of_scoreboard_v_begin_it != v_of_scoreboard_v_end_it; ++v_of_scoreboard_v_begin_it)
156
 
  {
157
 
    std::vector<ScoreboardSlot* > *scoreboard_vector= *v_of_scoreboard_v_begin_it;
158
 
 
159
 
    std::vector<ScoreboardSlot* >::iterator scoreboard_vector_it= scoreboard_vector->begin();
160
 
    std::vector<ScoreboardSlot* >::iterator scoreboard_vector_end= scoreboard_vector->end();
161
 
    for (; scoreboard_vector_it != scoreboard_vector_end; ++scoreboard_vector_it)
162
 
    {
163
 
      ScoreboardSlot *scoreboard_slot= *scoreboard_vector_it;
164
 
      scoreboard_slot->getStatusVars()->reset();
165
 
      scoreboard_slot->getUserCommands()->reset();
166
 
    }
167
 
  }
168
 
 
169
 
  return false;
170
 
}
171
 
 
172
140
bool LoggingStats::post(Session *session)
173
141
{
174
142
  if (! isEnabled() || (session->getSessionId() == 0))
210
178
       the scoreboard would be filled up quickly with invalid users. 
211
179
    */
212
180
    scoreboard_slot= new ScoreboardSlot();
213
 
    scoreboard_slot->setUser(session->user()->username());
214
 
    scoreboard_slot->setIp(session->user()->address());
 
181
    scoreboard_slot->setUser(session->getSecurityContext().getUser());
 
182
    scoreboard_slot->setIp(session->getSecurityContext().getIp());
215
183
  }
216
184
 
217
185
  scoreboard_slot->getStatusVars()->logStatusVar(session);
218
 
  scoreboard_slot->getStatusVars()->getStatusVarCounters()->connection_time= session->getConnectSeconds(); 
 
186
  scoreboard_slot->getStatusVars()->getStatusVarCounters()->connection_time= time(NULL) - session->start_time; 
219
187
 
220
188
  cumulative_stats->logUserStats(scoreboard_slot, isInScoreboard);
221
189
  cumulative_stats->logGlobalStats(scoreboard_slot);
253
221
 
254
222
static ScoreboardStatsTool *scoreboard_stats_tool= NULL;
255
223
 
256
 
static void enable(Session *, sql_var_t)
 
224
static void enable(Session *,
 
225
                   drizzle_sys_var *,
 
226
                   void *var_ptr,
 
227
                   const void *save)
257
228
{
258
229
  if (logging_stats)
259
230
  {
260
 
    if (sysvar_logging_stats_enabled)
 
231
    if (*(bool *)save != false)
261
232
    {
262
233
      logging_stats->enable();
 
234
      *(bool *) var_ptr= (bool) true;
263
235
    }
264
236
    else
265
237
    {
266
238
      logging_stats->disable();
 
239
      *(bool *) var_ptr= (bool) false;
267
240
    }
268
241
  }
269
242
}
335
308
 
336
309
  sysvar_logging_stats_enabled= (vm.count("disable")) ? false : true;
337
310
 
 
311
  if (vm.count("max-user-count"))
 
312
  {
 
313
    if (sysvar_logging_stats_max_user_count < 100 || sysvar_logging_stats_max_user_count > 50000)
 
314
    {
 
315
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for max-user-count\n"));
 
316
      exit(-1);
 
317
    }
 
318
  }
 
319
  if (vm.count("bucket-count"))
 
320
  {
 
321
    if (sysvar_logging_stats_bucket_count < 5 || sysvar_logging_stats_bucket_count > 500)
 
322
    {
 
323
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for bucket-count\n"));
 
324
      exit(-1);
 
325
    }
 
326
  }
 
327
 
 
328
  if (vm.count("scoreboard-size"))
 
329
  {
 
330
    if (sysvar_logging_stats_scoreboard_size < 10 || sysvar_logging_stats_scoreboard_size > 50000)
 
331
    {
 
332
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for scoreboard-size\n"));
 
333
      exit(-1);
 
334
    }
 
335
    else
 
336
      sysvar_logging_stats_scoreboard_size= vm["scoreboard-size"].as<uint32_t>(); 
 
337
  }
 
338
 
338
339
  logging_stats= new LoggingStats("logging_stats");
339
340
 
340
341
  if (initTable())
357
358
    logging_stats->enable();
358
359
  }
359
360
 
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
361
  return 0;
366
362
}
367
363
 
 
364
static DRIZZLE_SYSVAR_UINT(max_user_count,
 
365
                           sysvar_logging_stats_max_user_count,
 
366
                           PLUGIN_VAR_RQCMDARG,
 
367
                           N_("Max number of users that will be logged"),
 
368
                           NULL, /* check func */
 
369
                           NULL, /* update func */
 
370
                           500, /* default */
 
371
                           100, /* minimum */
 
372
                           50000,
 
373
                           0);
 
374
 
 
375
static DRIZZLE_SYSVAR_UINT(bucket_count,
 
376
                           sysvar_logging_stats_bucket_count,
 
377
                           PLUGIN_VAR_RQCMDARG,
 
378
                           N_("Max number of range locks to use for Scoreboard"),
 
379
                           NULL, /* check func */
 
380
                           NULL, /* update func */
 
381
                           10, /* default */
 
382
                           5, /* minimum */
 
383
                           500,
 
384
                           0);
 
385
 
 
386
static DRIZZLE_SYSVAR_UINT(scoreboard_size,
 
387
                           sysvar_logging_stats_scoreboard_size,
 
388
                           PLUGIN_VAR_RQCMDARG,
 
389
                           N_("Max number of concurrent sessions that will be logged"),
 
390
                           NULL, /* check func */
 
391
                           NULL, /* update func */
 
392
                           2000, /* default */
 
393
                           10, /* minimum */
 
394
                           50000, 
 
395
                           0);
 
396
 
 
397
static DRIZZLE_SYSVAR_BOOL(enable,
 
398
                           sysvar_logging_stats_enabled,
 
399
                           PLUGIN_VAR_NOCMDARG,
 
400
                           N_("Enable Logging Statistics Collection"),
 
401
                           NULL, /* check func */
 
402
                           enable, /* update func */
 
403
                           true /* default */);
368
404
 
369
405
static void init_options(drizzled::module::option_context &context)
370
406
{
371
407
  context("max-user-count",
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"));
 
408
          po::value<uint32_t>(&sysvar_logging_stats_max_user_count)->default_value(500),
 
409
          N_("Max number of users that will be logged"));
374
410
  context("bucket-count",
375
 
          po::value<bucket_count_constraint>(&sysvar_logging_stats_bucket_count)->default_value(10),
376
 
          _("Max number of range locks to use for Scoreboard"));
 
411
          po::value<uint32_t>(&sysvar_logging_stats_bucket_count)->default_value(10),
 
412
          N_("Max number of range locks to use for Scoreboard"));
377
413
  context("scoreboard-size",
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"));
 
414
          po::value<uint32_t>(&sysvar_logging_stats_scoreboard_size)->default_value(2000),
 
415
          N_("Max number of concurrent sessions that will be logged"));
 
416
  context("disable", N_("Enable Logging Statistics Collection"));
381
417
}
382
418
 
 
419
static drizzle_sys_var* system_var[]= {
 
420
  DRIZZLE_SYSVAR(max_user_count),
 
421
  DRIZZLE_SYSVAR(bucket_count),
 
422
  DRIZZLE_SYSVAR(scoreboard_size),
 
423
  DRIZZLE_SYSVAR(enable),
 
424
  NULL
 
425
};
 
426
 
383
427
DRIZZLE_DECLARE_PLUGIN
384
428
{
385
429
  DRIZZLE_VERSION_ID,
389
433
  N_("User Statistics as DATA_DICTIONARY tables"),
390
434
  PLUGIN_LICENSE_BSD,
391
435
  init,   /* Plugin Init      */
392
 
  NULL, /* depends */
 
436
  system_var, /* system variables */
393
437
  init_options    /* config options   */
394
438
}
395
439
DRIZZLE_DECLARE_PLUGIN_END;