1static ST_FIELD_INFO client_stats_fields[]=
2{
3 {"CLIENT", LIST_PROCESS_HOST_LEN, MYSQL_TYPE_STRING, 0, 0, "Client", 0},
4 {"TOTAL_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Total_connections", 0},
5 {"CONCURRENT_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Concurrent_connections", 0},
6 {"CONNECTED_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Connected_time", 0},
7 {"BUSY_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_DOUBLE, 0, 0, "Busy_time", 0},
8 {"CPU_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_DOUBLE, 0, 0, "Cpu_time", 0},
9 {"BYTES_RECEIVED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Bytes_received", 0},
10 {"BYTES_SENT", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Bytes_sent", 0},
11 {"BINLOG_BYTES_WRITTEN", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Binlog_bytes_written", 0},
12 {"ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_read", 0},
13 {"ROWS_SENT", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_sent", 0},
14 {"ROWS_DELETED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_deleted", 0},
15 {"ROWS_INSERTED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_inserted", 0},
16 {"ROWS_UPDATED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_updated", 0},
17 {"SELECT_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Select_commands", 0},
18 {"UPDATE_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Update_commands", 0},
19 {"OTHER_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Other_commands", 0},
20 {"COMMIT_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Commit_transactions", 0},
21 {"ROLLBACK_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rollback_transactions", 0},
22 {"DENIED_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Denied_connections", 0},
23 {"LOST_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Lost_connections", 0},
24 {"ACCESS_DENIED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Access_denied", 0},
25 {"EMPTY_QUERIES", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Empty_queries", 0},
26 {"TOTAL_SSL_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, MY_I_S_UNSIGNED, "Total_ssl_connections", 0},
27 {"MAX_STATEMENT_TIME_EXCEEDED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Max_statement_time_exceeded",SKIP_OPEN_TABLE},
28 {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0}
29};
30
31static int send_user_stats(THD* thd, HASH *all_user_stats, TABLE *table)
32{
33 mysql_mutex_lock(&LOCK_global_user_client_stats);
34 for (uint i= 0; i < all_user_stats->records; i++)
35 {
36 uint j= 0;
37 USER_STATS *user_stats= (USER_STATS*) my_hash_element(all_user_stats, i);
38
39 table->field[j++]->store(user_stats->user, user_stats->user_name_length,
40 system_charset_info);
41 table->field[j++]->store((longlong)user_stats->total_connections,TRUE);
42 table->field[j++]->store((longlong)user_stats->concurrent_connections, TRUE);
43 table->field[j++]->store((longlong)user_stats->connected_time, TRUE);
44 table->field[j++]->store((double)user_stats->busy_time);
45 table->field[j++]->store((double)user_stats->cpu_time);
46 table->field[j++]->store((longlong)user_stats->bytes_received, TRUE);
47 table->field[j++]->store((longlong)user_stats->bytes_sent, TRUE);
48 table->field[j++]->store((longlong)user_stats->binlog_bytes_written, TRUE);
49 table->field[j++]->store((longlong)user_stats->rows_read, TRUE);
50 table->field[j++]->store((longlong)user_stats->rows_sent, TRUE);
51 table->field[j++]->store((longlong)user_stats->rows_deleted, TRUE);
52 table->field[j++]->store((longlong)user_stats->rows_inserted, TRUE);
53 table->field[j++]->store((longlong)user_stats->rows_updated, TRUE);
54 table->field[j++]->store((longlong)user_stats->select_commands, TRUE);
55 table->field[j++]->store((longlong)user_stats->update_commands, TRUE);
56 table->field[j++]->store((longlong)user_stats->other_commands, TRUE);
57 table->field[j++]->store((longlong)user_stats->commit_trans, TRUE);
58 table->field[j++]->store((longlong)user_stats->rollback_trans, TRUE);
59 table->field[j++]->store((longlong)user_stats->denied_connections, TRUE);
60 table->field[j++]->store((longlong)user_stats->lost_connections, TRUE);
61 table->field[j++]->store((longlong)user_stats->access_denied_errors, TRUE);
62 table->field[j++]->store((longlong)user_stats->empty_queries, TRUE);
63 table->field[j++]->store((longlong)user_stats->total_ssl_connections, TRUE);
64 table->field[j++]->store((longlong)user_stats->max_statement_time_exceeded, TRUE);
65 if (schema_table_store_record(thd, table))
66 {
67 mysql_mutex_unlock(&LOCK_global_user_client_stats);
68 return 1;
69 }
70 }
71 mysql_mutex_unlock(&LOCK_global_user_client_stats);
72 return 0;
73}
74
75static int client_stats_fill(THD* thd, TABLE_LIST* tables, COND* cond)
76{
77 if (check_global_access(thd, SUPER_ACL | PROCESS_ACL, true))
78 return 0;
79
80 return send_user_stats(thd, &global_client_stats, tables->table);
81}
82
83static int client_stats_reset()
84{
85 mysql_mutex_lock(&LOCK_global_user_client_stats);
86 free_global_client_stats();
87 init_global_client_stats();
88 mysql_mutex_unlock(&LOCK_global_user_client_stats);
89 return 0;
90}
91
92static int client_stats_init(void *p)
93{
94 ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p;
95 schema->fields_info= client_stats_fields;
96 schema->fill_table= client_stats_fill;
97 schema->reset_table= client_stats_reset;
98 return 0;
99}
100