@berthojoris/mcp-mysql-server 1.43.2 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +57 -6
  2. package/DOCUMENTATIONS.md +40 -38
  3. package/README.md +26 -7
  4. package/bin/mcp-mysql.js +168 -168
  5. package/dist/cache/queryCache.js +1 -1
  6. package/dist/config/config.js +2 -1
  7. package/dist/config/featureConfig.d.ts +5 -0
  8. package/dist/config/featureConfig.js +26 -12
  9. package/dist/db/connection.d.ts +8 -1
  10. package/dist/db/connection.js +19 -14
  11. package/dist/index.js +0 -10
  12. package/dist/mcp-server.js +45 -305
  13. package/dist/security/securityLayer.d.ts +33 -5
  14. package/dist/security/securityLayer.js +211 -58
  15. package/dist/tools/aiTools.js +1 -1
  16. package/dist/tools/dataExportTools.js +8 -0
  17. package/dist/tools/queryTools.d.ts +1 -1
  18. package/dist/tools/queryTools.js +6 -7
  19. package/dist/tools/toolArgumentValidation.js +22 -22
  20. package/dist/tools/toolRegistry.d.ts +1 -1
  21. package/dist/tools/toolRegistry.js +7 -1
  22. package/dist/tools/transactionTools.js +1 -1
  23. package/manifest.json +5 -5
  24. package/package.json +86 -78
  25. package/dist/auth/authService.d.ts +0 -29
  26. package/dist/auth/authService.js +0 -114
  27. package/dist/tools/backupRestoreTools.d.ts +0 -18
  28. package/dist/tools/backupRestoreTools.js +0 -70
  29. package/dist/tools/documentationGeneratorTools.d.ts +0 -145
  30. package/dist/tools/documentationGeneratorTools.js +0 -820
  31. package/dist/tools/forecastingTools.d.ts +0 -36
  32. package/dist/tools/forecastingTools.js +0 -256
  33. package/dist/tools/functionTools.d.ts +0 -87
  34. package/dist/tools/functionTools.js +0 -358
  35. package/dist/tools/indexRecommendationTools.d.ts +0 -50
  36. package/dist/tools/indexRecommendationTools.js +0 -451
  37. package/dist/tools/intelligentQueryTools.d.ts +0 -94
  38. package/dist/tools/intelligentQueryTools.js +0 -713
  39. package/dist/tools/performanceTools.d.ts +0 -76
  40. package/dist/tools/performanceTools.js +0 -505
  41. package/dist/tools/processTools.d.ts +0 -61
  42. package/dist/tools/processTools.js +0 -181
  43. package/dist/tools/queryVisualizationTools.d.ts +0 -22
  44. package/dist/tools/queryVisualizationTools.js +0 -155
  45. package/dist/tools/schemaDesignTools.d.ts +0 -67
  46. package/dist/tools/schemaDesignTools.js +0 -359
  47. package/dist/tools/schemaPatternTools.d.ts +0 -19
  48. package/dist/tools/schemaPatternTools.js +0 -253
  49. package/dist/tools/schemaVersioningTools.d.ts +0 -138
  50. package/dist/tools/schemaVersioningTools.js +0 -1008
  51. package/dist/tools/securityAuditTools.d.ts +0 -39
  52. package/dist/tools/securityAuditTools.js +0 -319
  53. package/dist/tools/smartDiscoveryTools.d.ts +0 -163
  54. package/dist/tools/smartDiscoveryTools.js +0 -750
  55. package/dist/tools/testDataTools.d.ts +0 -26
  56. package/dist/tools/testDataTools.js +0 -325
@@ -1,76 +0,0 @@
1
- import { SecurityLayer } from "../security/securityLayer";
2
- export declare class PerformanceTools {
3
- private db;
4
- private security;
5
- constructor(security: SecurityLayer);
6
- /**
7
- * Get comprehensive performance metrics
8
- */
9
- getPerformanceMetrics(): Promise<{
10
- status: string;
11
- data?: any;
12
- error?: string;
13
- }>;
14
- /**
15
- * Get top queries by execution count
16
- */
17
- /**
18
- * Get slow queries
19
- */
20
- /**
21
- * Get table I/O statistics
22
- */
23
- getTableIOStats(params?: {
24
- limit?: number;
25
- table_schema?: string;
26
- }): Promise<{
27
- status: string;
28
- data?: any[];
29
- error?: string;
30
- }>;
31
- /**
32
- * Get index usage statistics
33
- */
34
- getIndexUsageStats(params?: {
35
- limit?: number;
36
- table_schema?: string;
37
- }): Promise<{
38
- status: string;
39
- data?: any[];
40
- error?: string;
41
- }>;
42
- /**
43
- * Get unused indexes
44
- */
45
- getUnusedIndexes(params?: {
46
- table_schema?: string;
47
- }): Promise<{
48
- status: string;
49
- data?: any[];
50
- error?: string;
51
- }>;
52
- /**
53
- * Get connection pool statistics
54
- */
55
- getConnectionPoolStats(): Promise<{
56
- status: string;
57
- data?: any;
58
- error?: string;
59
- }>;
60
- /**
61
- * Get database health check
62
- */
63
- getDatabaseHealthCheck(): Promise<{
64
- status: string;
65
- data?: any;
66
- error?: string;
67
- }>;
68
- /**
69
- * Reset performance schema statistics
70
- */
71
- resetPerformanceStats(): Promise<{
72
- status: string;
73
- message?: string;
74
- error?: string;
75
- }>;
76
- }
@@ -1,505 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PerformanceTools = void 0;
7
- const connection_1 = __importDefault(require("../db/connection"));
8
- class PerformanceTools {
9
- constructor(security) {
10
- this.db = connection_1.default.getInstance();
11
- this.security = security;
12
- }
13
- /**
14
- * Get comprehensive performance metrics
15
- */
16
- async getPerformanceMetrics() {
17
- try {
18
- const metrics = {};
19
- // Get query performance metrics
20
- const perfQuery = `
21
- SELECT
22
- SUM(TIMER_WAIT) / 1000000000000 as total_execution_time_sec,
23
- SUM(LOCK_TIME) / 1000000000000 as total_lock_time_sec,
24
- SUM(ROWS_EXAMINED) as total_rows_examined,
25
- SUM(ROWS_SENT) as total_rows_sent,
26
- SUM(ROWS_AFFECTED) as total_rows_affected,
27
- SUM(SELECT_FULL_JOIN) as full_table_scans,
28
- SUM(NO_INDEX_USED) as queries_without_indexes,
29
- SUM(NO_GOOD_INDEX_USED) as queries_with_bad_indexes,
30
- COUNT(*) as total_queries
31
- FROM performance_schema.events_statements_summary_global_by_event_name
32
- WHERE EVENT_NAME LIKE 'statement/sql/%'
33
- `;
34
- const perfResult = await this.db.query(perfQuery);
35
- metrics.query_performance = perfResult[0] || {};
36
- // Get connection metrics
37
- const connQuery = `
38
- SHOW GLOBAL STATUS WHERE Variable_name IN (
39
- 'Threads_connected', 'Threads_running', 'Threads_created',
40
- 'Connections', 'Max_used_connections', 'Aborted_connects', 'Aborted_clients'
41
- )
42
- `;
43
- const connResult = await this.db.query(connQuery);
44
- metrics.connections = {};
45
- for (const row of connResult) {
46
- metrics.connections[row.Variable_name.toLowerCase()] = row.Value;
47
- }
48
- // Get table cache metrics
49
- const cacheQuery = `
50
- SHOW GLOBAL STATUS WHERE Variable_name IN (
51
- 'Open_tables', 'Opened_tables', 'Table_open_cache_hits',
52
- 'Table_open_cache_misses', 'Table_open_cache_overflows'
53
- )
54
- `;
55
- const cacheResult = await this.db.query(cacheQuery);
56
- metrics.table_cache = {};
57
- for (const row of cacheResult) {
58
- metrics.table_cache[row.Variable_name.toLowerCase()] = row.Value;
59
- }
60
- // Get InnoDB metrics
61
- const innodbQuery = `
62
- SHOW GLOBAL STATUS WHERE Variable_name LIKE 'Innodb_%'
63
- AND Variable_name IN (
64
- 'Innodb_buffer_pool_reads', 'Innodb_buffer_pool_read_requests',
65
- 'Innodb_buffer_pool_pages_total', 'Innodb_buffer_pool_pages_free',
66
- 'Innodb_buffer_pool_pages_data', 'Innodb_buffer_pool_pages_dirty',
67
- 'Innodb_row_lock_waits', 'Innodb_row_lock_time', 'Innodb_rows_read',
68
- 'Innodb_rows_inserted', 'Innodb_rows_updated', 'Innodb_rows_deleted'
69
- )
70
- `;
71
- const innodbResult = await this.db.query(innodbQuery);
72
- metrics.innodb = {};
73
- for (const row of innodbResult) {
74
- metrics.innodb[row.Variable_name.toLowerCase()] = row.Value;
75
- }
76
- // Calculate buffer pool hit ratio
77
- if (metrics.innodb.innodb_buffer_pool_read_requests &&
78
- metrics.innodb.innodb_buffer_pool_reads) {
79
- const requests = parseFloat(metrics.innodb.innodb_buffer_pool_read_requests);
80
- const reads = parseFloat(metrics.innodb.innodb_buffer_pool_reads);
81
- metrics.innodb.buffer_pool_hit_ratio =
82
- (((requests - reads) / requests) * 100).toFixed(2) + "%";
83
- }
84
- // Get slow query metrics
85
- const slowQuery = `
86
- SHOW GLOBAL STATUS WHERE Variable_name IN ('Slow_queries', 'Questions')
87
- `;
88
- const slowResult = await this.db.query(slowQuery);
89
- metrics.slow_queries = {};
90
- for (const row of slowResult) {
91
- metrics.slow_queries[row.Variable_name.toLowerCase()] = row.Value;
92
- }
93
- // Calculate slow query percentage
94
- if (metrics.slow_queries.questions && metrics.slow_queries.slow_queries) {
95
- const total = parseFloat(metrics.slow_queries.questions);
96
- const slow = parseFloat(metrics.slow_queries.slow_queries);
97
- metrics.slow_queries.slow_query_percentage =
98
- ((slow / total) * 100).toFixed(4) + "%";
99
- }
100
- return {
101
- status: "success",
102
- data: metrics,
103
- };
104
- }
105
- catch (error) {
106
- return {
107
- status: "error",
108
- error: error.message,
109
- };
110
- }
111
- }
112
- /**
113
- * Get top queries by execution count
114
- */
115
- /**
116
- * Get slow queries
117
- */
118
- /**
119
- * Get table I/O statistics
120
- */
121
- async getTableIOStats(params) {
122
- try {
123
- const limit = params?.limit || 20;
124
- const schema = params?.table_schema;
125
- if (!Number.isInteger(limit) || limit <= 0 || limit > 100) {
126
- return {
127
- status: "error",
128
- error: "Limit must be a positive integer between 1 and 100",
129
- };
130
- }
131
- let query = `
132
- SELECT
133
- OBJECT_SCHEMA as table_schema,
134
- OBJECT_NAME as table_name,
135
- COUNT_READ as read_operations,
136
- COUNT_WRITE as write_operations,
137
- COUNT_FETCH as fetch_operations,
138
- COUNT_INSERT as insert_operations,
139
- COUNT_UPDATE as update_operations,
140
- COUNT_DELETE as delete_operations,
141
- ROUND(SUM_TIMER_READ / 1000000000000, 6) as total_read_time_sec,
142
- ROUND(SUM_TIMER_WRITE / 1000000000000, 6) as total_write_time_sec,
143
- ROUND(SUM_TIMER_FETCH / 1000000000000, 6) as total_fetch_time_sec
144
- FROM performance_schema.table_io_waits_summary_by_table
145
- WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema', 'information_schema', 'sys')
146
- `;
147
- if (schema) {
148
- query += ` AND OBJECT_SCHEMA = '${schema.replace(/'/g, "''")}'`;
149
- }
150
- query += ` ORDER BY (COUNT_READ + COUNT_WRITE) DESC LIMIT ${limit}`;
151
- const results = await this.db.query(query);
152
- return {
153
- status: "success",
154
- data: results,
155
- };
156
- }
157
- catch (error) {
158
- return {
159
- status: "error",
160
- error: error.message,
161
- };
162
- }
163
- }
164
- /**
165
- * Get index usage statistics
166
- */
167
- async getIndexUsageStats(params) {
168
- try {
169
- const limit = params?.limit || 20;
170
- const schema = params?.table_schema;
171
- if (!Number.isInteger(limit) || limit <= 0 || limit > 100) {
172
- return {
173
- status: "error",
174
- error: "Limit must be a positive integer between 1 and 100",
175
- };
176
- }
177
- let query = `
178
- SELECT
179
- OBJECT_SCHEMA as table_schema,
180
- OBJECT_NAME as table_name,
181
- INDEX_NAME as index_name,
182
- COUNT_STAR as usage_count,
183
- COUNT_READ as read_count,
184
- COUNT_WRITE as write_count,
185
- COUNT_FETCH as fetch_count,
186
- COUNT_INSERT as insert_count,
187
- COUNT_UPDATE as update_count,
188
- COUNT_DELETE as delete_count
189
- FROM performance_schema.table_io_waits_summary_by_index_usage
190
- WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema', 'information_schema', 'sys')
191
- AND INDEX_NAME IS NOT NULL
192
- `;
193
- if (schema) {
194
- query += ` AND OBJECT_SCHEMA = '${schema.replace(/'/g, "''")}'`;
195
- }
196
- query += ` ORDER BY COUNT_STAR DESC LIMIT ${limit}`;
197
- const results = await this.db.query(query);
198
- return {
199
- status: "success",
200
- data: results,
201
- };
202
- }
203
- catch (error) {
204
- return {
205
- status: "error",
206
- error: error.message,
207
- };
208
- }
209
- }
210
- /**
211
- * Get unused indexes
212
- */
213
- async getUnusedIndexes(params) {
214
- try {
215
- const schema = params?.table_schema;
216
- let query = `
217
- SELECT
218
- t.TABLE_SCHEMA as table_schema,
219
- t.TABLE_NAME as table_name,
220
- s.INDEX_NAME as index_name,
221
- s.COLUMN_NAME as column_name,
222
- s.SEQ_IN_INDEX as sequence_in_index,
223
- s.NON_UNIQUE as is_non_unique
224
- FROM information_schema.STATISTICS s
225
- LEFT JOIN performance_schema.table_io_waits_summary_by_index_usage p
226
- ON s.TABLE_SCHEMA = p.OBJECT_SCHEMA
227
- AND s.TABLE_NAME = p.OBJECT_NAME
228
- AND s.INDEX_NAME = p.INDEX_NAME
229
- JOIN information_schema.TABLES t
230
- ON s.TABLE_SCHEMA = t.TABLE_SCHEMA
231
- AND s.TABLE_NAME = t.TABLE_NAME
232
- WHERE s.TABLE_SCHEMA NOT IN ('mysql', 'performance_schema', 'information_schema', 'sys')
233
- AND s.INDEX_NAME != 'PRIMARY'
234
- AND (p.INDEX_NAME IS NULL OR p.COUNT_STAR = 0)
235
- AND t.TABLE_TYPE = 'BASE TABLE'
236
- `;
237
- if (schema) {
238
- query += ` AND s.TABLE_SCHEMA = '${schema.replace(/'/g, "''")}'`;
239
- }
240
- query += ` ORDER BY s.TABLE_SCHEMA, s.TABLE_NAME, s.INDEX_NAME, s.SEQ_IN_INDEX`;
241
- const results = await this.db.query(query);
242
- return {
243
- status: "success",
244
- data: results,
245
- };
246
- }
247
- catch (error) {
248
- return {
249
- status: "error",
250
- error: error.message,
251
- };
252
- }
253
- }
254
- /**
255
- * Get connection pool statistics
256
- */
257
- async getConnectionPoolStats() {
258
- try {
259
- const statusQuery = `
260
- SHOW GLOBAL STATUS WHERE Variable_name IN (
261
- 'Threads_connected', 'Threads_running', 'Threads_created', 'Threads_cached',
262
- 'Connections', 'Max_used_connections', 'Max_used_connections_time',
263
- 'Aborted_connects', 'Aborted_clients', 'Connection_errors_max_connections'
264
- )
265
- `;
266
- const variablesQuery = `
267
- SHOW GLOBAL VARIABLES WHERE Variable_name IN (
268
- 'max_connections', 'thread_cache_size', 'connect_timeout',
269
- 'wait_timeout', 'interactive_timeout'
270
- )
271
- `;
272
- const statusResult = await this.db.query(statusQuery);
273
- const variablesResult = await this.db.query(variablesQuery);
274
- const stats = {
275
- current_status: {},
276
- configuration: {},
277
- health_indicators: {},
278
- };
279
- for (const row of statusResult) {
280
- stats.current_status[row.Variable_name.toLowerCase()] = row.Value;
281
- }
282
- for (const row of variablesResult) {
283
- stats.configuration[row.Variable_name.toLowerCase()] = row.Value;
284
- }
285
- // Calculate health indicators
286
- const threadsConnected = parseInt(stats.current_status.threads_connected || "0");
287
- const maxConnections = parseInt(stats.configuration.max_connections || "0");
288
- const maxUsedConnections = parseInt(stats.current_status.max_used_connections || "0");
289
- if (maxConnections > 0) {
290
- stats.health_indicators.connection_usage_percentage =
291
- ((threadsConnected / maxConnections) * 100).toFixed(2) + "%";
292
- stats.health_indicators.max_usage_percentage =
293
- ((maxUsedConnections / maxConnections) * 100).toFixed(2) + "%";
294
- stats.health_indicators.available_connections =
295
- maxConnections - threadsConnected;
296
- }
297
- // Connection efficiency
298
- const totalConnections = parseInt(stats.current_status.connections || "0");
299
- const abortedConnects = parseInt(stats.current_status.aborted_connects || "0");
300
- if (totalConnections > 0) {
301
- stats.health_indicators.aborted_connection_percentage =
302
- ((abortedConnects / totalConnections) * 100).toFixed(4) + "%";
303
- }
304
- // Thread cache efficiency
305
- const threadsCreated = parseInt(stats.current_status.threads_created || "0");
306
- if (totalConnections > 0) {
307
- stats.health_indicators.thread_cache_hit_rate =
308
- (((totalConnections - threadsCreated) / totalConnections) *
309
- 100).toFixed(2) + "%";
310
- }
311
- return {
312
- status: "success",
313
- data: stats,
314
- };
315
- }
316
- catch (error) {
317
- return {
318
- status: "error",
319
- error: error.message,
320
- };
321
- }
322
- }
323
- /**
324
- * Get database health check
325
- */
326
- async getDatabaseHealthCheck() {
327
- try {
328
- const health = {
329
- overall_status: "healthy",
330
- checks: [],
331
- warnings: [],
332
- errors: [],
333
- };
334
- // Check 1: Connection usage
335
- const connQuery = `
336
- SHOW GLOBAL STATUS WHERE Variable_name IN ('Threads_connected', 'Max_used_connections')
337
- `;
338
- const maxConnQuery = `SHOW GLOBAL VARIABLES WHERE Variable_name = 'max_connections'`;
339
- const connResult = await this.db.query(connQuery);
340
- const maxConnResult = await this.db.query(maxConnQuery);
341
- let threadsConnected = 0;
342
- let maxUsedConnections = 0;
343
- let maxConnections = 0;
344
- for (const row of connResult) {
345
- if (row.Variable_name === "Threads_connected")
346
- threadsConnected = parseInt(row.Value);
347
- if (row.Variable_name === "Max_used_connections")
348
- maxUsedConnections = parseInt(row.Value);
349
- }
350
- for (const row of maxConnResult) {
351
- maxConnections = parseInt(row.Value);
352
- }
353
- const connUsage = (threadsConnected / maxConnections) * 100;
354
- const maxConnUsage = (maxUsedConnections / maxConnections) * 100;
355
- health.checks.push({
356
- name: "Connection Usage",
357
- status: connUsage < 80 ? "healthy" : connUsage < 90 ? "warning" : "critical",
358
- current: threadsConnected,
359
- max: maxConnections,
360
- usage_percentage: connUsage.toFixed(2) + "%",
361
- });
362
- if (connUsage >= 90) {
363
- health.errors.push("Connection usage is critically high (>90%)");
364
- health.overall_status = "critical";
365
- }
366
- else if (connUsage >= 80) {
367
- health.warnings.push("Connection usage is high (>80%)");
368
- if (health.overall_status === "healthy")
369
- health.overall_status = "warning";
370
- }
371
- // Check 2: Buffer pool hit ratio
372
- const bufferQuery = `
373
- SHOW GLOBAL STATUS WHERE Variable_name IN ('Innodb_buffer_pool_read_requests', 'Innodb_buffer_pool_reads')
374
- `;
375
- const bufferResult = await this.db.query(bufferQuery);
376
- let readRequests = 0;
377
- let reads = 0;
378
- for (const row of bufferResult) {
379
- if (row.Variable_name === "Innodb_buffer_pool_read_requests")
380
- readRequests = parseInt(row.Value);
381
- if (row.Variable_name === "Innodb_buffer_pool_reads")
382
- reads = parseInt(row.Value);
383
- }
384
- const hitRatio = readRequests > 0 ? ((readRequests - reads) / readRequests) * 100 : 100;
385
- health.checks.push({
386
- name: "Buffer Pool Hit Ratio",
387
- status: hitRatio > 95 ? "healthy" : hitRatio > 85 ? "warning" : "critical",
388
- hit_ratio: hitRatio.toFixed(2) + "%",
389
- });
390
- if (hitRatio <= 85) {
391
- health.errors.push("Buffer pool hit ratio is too low (<85%)");
392
- health.overall_status = "critical";
393
- }
394
- else if (hitRatio <= 95) {
395
- health.warnings.push("Buffer pool hit ratio could be improved (<95%)");
396
- if (health.overall_status === "healthy")
397
- health.overall_status = "warning";
398
- }
399
- // Check 3: Aborted connections
400
- const abortQuery = `
401
- SHOW GLOBAL STATUS WHERE Variable_name IN ('Connections', 'Aborted_connects')
402
- `;
403
- const abortResult = await this.db.query(abortQuery);
404
- let totalConnections = 0;
405
- let abortedConnects = 0;
406
- for (const row of abortResult) {
407
- if (row.Variable_name === "Connections")
408
- totalConnections = parseInt(row.Value);
409
- if (row.Variable_name === "Aborted_connects")
410
- abortedConnects = parseInt(row.Value);
411
- }
412
- const abortRate = totalConnections > 0 ? (abortedConnects / totalConnections) * 100 : 0;
413
- health.checks.push({
414
- name: "Aborted Connections",
415
- status: abortRate < 1 ? "healthy" : abortRate < 5 ? "warning" : "critical",
416
- aborted: abortedConnects,
417
- total: totalConnections,
418
- abort_rate: abortRate.toFixed(4) + "%",
419
- });
420
- if (abortRate >= 5) {
421
- health.errors.push("High rate of aborted connections (>5%)");
422
- if (health.overall_status !== "critical")
423
- health.overall_status = "warning";
424
- }
425
- else if (abortRate >= 1) {
426
- health.warnings.push("Elevated rate of aborted connections (>1%)");
427
- if (health.overall_status === "healthy")
428
- health.overall_status = "warning";
429
- }
430
- // Check 4: Slow queries
431
- const slowQuery = `
432
- SHOW GLOBAL STATUS WHERE Variable_name IN ('Questions', 'Slow_queries')
433
- `;
434
- const slowResult = await this.db.query(slowQuery);
435
- let questions = 0;
436
- let slowQueries = 0;
437
- for (const row of slowResult) {
438
- if (row.Variable_name === "Questions")
439
- questions = parseInt(row.Value);
440
- if (row.Variable_name === "Slow_queries")
441
- slowQueries = parseInt(row.Value);
442
- }
443
- const slowQueryRate = questions > 0 ? (slowQueries / questions) * 100 : 0;
444
- health.checks.push({
445
- name: "Slow Queries",
446
- status: slowQueryRate < 1
447
- ? "healthy"
448
- : slowQueryRate < 5
449
- ? "warning"
450
- : "critical",
451
- slow_queries: slowQueries,
452
- total_queries: questions,
453
- slow_query_rate: slowQueryRate.toFixed(4) + "%",
454
- });
455
- if (slowQueryRate >= 5) {
456
- health.warnings.push("High rate of slow queries (>5%)");
457
- if (health.overall_status === "healthy")
458
- health.overall_status = "warning";
459
- }
460
- else if (slowQueryRate >= 1) {
461
- health.warnings.push("Elevated rate of slow queries (>1%)");
462
- if (health.overall_status === "healthy")
463
- health.overall_status = "warning";
464
- }
465
- return {
466
- status: "success",
467
- data: health,
468
- };
469
- }
470
- catch (error) {
471
- return {
472
- status: "error",
473
- error: error.message,
474
- };
475
- }
476
- }
477
- /**
478
- * Reset performance schema statistics
479
- */
480
- async resetPerformanceStats() {
481
- try {
482
- // Truncate performance schema summary tables
483
- const tables = [
484
- "events_statements_summary_by_digest",
485
- "events_statements_summary_global_by_event_name",
486
- "table_io_waits_summary_by_table",
487
- "table_io_waits_summary_by_index_usage",
488
- ];
489
- for (const table of tables) {
490
- await this.db.query(`TRUNCATE TABLE performance_schema.${table}`);
491
- }
492
- return {
493
- status: "success",
494
- message: "Performance statistics reset successfully",
495
- };
496
- }
497
- catch (error) {
498
- return {
499
- status: "error",
500
- error: error.message,
501
- };
502
- }
503
- }
504
- }
505
- exports.PerformanceTools = PerformanceTools;
@@ -1,61 +0,0 @@
1
- import { SecurityLayer } from "../security/securityLayer";
2
- export declare class ProcessTools {
3
- private db;
4
- private security;
5
- constructor(security: SecurityLayer);
6
- /**
7
- * Show all running processes/connections
8
- */
9
- showProcessList(params?: {
10
- full?: boolean;
11
- }): Promise<{
12
- status: string;
13
- data?: any[];
14
- error?: string;
15
- }>;
16
- /**
17
- * Kill a specific process/connection
18
- */
19
- killProcess(params: {
20
- process_id: number;
21
- type?: "CONNECTION" | "QUERY";
22
- }): Promise<{
23
- status: string;
24
- message?: string;
25
- error?: string;
26
- }>;
27
- /**
28
- * Show server status variables
29
- */
30
- showStatus(params?: {
31
- like?: string;
32
- global?: boolean;
33
- }): Promise<{
34
- status: string;
35
- data?: any;
36
- error?: string;
37
- }>;
38
- /**
39
- * Show server variables
40
- */
41
- showVariables(params?: {
42
- like?: string;
43
- global?: boolean;
44
- }): Promise<{
45
- status: string;
46
- data?: any;
47
- error?: string;
48
- }>;
49
- /**
50
- * Explain a query (show execution plan)
51
- */
52
- explainQuery(params: {
53
- query: string;
54
- format?: "TRADITIONAL" | "JSON" | "TREE";
55
- analyze?: boolean;
56
- }): Promise<{
57
- status: string;
58
- data?: any;
59
- error?: string;
60
- }>;
61
- }