00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00106 #include <config.h>
00107
00108 #include "stats_schema.h"
00109
00110 #include <sstream>
00111
00112 using namespace drizzled;
00113 using namespace plugin;
00114 using namespace std;
00115
00116 SessionStatementsTool::SessionStatementsTool(LoggingStats *in_logging_stats) :
00117 plugin::TableFunction("DATA_DICTIONARY", "SESSION_STATEMENTS")
00118 {
00119 logging_stats= in_logging_stats;
00120 add_field("VARIABLE_NAME");
00121 add_field("VARIABLE_VALUE", 1024);
00122 }
00123
00124 SessionStatementsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
00125 plugin::TableFunction::Generator(arg)
00126 {
00127 count= 0;
00128
00129
00130 Scoreboard *current_scoreboard= in_logging_stats->getCurrentScoreboard();
00131
00132 uint32_t bucket_number= current_scoreboard->getBucketNumber(&getSession());
00133
00134 std::vector<ScoreboardSlot* > *scoreboard_vector=
00135 current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number);
00136
00137 std::vector<ScoreboardSlot *>::iterator scoreboard_vector_it= scoreboard_vector->begin();
00138 std::vector<ScoreboardSlot *>::iterator scoreboard_vector_end= scoreboard_vector->end();
00139
00140 ScoreboardSlot *scoreboard_slot= NULL;
00141 for (std::vector<ScoreboardSlot *>::iterator it= scoreboard_vector->begin();
00142 it != scoreboard_vector->end(); ++it)
00143 {
00144 scoreboard_slot= *it;
00145 if (scoreboard_slot->getSessionId() == getSession().getSessionId())
00146 {
00147 break;
00148 }
00149 }
00150
00151 user_commands= NULL;
00152
00153 if (scoreboard_slot != NULL)
00154 {
00155 user_commands= scoreboard_slot->getUserCommands();
00156 }
00157 }
00158
00159 bool SessionStatementsTool::Generator::populate()
00160 {
00161 if (user_commands == NULL)
00162 {
00163 return false;
00164 }
00165
00166 uint32_t number_identifiers= UserCommands::getStatusVarsCount();
00167
00168 if (count == number_identifiers)
00169 {
00170 return false;
00171 }
00172
00173 push(UserCommands::COM_STATUS_VARS[count]);
00174 ostringstream oss;
00175 oss << user_commands->getCount(count);
00176 push(oss.str());
00177
00178 ++count;
00179 return true;
00180 }
00181
00182 GlobalStatementsTool::GlobalStatementsTool(LoggingStats *in_logging_stats) :
00183 plugin::TableFunction("DATA_DICTIONARY", "GLOBAL_STATEMENTS")
00184 {
00185 logging_stats= in_logging_stats;
00186 add_field("VARIABLE_NAME");
00187 add_field("VARIABLE_VALUE", 1024);
00188 }
00189
00190 GlobalStatementsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
00191 plugin::TableFunction::Generator(arg)
00192 {
00193 count= 0;
00194
00195 global_stats_to_display= new GlobalStats();
00196 CumulativeStats *cumulativeStats= in_logging_stats->getCumulativeStats();
00197 cumulativeStats->sumCurrentScoreboard(in_logging_stats->getCurrentScoreboard(),
00198 NULL, global_stats_to_display->getUserCommands());
00199 global_stats_to_display->merge(in_logging_stats->getCumulativeStats()->getGlobalStats());
00200 }
00201
00202 GlobalStatementsTool::Generator::~Generator()
00203 {
00204 delete global_stats_to_display;
00205 }
00206
00207 bool GlobalStatementsTool::Generator::populate()
00208 {
00209 uint32_t number_identifiers= UserCommands::getStatusVarsCount();
00210 if (count == number_identifiers)
00211 {
00212 return false;
00213 }
00214
00215 push(UserCommands::COM_STATUS_VARS[count]);
00216 ostringstream oss;
00217 oss << global_stats_to_display->getUserCommands()->getCount(count);
00218 push(oss.str());
00219
00220 ++count;
00221 return true;
00222 }
00223
00224 CurrentCommandsTool::CurrentCommandsTool(LoggingStats *logging_stats) :
00225 plugin::TableFunction("DATA_DICTIONARY", "CURRENT_SQL_COMMANDS")
00226 {
00227 outer_logging_stats= logging_stats;
00228
00229 add_field("USERNAME");
00230 add_field("IP");
00231
00232 uint32_t number_commands= UserCommands::getUserCounts();
00233
00234 for (uint32_t j= 0; j < number_commands; ++j)
00235 {
00236 add_field(UserCommands::USER_COUNTS[j], TableFunction::NUMBER);
00237 }
00238 }
00239
00240 CurrentCommandsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
00241 plugin::TableFunction::Generator(arg)
00242 {
00243 inner_logging_stats= logging_stats;
00244
00245 isEnabled= inner_logging_stats->isEnabled();
00246
00247 if (isEnabled == false)
00248 {
00249 return;
00250 }
00251
00252 current_scoreboard= logging_stats->getCurrentScoreboard();
00253 current_bucket= 0;
00254
00255 vector_of_scoreboard_vectors_it= current_scoreboard->getVectorOfScoreboardVectors()->begin();
00256 vector_of_scoreboard_vectors_end= current_scoreboard->getVectorOfScoreboardVectors()->end();
00257
00258 setVectorIteratorsAndLock(current_bucket);
00259 }
00260
00261 void CurrentCommandsTool::Generator::setVectorIteratorsAndLock(uint32_t bucket_number)
00262 {
00263 std::vector<ScoreboardSlot* > *scoreboard_vector=
00264 current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number);
00265
00266 current_lock= current_scoreboard->getVectorOfScoreboardLocks()->at(bucket_number);
00267
00268 scoreboard_vector_it= scoreboard_vector->begin();
00269 scoreboard_vector_end= scoreboard_vector->end();
00270 current_lock->lock_shared();
00271 }
00272
00273 bool CurrentCommandsTool::Generator::populate()
00274 {
00275 if (isEnabled == false)
00276 {
00277 return false;
00278 }
00279
00280 while (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
00281 {
00282 while (scoreboard_vector_it != scoreboard_vector_end)
00283 {
00284 ScoreboardSlot *scoreboard_slot= *scoreboard_vector_it;
00285 if (scoreboard_slot->isInUse())
00286 {
00287 UserCommands *user_commands= scoreboard_slot->getUserCommands();
00288 push(scoreboard_slot->getUser());
00289 push(scoreboard_slot->getIp());
00290
00291 uint32_t number_commands= UserCommands::getUserCounts();
00292
00293 for (uint32_t j= 0; j < number_commands; ++j)
00294 {
00295 push(user_commands->getUserCount(j));
00296 }
00297
00298 ++scoreboard_vector_it;
00299 return true;
00300 }
00301 ++scoreboard_vector_it;
00302 }
00303
00304 ++vector_of_scoreboard_vectors_it;
00305 current_lock->unlock_shared();
00306 ++current_bucket;
00307 if (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
00308 {
00309 setVectorIteratorsAndLock(current_bucket);
00310 }
00311 }
00312
00313 return false;
00314 }
00315
00316 CumulativeCommandsTool::CumulativeCommandsTool(LoggingStats *logging_stats) :
00317 plugin::TableFunction("DATA_DICTIONARY", "CUMULATIVE_SQL_COMMANDS")
00318 {
00319 outer_logging_stats= logging_stats;
00320
00321 add_field("USERNAME");
00322
00323 uint32_t number_commands= UserCommands::getUserCounts();
00324
00325 for (uint32_t j= 0; j < number_commands; ++j)
00326 {
00327 add_field(UserCommands::USER_COUNTS[j], TableFunction::NUMBER);
00328 }
00329 }
00330
00331 CumulativeCommandsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
00332 plugin::TableFunction::Generator(arg)
00333 {
00334 inner_logging_stats= logging_stats;
00335 record_number= 0;
00336
00337 if (inner_logging_stats->isEnabled())
00338 {
00339 last_valid_index= inner_logging_stats->getCumulativeStats()->getCumulativeStatsLastValidIndex();
00340 }
00341 else
00342 {
00343 last_valid_index= INVALID_INDEX;
00344 }
00345 }
00346
00347 bool CumulativeCommandsTool::Generator::populate()
00348 {
00349 if ((record_number > last_valid_index) || (last_valid_index == INVALID_INDEX))
00350 {
00351 return false;
00352 }
00353
00354 while (record_number <= last_valid_index)
00355 {
00356 ScoreboardSlot *cumulative_scoreboard_slot=
00357 inner_logging_stats->getCumulativeStats()->getCumulativeStatsByUserVector()->at(record_number);
00358
00359 if (cumulative_scoreboard_slot->isInUse())
00360 {
00361 UserCommands *user_commands= cumulative_scoreboard_slot->getUserCommands();
00362 push(cumulative_scoreboard_slot->getUser());
00363
00364 uint32_t number_commands= UserCommands::getUserCounts();
00365
00366 for (uint32_t j= 0; j < number_commands; ++j)
00367 {
00368 push(user_commands->getUserCount(j));
00369 }
00370 ++record_number;
00371 return true;
00372 }
00373 else
00374 {
00375 ++record_number;
00376 }
00377 }
00378
00379 return false;
00380 }
00381
00382 CumulativeUserStatsTool::CumulativeUserStatsTool(LoggingStats *logging_stats) :
00383 plugin::TableFunction("DATA_DICTIONARY", "CUMULATIVE_USER_STATS")
00384 {
00385 outer_logging_stats= logging_stats;
00386
00387 add_field("USERNAME");
00388 add_field("BYTES_RECEIVED");
00389 add_field("BYTES_SENT");
00390 add_field("DENIED_CONNECTIONS");
00391 add_field("LOST_CONNECTIONS");
00392 add_field("ACCESS_DENIED");
00393 add_field("CONNECTED_TIME_SEC");
00394 add_field("EXECUTION_TIME_NSEC");
00395 add_field("ROWS_FETCHED");
00396 add_field("ROWS_UPDATED");
00397 add_field("ROWS_DELETED");
00398 add_field("ROWS_INSERTED");
00399 }
00400
00401 CumulativeUserStatsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
00402 plugin::TableFunction::Generator(arg)
00403 {
00404 inner_logging_stats= logging_stats;
00405 record_number= 0;
00406
00407 if (inner_logging_stats->isEnabled())
00408 {
00409 last_valid_index= inner_logging_stats->getCumulativeStats()->getCumulativeStatsLastValidIndex();
00410 }
00411 else
00412 {
00413 last_valid_index= INVALID_INDEX;
00414 }
00415 }
00416
00417 bool CumulativeUserStatsTool::Generator::populate()
00418 {
00419 if ((record_number > last_valid_index) || (last_valid_index == INVALID_INDEX))
00420 {
00421 return false;
00422 }
00423
00424 while (record_number <= last_valid_index)
00425 {
00426 ScoreboardSlot *cumulative_scoreboard_slot=
00427 inner_logging_stats->getCumulativeStats()->getCumulativeStatsByUserVector()->at(record_number);
00428
00429 if (cumulative_scoreboard_slot->isInUse())
00430 {
00431 StatusVars *status_vars= cumulative_scoreboard_slot->getStatusVars();
00432 push(cumulative_scoreboard_slot->getUser());
00433
00434 push(status_vars->getStatusVarCounters()->bytes_received);
00435 push(status_vars->getStatusVarCounters()->bytes_sent);
00436 push(status_vars->getStatusVarCounters()->aborted_connects);
00437 push(status_vars->getStatusVarCounters()->aborted_threads);
00438 push(status_vars->getStatusVarCounters()->access_denied);
00439 push(status_vars->getStatusVarCounters()->connection_time);
00440 push(status_vars->getStatusVarCounters()->execution_time_nsec);
00441 push(status_vars->sent_row_count);
00442 push(status_vars->getStatusVarCounters()->updated_row_count);
00443 push(status_vars->getStatusVarCounters()->deleted_row_count);
00444 push(status_vars->getStatusVarCounters()->inserted_row_count);
00445
00446 ++record_number;
00447 return true;
00448 }
00449 else
00450 {
00451 ++record_number;
00452 }
00453 }
00454
00455 return false;
00456 }
00457
00458 ScoreboardStatsTool::ScoreboardStatsTool(LoggingStats *logging_stats) :
00459 plugin::TableFunction("DATA_DICTIONARY", "SCOREBOARD_STATISTICS")
00460 {
00461 outer_logging_stats= logging_stats;
00462
00463 add_field("SCOREBOARD_SIZE", TableFunction::NUMBER);
00464 add_field("NUMBER_OF_RANGE_LOCKS", TableFunction::NUMBER);
00465 add_field("MAX_USERS_LOGGED", TableFunction::NUMBER);
00466 add_field("MEMORY_USAGE_BYTES", TableFunction::NUMBER);
00467 }
00468
00469 ScoreboardStatsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
00470 plugin::TableFunction::Generator(arg)
00471 {
00472 inner_logging_stats= logging_stats;
00473 is_last_record= false;
00474 }
00475
00476 bool ScoreboardStatsTool::Generator::populate()
00477 {
00478 if (is_last_record)
00479 {
00480 return false;
00481 }
00482
00483 Scoreboard *scoreboard= inner_logging_stats->getCurrentScoreboard();
00484 CumulativeStats *cumulativeStats= inner_logging_stats->getCumulativeStats();
00485
00486 push(static_cast<uint64_t>(scoreboard->getNumberPerBucket() * scoreboard->getNumberBuckets()));
00487 push(static_cast<uint64_t>(scoreboard->getNumberBuckets()));
00488 push(static_cast<uint64_t>(cumulativeStats->getCumulativeStatsByUserMax()));
00489 push(cumulativeStats->getCumulativeSizeBytes() + scoreboard->getScoreboardSizeBytes());
00490
00491 is_last_record= true;
00492
00493 return true;
00494 }