27
27
* THE POSSIBILITY OF SUCH DAMAGE.
33
* This class defines the following DATA_DICTIONARY tables:
35
* drizzle> describe GLOBAL_STATEMENTS;
36
* +----------------+---------+-------+---------+-----------------+-----------+
37
* | Field | Type | Null | Default | Default_is_NULL | On_Update |
38
* +----------------+---------+-------+---------+-----------------+-----------+
39
* | VARIABLE_NAME | VARCHAR | FALSE | | FALSE | |
40
* | VARIABLE_VALUE | BIGINT | FALSE | | FALSE | |
41
* +----------------+---------+-------+---------+-----------------+-----------+
43
* drizzle> describe SESSION_STATEMENTS;
44
* +----------------+---------+-------+---------+-----------------+-----------+
45
* | Field | Type | Null | Default | Default_is_NULL | On_Update |
46
* +----------------+---------+-------+---------+-----------------+-----------+
47
* | VARIABLE_NAME | VARCHAR | FALSE | | FALSE | |
48
* | VARIABLE_VALUE | BIGINT | FALSE | | FALSE | |
49
* +----------------+---------+-------+---------+-----------------+-----------+
51
* drizzle> describe CURRENT_SQL_COMMANDS;
52
* +----------------+---------+-------+---------+-----------------+-----------+
53
* | Field | Type | Null | Default | Default_is_NULL | On_Update |
54
* +----------------+---------+-------+---------+-----------------+-----------+
55
* | USERNAME | VARCHAR | FALSE | | FALSE | |
56
* | IP | VARCHAR | FALSE | | FALSE | |
57
* | COUNT_SELECT | BIGINT | FALSE | | FALSE | |
58
* | COUNT_DELETE | BIGINT | FALSE | | FALSE | |
59
* | COUNT_UPDATE | BIGINT | FALSE | | FALSE | |
60
* | COUNT_INSERT | BIGINT | FALSE | | FALSE | |
61
* | COUNT_ROLLBACK | BIGINT | FALSE | | FALSE | |
62
* | COUNT_COMMIT | BIGINT | FALSE | | FALSE | |
63
* | COUNT_CREATE | BIGINT | FALSE | | FALSE | |
64
* | COUNT_ALTER | BIGINT | FALSE | | FALSE | |
65
* | COUNT_DROP | BIGINT | FALSE | | FALSE | |
66
* | COUNT_ADMIN | BIGINT | FALSE | | FALSE | |
67
* +----------------+---------+-------+---------+-----------------+-----------+
69
* drizzle> describe CUMULATIVE_SQL_COMMANDS;
70
* +----------------+---------+-------+---------+-----------------+-----------+
71
* | Field | Type | Null | Default | Default_is_NULL | On_Update |
72
* +----------------+---------+-------+---------+-----------------+-----------+
73
* | USERNAME | VARCHAR | FALSE | | FALSE | |
74
* | COUNT_SELECT | BIGINT | FALSE | | FALSE | |
75
* | COUNT_DELETE | BIGINT | FALSE | | FALSE | |
76
* | COUNT_UPDATE | BIGINT | FALSE | | FALSE | |
77
* | COUNT_INSERT | BIGINT | FALSE | | FALSE | |
78
* | COUNT_ROLLBACK | BIGINT | FALSE | | FALSE | |
79
* | COUNT_COMMIT | BIGINT | FALSE | | FALSE | |
80
* | COUNT_CREATE | BIGINT | FALSE | | FALSE | |
81
* | COUNT_ALTER | BIGINT | FALSE | | FALSE | |
82
* | COUNT_DROP | BIGINT | FALSE | | FALSE | |
83
* | COUNT_ADMIN | BIGINT | FALSE | | FALSE | |
84
* +----------------+---------+-------+---------+-----------------+-----------+
86
* drizzle> describe CUMULATIVE_USER_STATS;
87
* +---------------------+---------+-------+---------+-----------------+-----------+
88
* | Field | Type | Null | Default | Default_is_NULL | On_Update |
89
* +---------------------+---------+-------+---------+-----------------+-----------+
90
* | USERNAME | VARCHAR | FALSE | | FALSE | |
91
* | BYTES_RECEIVED | VARCHAR | FALSE | | FALSE | |
92
* | BYTES_SENT | VARCHAR | FALSE | | FALSE | |
93
* | DENIED_CONNECTIONS | VARCHAR | FALSE | | FALSE | |
94
* | LOST_CONNECTIONS | VARCHAR | FALSE | | FALSE | |
95
* | ACCESS_DENIED | VARCHAR | FALSE | | FALSE | |
96
* | CONNECTED_TIME_SEC | VARCHAR | FALSE | | FALSE | |
97
* | EXECUTION_TIME_NSEC | VARCHAR | FALSE | | FALSE | |
98
* | ROWS_FETCHED | VARCHAR | FALSE | | FALSE | |
99
* | ROWS_UPDATED | VARCHAR | FALSE | | FALSE | |
100
* | ROWS_DELETED | VARCHAR | FALSE | | FALSE | |
101
* | ROWS_INSERTED | VARCHAR | FALSE | | FALSE | |
102
* +---------------------+---------+-------+---------+-----------------+-----------+
31
108
#include "stats_schema.h"
33
112
using namespace drizzled;
34
113
using namespace plugin;
35
114
using namespace std;
37
CommandsTool::CommandsTool(LoggingStats *logging_stats) :
38
plugin::TableFunction("DATA_DICTIONARY", "SQL_COMMANDS_BY_USER")
40
outer_logging_stats= logging_stats;
116
SessionStatementsTool::SessionStatementsTool(LoggingStats *in_logging_stats) :
117
plugin::TableFunction("DATA_DICTIONARY", "SESSION_STATEMENTS")
119
logging_stats= in_logging_stats;
120
add_field("VARIABLE_NAME");
121
add_field("VARIABLE_VALUE", 1024);
124
SessionStatementsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
125
plugin::TableFunction::Generator(arg)
129
/* Set user_commands */
130
Scoreboard *current_scoreboard= in_logging_stats->getCurrentScoreboard();
132
uint32_t bucket_number= current_scoreboard->getBucketNumber(&getSession());
134
std::vector<ScoreboardSlot* > *scoreboard_vector=
135
current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number);
137
std::vector<ScoreboardSlot *>::iterator scoreboard_vector_it= scoreboard_vector->begin();
138
std::vector<ScoreboardSlot *>::iterator scoreboard_vector_end= scoreboard_vector->end();
140
ScoreboardSlot *scoreboard_slot= NULL;
141
for (std::vector<ScoreboardSlot *>::iterator it= scoreboard_vector->begin();
142
it != scoreboard_vector->end(); ++it)
144
scoreboard_slot= *it;
145
if (scoreboard_slot->getSessionId() == getSession().getSessionId())
153
if (scoreboard_slot != NULL)
155
user_commands= scoreboard_slot->getUserCommands();
159
bool SessionStatementsTool::Generator::populate()
161
if (user_commands == NULL)
166
uint32_t number_identifiers= UserCommands::getStatusVarsCount();
168
if (count == number_identifiers)
173
push(UserCommands::COM_STATUS_VARS[count]);
175
oss << user_commands->getCount(count);
182
GlobalStatementsTool::GlobalStatementsTool(LoggingStats *in_logging_stats) :
183
plugin::TableFunction("DATA_DICTIONARY", "GLOBAL_STATEMENTS")
185
logging_stats= in_logging_stats;
186
add_field("VARIABLE_NAME");
187
add_field("VARIABLE_VALUE", 1024);
190
GlobalStatementsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
191
plugin::TableFunction::Generator(arg)
194
/* add the current scoreboard and the saved global statements */
195
global_stats_to_display= new GlobalStats();
196
CumulativeStats *cumulativeStats= in_logging_stats->getCumulativeStats();
197
cumulativeStats->sumCurrentScoreboard(in_logging_stats->getCurrentScoreboard(),
198
NULL, global_stats_to_display->getUserCommands());
199
global_stats_to_display->merge(in_logging_stats->getCumulativeStats()->getGlobalStats());
202
GlobalStatementsTool::Generator::~Generator()
204
delete global_stats_to_display;
207
bool GlobalStatementsTool::Generator::populate()
209
uint32_t number_identifiers= UserCommands::getStatusVarsCount();
210
if (count == number_identifiers)
215
push(UserCommands::COM_STATUS_VARS[count]);
217
oss << global_stats_to_display->getUserCommands()->getCount(count);
224
CurrentCommandsTool::CurrentCommandsTool(LoggingStats *logging_stats) :
225
plugin::TableFunction("DATA_DICTIONARY", "CURRENT_SQL_COMMANDS")
227
outer_logging_stats= logging_stats;
229
add_field("USERNAME");
44
add_field("COUNT_SELECT", TableFunction::NUMBER);
45
add_field("COUNT_DELETE", TableFunction::NUMBER);
46
add_field("COUNT_UPDATE", TableFunction::NUMBER);
47
add_field("COUNT_INSERT", TableFunction::NUMBER);
48
add_field("COUNT_ROLLBACK", TableFunction::NUMBER);
49
add_field("COUNT_COMMIT", TableFunction::NUMBER);
50
add_field("COUNT_CREATE", TableFunction::NUMBER);
51
add_field("COUNT_ALTER", TableFunction::NUMBER);
52
add_field("COUNT_DROP", TableFunction::NUMBER);
53
add_field("COUNT_ADMIN", TableFunction::NUMBER);
56
CommandsTool::Generator::Generator(Field **arg, LoggingStats *in_logging_stats) :
57
plugin::TableFunction::Generator(arg)
59
pthread_rwlock_rdlock(&LOCK_scoreboard);
60
logging_stats= in_logging_stats;
62
if (logging_stats->isEnabled())
232
uint32_t number_commands= UserCommands::getUserCounts();
234
for (uint32_t j= 0; j < number_commands; ++j)
236
add_field(UserCommands::USER_COUNTS[j], TableFunction::NUMBER);
68
record_number= logging_stats->getScoreBoardSize();
72
CommandsTool::Generator::~Generator()
74
pthread_rwlock_unlock(&LOCK_scoreboard);
77
bool CommandsTool::Generator::populate()
79
if (record_number == logging_stats->getScoreBoardSize())
240
CurrentCommandsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
241
plugin::TableFunction::Generator(arg)
243
inner_logging_stats= logging_stats;
245
isEnabled= inner_logging_stats->isEnabled();
247
if (isEnabled == false)
252
current_scoreboard= logging_stats->getCurrentScoreboard();
255
vector_of_scoreboard_vectors_it= current_scoreboard->getVectorOfScoreboardVectors()->begin();
256
vector_of_scoreboard_vectors_end= current_scoreboard->getVectorOfScoreboardVectors()->end();
258
setVectorIteratorsAndLock(current_bucket);
261
void CurrentCommandsTool::Generator::setVectorIteratorsAndLock(uint32_t bucket_number)
263
std::vector<ScoreboardSlot* > *scoreboard_vector=
264
current_scoreboard->getVectorOfScoreboardVectors()->at(bucket_number);
266
current_lock= current_scoreboard->getVectorOfScoreboardLocks()->at(bucket_number);
268
scoreboard_vector_it= scoreboard_vector->begin();
269
scoreboard_vector_end= scoreboard_vector->end();
270
current_lock->lock_shared();
273
bool CurrentCommandsTool::Generator::populate()
275
if (isEnabled == false)
280
while (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
282
while (scoreboard_vector_it != scoreboard_vector_end)
284
ScoreboardSlot *scoreboard_slot= *scoreboard_vector_it;
285
if (scoreboard_slot->isInUse())
287
UserCommands *user_commands= scoreboard_slot->getUserCommands();
288
push(scoreboard_slot->getUser());
289
push(scoreboard_slot->getIp());
291
uint32_t number_commands= UserCommands::getUserCounts();
293
for (uint32_t j= 0; j < number_commands; ++j)
295
push(user_commands->getUserCount(j));
298
++scoreboard_vector_it;
301
++scoreboard_vector_it;
304
++vector_of_scoreboard_vectors_it;
305
current_lock->unlock_shared();
307
if (vector_of_scoreboard_vectors_it != vector_of_scoreboard_vectors_end)
309
setVectorIteratorsAndLock(current_bucket);
316
CumulativeCommandsTool::CumulativeCommandsTool(LoggingStats *logging_stats) :
317
plugin::TableFunction("DATA_DICTIONARY", "CUMULATIVE_SQL_COMMANDS")
319
outer_logging_stats= logging_stats;
321
add_field("USERNAME");
323
uint32_t number_commands= UserCommands::getUserCounts();
325
for (uint32_t j= 0; j < number_commands; ++j)
327
add_field(UserCommands::USER_COUNTS[j], TableFunction::NUMBER);
331
CumulativeCommandsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
332
plugin::TableFunction::Generator(arg)
334
inner_logging_stats= logging_stats;
337
if (inner_logging_stats->isEnabled())
339
last_valid_index= inner_logging_stats->getCumulativeStats()->getCumulativeStatsLastValidIndex();
343
last_valid_index= INVALID_INDEX;
347
bool CumulativeCommandsTool::Generator::populate()
349
if ((record_number > last_valid_index) || (last_valid_index == INVALID_INDEX))
354
while (record_number <= last_valid_index)
356
ScoreboardSlot *cumulative_scoreboard_slot=
357
inner_logging_stats->getCumulativeStats()->getCumulativeStatsByUserVector()->at(record_number);
359
if (cumulative_scoreboard_slot->isInUse())
361
UserCommands *user_commands= cumulative_scoreboard_slot->getUserCommands();
362
push(cumulative_scoreboard_slot->getUser());
364
uint32_t number_commands= UserCommands::getUserCounts();
366
for (uint32_t j= 0; j < number_commands; ++j)
368
push(user_commands->getUserCount(j));
382
CumulativeUserStatsTool::CumulativeUserStatsTool(LoggingStats *logging_stats) :
383
plugin::TableFunction("DATA_DICTIONARY", "CUMULATIVE_USER_STATS")
385
outer_logging_stats= logging_stats;
387
add_field("USERNAME");
388
add_field("BYTES_RECEIVED");
389
add_field("BYTES_SENT");
390
add_field("DENIED_CONNECTIONS");
391
add_field("LOST_CONNECTIONS");
392
add_field("ACCESS_DENIED");
393
add_field("CONNECTED_TIME_SEC");
394
add_field("EXECUTION_TIME_NSEC");
395
add_field("ROWS_FETCHED");
396
add_field("ROWS_UPDATED");
397
add_field("ROWS_DELETED");
398
add_field("ROWS_INSERTED");
401
CumulativeUserStatsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
402
plugin::TableFunction::Generator(arg)
404
inner_logging_stats= logging_stats;
407
if (inner_logging_stats->isEnabled())
409
last_valid_index= inner_logging_stats->getCumulativeStats()->getCumulativeStatsLastValidIndex();
413
last_valid_index= INVALID_INDEX;
417
bool CumulativeUserStatsTool::Generator::populate()
419
if ((record_number > last_valid_index) || (last_valid_index == INVALID_INDEX))
424
while (record_number <= last_valid_index)
426
ScoreboardSlot *cumulative_scoreboard_slot=
427
inner_logging_stats->getCumulativeStats()->getCumulativeStatsByUserVector()->at(record_number);
429
if (cumulative_scoreboard_slot->isInUse())
431
StatusVars *status_vars= cumulative_scoreboard_slot->getStatusVars();
432
push(cumulative_scoreboard_slot->getUser());
434
push(status_vars->getStatusVarCounters()->bytes_received);
435
push(status_vars->getStatusVarCounters()->bytes_sent);
436
push(status_vars->getStatusVarCounters()->aborted_connects);
437
push(status_vars->getStatusVarCounters()->aborted_threads);
438
push(status_vars->getStatusVarCounters()->access_denied);
439
push(status_vars->getStatusVarCounters()->connection_time);
440
push(status_vars->getStatusVarCounters()->execution_time_nsec);
441
push(status_vars->sent_row_count);
442
push(status_vars->getStatusVarCounters()->updated_row_count);
443
push(status_vars->getStatusVarCounters()->deleted_row_count);
444
push(status_vars->getStatusVarCounters()->inserted_row_count);
458
ScoreboardStatsTool::ScoreboardStatsTool(LoggingStats *logging_stats) :
459
plugin::TableFunction("DATA_DICTIONARY", "SCOREBOARD_STATISTICS")
461
outer_logging_stats= logging_stats;
463
add_field("SCOREBOARD_SIZE", TableFunction::NUMBER);
464
add_field("NUMBER_OF_RANGE_LOCKS", TableFunction::NUMBER);
465
add_field("MAX_USERS_LOGGED", TableFunction::NUMBER);
466
add_field("MEMORY_USAGE_BYTES", TableFunction::NUMBER);
469
ScoreboardStatsTool::Generator::Generator(Field **arg, LoggingStats *logging_stats) :
470
plugin::TableFunction::Generator(arg)
472
inner_logging_stats= logging_stats;
473
is_last_record= false;
476
bool ScoreboardStatsTool::Generator::populate()
483
Scoreboard *scoreboard= inner_logging_stats->getCurrentScoreboard();
484
CumulativeStats *cumulativeStats= inner_logging_stats->getCumulativeStats();
486
push(static_cast<uint64_t>(scoreboard->getNumberPerBucket() * scoreboard->getNumberBuckets()));
487
push(static_cast<uint64_t>(scoreboard->getNumberBuckets()));
488
push(static_cast<uint64_t>(cumulativeStats->getCumulativeStatsByUserMax()));
489
push(cumulativeStats->getCumulativeSizeBytes() + scoreboard->getScoreboardSizeBytes());
84
ScoreBoardSlot *score_board_slots= logging_stats->getScoreBoardSlots();
86
while (record_number < logging_stats->getScoreBoardSize())
88
ScoreBoardSlot *score_board_slot= &score_board_slots[record_number];
89
if (score_board_slot->isInUse())
91
UserCommands *user_commands= score_board_slot->getUserCommands();
92
push(score_board_slot->getUser());
93
push(score_board_slot->getIp());
94
push(user_commands->getSelectCount());
95
push(user_commands->getDeleteCount());
96
push(user_commands->getUpdateCount());
97
push(user_commands->getInsertCount());
98
push(user_commands->getRollbackCount());
99
push(user_commands->getCommitCount());
100
push(user_commands->getCreateCount());
101
push(user_commands->getAlterCount());
102
push(user_commands->getDropCount());
103
push(user_commands->getAdminCount());
491
is_last_record= true;