mcp-wordpress 2.4.2 → 2.5.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.
- package/README.md +114 -48
- package/dist/ajv-patch.js +34 -0
- package/dist/cache/CacheInvalidation.d.ts +3 -1
- package/dist/cache/CacheInvalidation.d.ts.map +1 -1
- package/dist/cache/CacheInvalidation.js +10 -4
- package/dist/cache/CacheInvalidation.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +3 -2
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +11 -3
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/HttpCacheWrapper.d.ts +7 -6
- package/dist/cache/HttpCacheWrapper.d.ts.map +1 -1
- package/dist/cache/HttpCacheWrapper.js +8 -5
- package/dist/cache/HttpCacheWrapper.js.map +1 -1
- package/dist/cache/__tests__/HttpCacheWrapper.test.js +6 -5
- package/dist/cache/__tests__/HttpCacheWrapper.test.js.map +1 -1
- package/dist/cache/index.d.ts +3 -3
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cache/index.js.map +1 -1
- package/dist/client/CachedWordPressClient.d.ts +23 -9
- package/dist/client/CachedWordPressClient.d.ts.map +1 -1
- package/dist/client/CachedWordPressClient.js +4 -1
- package/dist/client/CachedWordPressClient.js.map +1 -1
- package/dist/client/MockWordPressClient.d.ts +2 -1
- package/dist/client/MockWordPressClient.d.ts.map +1 -1
- package/dist/client/MockWordPressClient.js +3 -1
- package/dist/client/MockWordPressClient.js.map +1 -1
- package/dist/client/api.d.ts +17 -13
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +135 -30
- package/dist/client/api.js.map +1 -1
- package/dist/client/auth.d.ts.map +1 -1
- package/dist/client/auth.js +2 -3
- package/dist/client/auth.js.map +1 -1
- package/dist/client/managers/AuthenticationManager.d.ts +55 -2
- package/dist/client/managers/AuthenticationManager.d.ts.map +1 -1
- package/dist/client/managers/AuthenticationManager.js +269 -71
- package/dist/client/managers/AuthenticationManager.js.map +1 -1
- package/dist/client/managers/BaseManager.d.ts +3 -3
- package/dist/client/managers/BaseManager.d.ts.map +1 -1
- package/dist/client/managers/BaseManager.js +11 -5
- package/dist/client/managers/BaseManager.js.map +1 -1
- package/dist/client/managers/RequestManager.d.ts +2 -2
- package/dist/client/managers/RequestManager.d.ts.map +1 -1
- package/dist/client/managers/RequestManager.js +25 -12
- package/dist/client/managers/RequestManager.js.map +1 -1
- package/dist/config/Config.d.ts +155 -0
- package/dist/config/Config.d.ts.map +1 -0
- package/dist/config/Config.js +215 -0
- package/dist/config/Config.js.map +1 -0
- package/dist/config/ConfigurationSchema.d.ts +21 -21
- package/dist/config/ConfigurationSchema.d.ts.map +1 -1
- package/dist/config/ConfigurationSchema.js +19 -2
- package/dist/config/ConfigurationSchema.js.map +1 -1
- package/dist/config/ServerConfiguration.d.ts +2 -1
- package/dist/config/ServerConfiguration.d.ts.map +1 -1
- package/dist/config/ServerConfiguration.js +50 -41
- package/dist/config/ServerConfiguration.js.map +1 -1
- package/dist/docs/DocumentationGenerator.d.ts +9 -8
- package/dist/docs/DocumentationGenerator.d.ts.map +1 -1
- package/dist/docs/DocumentationGenerator.js +10 -7
- package/dist/docs/DocumentationGenerator.js.map +1 -1
- package/dist/docs/MarkdownFormatter.d.ts.map +1 -1
- package/dist/docs/MarkdownFormatter.js +3 -2
- package/dist/docs/MarkdownFormatter.js.map +1 -1
- package/dist/dxt-entry.cjs +81 -0
- package/dist/dxt-entry.js +15 -14
- package/dist/dxt-entry.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -21
- package/dist/index.js.map +1 -1
- package/dist/performance/MetricsCollector.d.ts +13 -7
- package/dist/performance/MetricsCollector.d.ts.map +1 -1
- package/dist/performance/MetricsCollector.js +69 -27
- package/dist/performance/MetricsCollector.js.map +1 -1
- package/dist/performance/PerformanceAnalytics.d.ts +8 -2
- package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
- package/dist/performance/PerformanceAnalytics.js +17 -47
- package/dist/performance/PerformanceAnalytics.js.map +1 -1
- package/dist/performance/PerformanceMonitor.d.ts +2 -1
- package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
- package/dist/performance/PerformanceMonitor.js +12 -13
- package/dist/performance/PerformanceMonitor.js.map +1 -1
- package/dist/performance/index.d.ts +2 -2
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/security/AISecurityScanner.d.ts +1 -0
- package/dist/security/AISecurityScanner.d.ts.map +1 -1
- package/dist/security/AISecurityScanner.js +22 -12
- package/dist/security/AISecurityScanner.js.map +1 -1
- package/dist/security/AutomatedRemediation.d.ts +4 -3
- package/dist/security/AutomatedRemediation.d.ts.map +1 -1
- package/dist/security/AutomatedRemediation.js +46 -15
- package/dist/security/AutomatedRemediation.js.map +1 -1
- package/dist/security/InputValidator.d.ts +13 -9
- package/dist/security/InputValidator.d.ts.map +1 -1
- package/dist/security/InputValidator.js +4 -2
- package/dist/security/InputValidator.js.map +1 -1
- package/dist/security/SecurityCIPipeline.d.ts +1 -1
- package/dist/security/SecurityCIPipeline.d.ts.map +1 -1
- package/dist/security/SecurityCIPipeline.js +38 -29
- package/dist/security/SecurityCIPipeline.js.map +1 -1
- package/dist/security/SecurityConfig.d.ts +3 -3
- package/dist/security/SecurityConfig.d.ts.map +1 -1
- package/dist/security/SecurityConfig.js +13 -9
- package/dist/security/SecurityConfig.js.map +1 -1
- package/dist/security/SecurityConfigManager.d.ts +2 -2
- package/dist/security/SecurityConfigManager.d.ts.map +1 -1
- package/dist/security/SecurityConfigManager.js +20 -15
- package/dist/security/SecurityConfigManager.js.map +1 -1
- package/dist/security/SecurityMonitoring.d.ts +2 -2
- package/dist/security/SecurityMonitoring.d.ts.map +1 -1
- package/dist/security/SecurityMonitoring.js +19 -17
- package/dist/security/SecurityMonitoring.js.map +1 -1
- package/dist/security/SecurityReviewer.d.ts.map +1 -1
- package/dist/security/SecurityReviewer.js +10 -7
- package/dist/security/SecurityReviewer.js.map +1 -1
- package/dist/security/index.d.ts +24 -23
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +52 -23
- package/dist/security/index.js.map +1 -1
- package/dist/server/ConnectionTester.d.ts +12 -4
- package/dist/server/ConnectionTester.d.ts.map +1 -1
- package/dist/server/ConnectionTester.js +96 -22
- package/dist/server/ConnectionTester.js.map +1 -1
- package/dist/server/ToolRegistry.d.ts +2 -2
- package/dist/server/ToolRegistry.d.ts.map +1 -1
- package/dist/server/ToolRegistry.js +10 -5
- package/dist/server/ToolRegistry.js.map +1 -1
- package/dist/tools/BaseToolManager.d.ts +47 -11
- package/dist/tools/BaseToolManager.d.ts.map +1 -1
- package/dist/tools/BaseToolManager.js +168 -29
- package/dist/tools/BaseToolManager.js.map +1 -1
- package/dist/tools/auth.d.ts +16 -10
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js +3 -2
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/cache.d.ts +30 -30
- package/dist/tools/cache.d.ts.map +1 -1
- package/dist/tools/cache.js +1 -6
- package/dist/tools/cache.js.map +1 -1
- package/dist/tools/comments.d.ts +20 -20
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js +16 -9
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/media.d.ts +18 -16
- package/dist/tools/media.d.ts.map +1 -1
- package/dist/tools/media.js +16 -15
- package/dist/tools/media.js.map +1 -1
- package/dist/tools/pages.d.ts +19 -17
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js +16 -12
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/performance.d.ts +11 -1
- package/dist/tools/performance.d.ts.map +1 -1
- package/dist/tools/performance.js +67 -34
- package/dist/tools/performance.js.map +1 -1
- package/dist/tools/posts/PostHandlers.d.ts +46 -0
- package/dist/tools/posts/PostHandlers.d.ts.map +1 -0
- package/dist/tools/posts/PostHandlers.js +400 -0
- package/dist/tools/posts/PostHandlers.js.map +1 -0
- package/dist/tools/posts/PostToolDefinitions.d.ts +37 -0
- package/dist/tools/posts/PostToolDefinitions.d.ts.map +1 -0
- package/dist/tools/posts/PostToolDefinitions.js +236 -0
- package/dist/tools/posts/PostToolDefinitions.js.map +1 -0
- package/dist/tools/posts/index.d.ts +138 -0
- package/dist/tools/posts/index.d.ts.map +1 -0
- package/dist/tools/posts/index.js +163 -0
- package/dist/tools/posts/index.js.map +1 -0
- package/dist/tools/posts.d.ts +10 -246
- package/dist/tools/posts.d.ts.map +1 -1
- package/dist/tools/posts.js +11 -723
- package/dist/tools/posts.js.map +1 -1
- package/dist/tools/site.d.ts +19 -18
- package/dist/tools/site.d.ts.map +1 -1
- package/dist/tools/site.js +14 -10
- package/dist/tools/site.js.map +1 -1
- package/dist/tools/taxonomies.d.ts +23 -24
- package/dist/tools/taxonomies.d.ts.map +1 -1
- package/dist/tools/taxonomies.js +24 -18
- package/dist/tools/taxonomies.js.map +1 -1
- package/dist/tools/users.d.ts +20 -15
- package/dist/tools/users.d.ts.map +1 -1
- package/dist/tools/users.js +12 -8
- package/dist/tools/users.js.map +1 -1
- package/dist/types/client.d.ts +48 -41
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client.js +30 -5
- package/dist/types/client.js.map +1 -1
- package/dist/types/enhanced.d.ts +237 -0
- package/dist/types/enhanced.d.ts.map +1 -0
- package/dist/types/enhanced.js +49 -0
- package/dist/types/enhanced.js.map +1 -0
- package/dist/types/index.d.ts +15 -12
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/mcp.d.ts +12 -12
- package/dist/types/mcp.d.ts.map +1 -1
- package/dist/types/requests.d.ts +322 -0
- package/dist/types/requests.d.ts.map +1 -0
- package/dist/types/requests.js +8 -0
- package/dist/types/requests.js.map +1 -0
- package/dist/types/tools.d.ts +506 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +8 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/types/wordpress.d.ts +43 -15
- package/dist/types/wordpress.d.ts.map +1 -1
- package/dist/types/wordpress.js +8 -1
- package/dist/types/wordpress.js.map +1 -1
- package/dist/utils/debug.d.ts +19 -11
- package/dist/utils/debug.d.ts.map +1 -1
- package/dist/utils/debug.js +46 -10
- package/dist/utils/debug.js.map +1 -1
- package/dist/utils/enhancedError.d.ts +8 -8
- package/dist/utils/enhancedError.d.ts.map +1 -1
- package/dist/utils/enhancedError.js.map +1 -1
- package/dist/utils/error.d.ts +2 -4
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/utils/error.js +42 -5
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/logger.d.ts +106 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +280 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/streaming.d.ts +9 -9
- package/dist/utils/streaming.d.ts.map +1 -1
- package/dist/utils/streaming.js +71 -52
- package/dist/utils/streaming.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts +9 -7
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/dist/utils/toolWrapper.js.map +1 -1
- package/dist/utils/validation/core.d.ts +21 -0
- package/dist/utils/validation/core.d.ts.map +1 -0
- package/dist/utils/validation/core.js +71 -0
- package/dist/utils/validation/core.js.map +1 -0
- package/dist/utils/validation/index.d.ts +25 -0
- package/dist/utils/validation/index.d.ts.map +1 -0
- package/dist/utils/validation/index.js +29 -0
- package/dist/utils/validation/index.js.map +1 -0
- package/dist/utils/validation/network.d.ts +19 -0
- package/dist/utils/validation/network.d.ts.map +1 -0
- package/dist/utils/validation/network.js +93 -0
- package/dist/utils/validation/network.js.map +1 -0
- package/dist/utils/validation/rateLimit.d.ts +21 -0
- package/dist/utils/validation/rateLimit.d.ts.map +1 -0
- package/dist/utils/validation/rateLimit.js +43 -0
- package/dist/utils/validation/rateLimit.js.map +1 -0
- package/dist/utils/validation/security.d.ts +29 -0
- package/dist/utils/validation/security.d.ts.map +1 -0
- package/dist/utils/validation/security.js +327 -0
- package/dist/utils/validation/security.js.map +1 -0
- package/dist/utils/validation/wordpress.d.ts +31 -0
- package/dist/utils/validation/wordpress.d.ts.map +1 -0
- package/dist/utils/validation/wordpress.js +146 -0
- package/dist/utils/validation/wordpress.js.map +1 -0
- package/dist/utils/validation.d.ts +13 -82
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +25 -343
- package/dist/utils/validation.js.map +1 -1
- package/docs/BADGE_UPDATES.md +132 -0
- package/docs/CI_CD_IMPROVEMENTS.md +191 -0
- package/docs/INCREMENTAL_COVERAGE.md +183 -0
- package/docs/api/README.md +3 -1
- package/docs/api/openapi.json +5 -1
- package/docs/api/summary.json +1 -1
- package/docs/api/tools/wp_create_post.md +12 -14
- package/docs/examples/claude-desktop-config.md +1 -1
- package/docs/examples/docker-production.md +100 -93
- package/docs/examples/multi-site-setup.md +5 -4
- package/docs/examples/single-site-setup.md +3 -4
- package/docs/examples/use-case-workflows.md +4 -5
- package/docs/integrations/claude-desktop.md +31 -31
- package/docs/integrations/cline.md +4 -4
- package/docs/integrations/vs-code.md +9 -8
- package/docs/user-guides/SMITHERY_SETUP.md +10 -10
- package/package.json +44 -25
- package/src/cache/CacheInvalidation.ts +12 -5
- package/src/cache/CacheManager.ts +18 -15
- package/src/cache/HttpCacheWrapper.ts +30 -59
- package/src/cache/__tests__/HttpCacheWrapper.test.ts +6 -5
- package/src/cache/index.ts +3 -14
- package/src/client/CachedWordPressClient.ts +32 -30
- package/src/client/MockWordPressClient.ts +4 -2
- package/src/client/api.ts +186 -64
- package/src/client/auth.ts +15 -40
- package/src/client/managers/AuthenticationManager.ts +337 -77
- package/src/client/managers/BaseManager.ts +18 -30
- package/src/client/managers/RequestManager.ts +39 -44
- package/src/config/Config.ts +308 -0
- package/src/config/ConfigurationSchema.ts +23 -2
- package/src/config/ServerConfiguration.ts +51 -47
- package/src/docs/DocumentationGenerator.ts +50 -39
- package/src/docs/MarkdownFormatter.ts +19 -29
- package/src/dxt-entry.cjs +26 -16
- package/src/dxt-entry.ts +17 -27
- package/src/index.ts +42 -28
- package/src/performance/MetricsCollector.ts +108 -86
- package/src/performance/PerformanceAnalytics.ts +69 -164
- package/src/performance/PerformanceMonitor.ts +32 -47
- package/src/performance/index.ts +2 -10
- package/src/security/AISecurityScanner.ts +22 -12
- package/src/security/AutomatedRemediation.ts +49 -18
- package/src/security/InputValidator.ts +9 -6
- package/src/security/SecurityCIPipeline.ts +53 -37
- package/src/security/SecurityConfig.ts +22 -22
- package/src/security/SecurityConfigManager.ts +23 -19
- package/src/security/SecurityMonitoring.ts +24 -21
- package/src/security/SecurityReviewer.ts +10 -7
- package/src/security/index.ts +64 -29
- package/src/server/ConnectionTester.ts +120 -31
- package/src/server/ToolRegistry.ts +31 -21
- package/src/tools/BaseToolManager.ts +286 -33
- package/src/tools/auth.ts +20 -8
- package/src/tools/cache.ts +5 -15
- package/src/tools/comments.ts +34 -48
- package/src/tools/media.ts +41 -53
- package/src/tools/pages.ts +32 -54
- package/src/tools/performance.ts +141 -176
- package/src/tools/posts/PostHandlers.ts +474 -0
- package/src/tools/posts/PostToolDefinitions.ts +250 -0
- package/src/tools/posts/index.ts +192 -0
- package/src/tools/posts.ts +24 -780
- package/src/tools/site.ts +34 -19
- package/src/tools/taxonomies.ts +41 -57
- package/src/tools/users.ts +28 -16
- package/src/types/client.ts +114 -138
- package/src/types/enhanced.ts +318 -0
- package/src/types/index.ts +51 -30
- package/src/types/mcp.ts +20 -42
- package/src/types/requests.ts +378 -0
- package/src/types/tools.ts +608 -0
- package/src/types/wordpress.ts +56 -34
- package/src/utils/debug.ts +77 -59
- package/src/utils/enhancedError.ts +8 -8
- package/src/utils/error.ts +53 -31
- package/src/utils/logger.ts +351 -0
- package/src/utils/streaming.ts +86 -68
- package/src/utils/toolWrapper.ts +10 -12
- package/src/utils/validation/core.ts +108 -0
- package/src/utils/validation/index.ts +36 -0
- package/src/utils/validation/network.ts +132 -0
- package/src/utils/validation/rateLimit.ts +54 -0
- package/src/utils/validation/security.ts +361 -0
- package/src/utils/validation/wordpress.ts +180 -0
- package/src/utils/validation.ts +47 -470
package/src/tools/performance.ts
CHANGED
|
@@ -2,12 +2,21 @@
|
|
|
2
2
|
* Performance Monitoring MCP Tools for WordPress Server
|
|
3
3
|
* Provides comprehensive performance insights and management
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Performance Monitoring MCP Tools for WordPress Server
|
|
7
|
+
* Provides comprehensive performance insights and management
|
|
8
|
+
*/
|
|
5
9
|
|
|
6
10
|
import type { ToolDefinition } from "../server/ToolRegistry.js";
|
|
7
|
-
import { PerformanceMonitor } from "../performance/PerformanceMonitor.js";
|
|
11
|
+
import { PerformanceMonitor, type PerformanceMetrics, type PerformanceAlert } from "../performance/PerformanceMonitor.js";
|
|
8
12
|
import { MetricsCollector } from "../performance/MetricsCollector.js";
|
|
9
|
-
import { PerformanceAnalytics } from "../performance/PerformanceAnalytics.js";
|
|
13
|
+
import { PerformanceAnalytics, type BenchmarkComparison, type PerformanceAnomaly } from "../performance/PerformanceAnalytics.js";
|
|
10
14
|
import { toolWrapper } from "../utils/toolWrapper.js";
|
|
15
|
+
import { ConfigHelpers } from "../config/Config.js";
|
|
16
|
+
import { LoggerFactory } from "../utils/logger.js";
|
|
17
|
+
import type { WordPressClient } from "../client/api.js";
|
|
18
|
+
|
|
19
|
+
// Using existing performance interfaces from PerformanceMonitor/PerformanceAnalytics
|
|
11
20
|
|
|
12
21
|
/**
|
|
13
22
|
* Performance Tools Class
|
|
@@ -16,8 +25,10 @@ export default class PerformanceTools {
|
|
|
16
25
|
private monitor: PerformanceMonitor;
|
|
17
26
|
private collector: MetricsCollector;
|
|
18
27
|
private analytics: PerformanceAnalytics;
|
|
28
|
+
private logger = LoggerFactory.performance();
|
|
29
|
+
private historicalDataInterval?: NodeJS.Timeout | undefined;
|
|
19
30
|
|
|
20
|
-
constructor(clients?: Map<string,
|
|
31
|
+
constructor(clients?: Map<string, unknown>) {
|
|
21
32
|
// Initialize performance monitoring system
|
|
22
33
|
this.monitor = new PerformanceMonitor({
|
|
23
34
|
enableRealTimeMonitoring: true,
|
|
@@ -43,14 +54,17 @@ export default class PerformanceTools {
|
|
|
43
54
|
this.collector.registerClient(siteId, client);
|
|
44
55
|
|
|
45
56
|
// Register cache manager if client has one
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
const possibleCacheMgr = (client as Record<string, unknown>)?.cacheManager as unknown;
|
|
58
|
+
if (possibleCacheMgr) {
|
|
59
|
+
this.collector.registerCacheManager(siteId, possibleCacheMgr);
|
|
48
60
|
}
|
|
49
61
|
}
|
|
50
62
|
}
|
|
51
63
|
|
|
52
|
-
//
|
|
53
|
-
|
|
64
|
+
// Only start historical data collection in production environments
|
|
65
|
+
if (ConfigHelpers.isProd() || ConfigHelpers.isDev()) {
|
|
66
|
+
this.startHistoricalDataCollection();
|
|
67
|
+
}
|
|
54
68
|
}
|
|
55
69
|
|
|
56
70
|
/**
|
|
@@ -65,22 +79,19 @@ export default class PerformanceTools {
|
|
|
65
79
|
{
|
|
66
80
|
name: "site",
|
|
67
81
|
type: "string",
|
|
68
|
-
description:
|
|
69
|
-
"Specific site ID for multi-site setups (optional for single site)",
|
|
82
|
+
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
70
83
|
required: false,
|
|
71
84
|
},
|
|
72
85
|
{
|
|
73
86
|
name: "category",
|
|
74
87
|
type: "string",
|
|
75
|
-
description:
|
|
76
|
-
"Category of metrics to return (overview, requests, cache, system, tools, all)",
|
|
88
|
+
description: "Category of metrics to return (overview, requests, cache, system, tools, all)",
|
|
77
89
|
required: false,
|
|
78
90
|
},
|
|
79
91
|
{
|
|
80
92
|
name: "format",
|
|
81
93
|
type: "string",
|
|
82
|
-
description:
|
|
83
|
-
"Detail level of the response (summary, detailed, raw)",
|
|
94
|
+
description: "Detail level of the response (summary, detailed, raw)",
|
|
84
95
|
required: false,
|
|
85
96
|
},
|
|
86
97
|
],
|
|
@@ -93,15 +104,13 @@ export default class PerformanceTools {
|
|
|
93
104
|
{
|
|
94
105
|
name: "site",
|
|
95
106
|
type: "string",
|
|
96
|
-
description:
|
|
97
|
-
"Specific site ID for multi-site setups (optional for single site)",
|
|
107
|
+
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
98
108
|
required: false,
|
|
99
109
|
},
|
|
100
110
|
{
|
|
101
111
|
name: "timeframe",
|
|
102
112
|
type: "string",
|
|
103
|
-
description:
|
|
104
|
-
"Time period for historical data (1h, 6h, 12h, 24h, 7d)",
|
|
113
|
+
description: "Time period for historical data (1h, 6h, 12h, 24h, 7d)",
|
|
105
114
|
required: false,
|
|
106
115
|
},
|
|
107
116
|
{
|
|
@@ -127,15 +136,13 @@ export default class PerformanceTools {
|
|
|
127
136
|
{
|
|
128
137
|
name: "site",
|
|
129
138
|
type: "string",
|
|
130
|
-
description:
|
|
131
|
-
"Specific site ID for multi-site setups (optional for single site)",
|
|
139
|
+
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
132
140
|
required: false,
|
|
133
141
|
},
|
|
134
142
|
{
|
|
135
143
|
name: "category",
|
|
136
144
|
type: "string",
|
|
137
|
-
description:
|
|
138
|
-
"Benchmark category (response_time, cache_performance, error_rate, system_resources, all)",
|
|
145
|
+
description: "Benchmark category (response_time, cache_performance, error_rate, system_resources, all)",
|
|
139
146
|
required: false,
|
|
140
147
|
},
|
|
141
148
|
{
|
|
@@ -154,22 +161,19 @@ export default class PerformanceTools {
|
|
|
154
161
|
{
|
|
155
162
|
name: "site",
|
|
156
163
|
type: "string",
|
|
157
|
-
description:
|
|
158
|
-
"Specific site ID for multi-site setups (optional for single site)",
|
|
164
|
+
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
159
165
|
required: false,
|
|
160
166
|
},
|
|
161
167
|
{
|
|
162
168
|
name: "severity",
|
|
163
169
|
type: "string",
|
|
164
|
-
description:
|
|
165
|
-
"Filter alerts by severity level (info, warning, error, critical)",
|
|
170
|
+
description: "Filter alerts by severity level (info, warning, error, critical)",
|
|
166
171
|
required: false,
|
|
167
172
|
},
|
|
168
173
|
{
|
|
169
174
|
name: "category",
|
|
170
175
|
type: "string",
|
|
171
|
-
description:
|
|
172
|
-
"Filter alerts by category (performance, cache, system, wordpress)",
|
|
176
|
+
description: "Filter alerts by category (performance, cache, system, wordpress)",
|
|
173
177
|
required: false,
|
|
174
178
|
},
|
|
175
179
|
{
|
|
@@ -194,22 +198,19 @@ export default class PerformanceTools {
|
|
|
194
198
|
{
|
|
195
199
|
name: "site",
|
|
196
200
|
type: "string",
|
|
197
|
-
description:
|
|
198
|
-
"Specific site ID for multi-site setups (optional for single site)",
|
|
201
|
+
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
199
202
|
required: false,
|
|
200
203
|
},
|
|
201
204
|
{
|
|
202
205
|
name: "focus",
|
|
203
206
|
type: "string",
|
|
204
|
-
description:
|
|
205
|
-
"Optimization focus area (speed, reliability, efficiency, scaling)",
|
|
207
|
+
description: "Optimization focus area (speed, reliability, efficiency, scaling)",
|
|
206
208
|
required: false,
|
|
207
209
|
},
|
|
208
210
|
{
|
|
209
211
|
name: "priority",
|
|
210
212
|
type: "string",
|
|
211
|
-
description:
|
|
212
|
-
"Implementation timeline (quick_wins, medium_term, long_term, all)",
|
|
213
|
+
description: "Implementation timeline (quick_wins, medium_term, long_term, all)",
|
|
213
214
|
required: false,
|
|
214
215
|
},
|
|
215
216
|
{
|
|
@@ -234,8 +235,7 @@ export default class PerformanceTools {
|
|
|
234
235
|
{
|
|
235
236
|
name: "site",
|
|
236
237
|
type: "string",
|
|
237
|
-
description:
|
|
238
|
-
"Specific site ID for multi-site setups (optional for single site)",
|
|
238
|
+
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
239
239
|
required: false,
|
|
240
240
|
},
|
|
241
241
|
{
|
|
@@ -271,21 +271,21 @@ export default class PerformanceTools {
|
|
|
271
271
|
/**
|
|
272
272
|
* Get real-time performance statistics
|
|
273
273
|
*/
|
|
274
|
-
private async getPerformanceStats(params:
|
|
274
|
+
private async getPerformanceStats(_client: WordPressClient, params: Record<string, unknown>): Promise<unknown> {
|
|
275
275
|
return toolWrapper(async () => {
|
|
276
|
-
const { site, category = "overview", format = "summary" } = params;
|
|
276
|
+
const { site, category = "overview", format = "summary" } = params as { site?: string; category?: string; format?: string };
|
|
277
277
|
|
|
278
278
|
// Get current metrics
|
|
279
|
-
|
|
279
|
+
const metrics = this.collector.collectCurrentMetrics();
|
|
280
280
|
|
|
281
281
|
// Get site-specific metrics if requested
|
|
282
282
|
let siteMetrics = null;
|
|
283
283
|
if (site) {
|
|
284
|
-
|
|
284
|
+
siteMetrics = this.collector.getSiteMetrics(site as string);
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
// Filter by category
|
|
288
|
-
const result:
|
|
288
|
+
const result: Record<string, unknown> = {};
|
|
289
289
|
|
|
290
290
|
if (category === "overview" || category === "all") {
|
|
291
291
|
result.overview = {
|
|
@@ -331,15 +331,14 @@ export default class PerformanceTools {
|
|
|
331
331
|
result.tools = {
|
|
332
332
|
mostUsedTool: metrics.tools.mostUsedTool,
|
|
333
333
|
totalToolCalls: Object.values(metrics.tools.toolUsageCount).reduce(
|
|
334
|
-
(sum: number, count:
|
|
334
|
+
(sum: number, count: unknown) => sum + (typeof count === "number" ? count : 0),
|
|
335
335
|
0,
|
|
336
336
|
),
|
|
337
337
|
topTools: Object.entries(metrics.tools.toolUsageCount)
|
|
338
338
|
.sort(([, a], [, b]) => (b as number) - (a as number))
|
|
339
339
|
.slice(0, 5)
|
|
340
340
|
.map(([tool, count]) => ({ tool, count })),
|
|
341
|
-
toolPerformance:
|
|
342
|
-
format === "detailed" ? metrics.tools.toolPerformance : undefined,
|
|
341
|
+
toolPerformance: format === "detailed" ? metrics.tools.toolPerformance : undefined,
|
|
343
342
|
};
|
|
344
343
|
}
|
|
345
344
|
|
|
@@ -371,42 +370,32 @@ export default class PerformanceTools {
|
|
|
371
370
|
/**
|
|
372
371
|
* Get historical performance data and trends
|
|
373
372
|
*/
|
|
374
|
-
private async getPerformanceHistory(params:
|
|
373
|
+
private async getPerformanceHistory(_client: WordPressClient, params: Record<string, unknown>): Promise<unknown> {
|
|
375
374
|
return toolWrapper(async () => {
|
|
376
|
-
const {
|
|
377
|
-
site,
|
|
378
|
-
timeframe = "24h",
|
|
379
|
-
metrics: requestedMetrics,
|
|
380
|
-
includeTrends = true,
|
|
381
|
-
} = params;
|
|
375
|
+
const { site, timeframe = "24h", metrics: requestedMetrics, includeTrends = true } = params as { site?: string; timeframe?: string; metrics?: string[]; includeTrends?: boolean };
|
|
382
376
|
|
|
383
377
|
// Convert timeframe to milliseconds
|
|
384
378
|
const timeframMs = this.parseTimeframe(timeframe);
|
|
385
379
|
const startTime = Date.now() - timeframMs;
|
|
386
380
|
|
|
387
381
|
// Get historical data
|
|
388
|
-
|
|
382
|
+
const historicalData = this.monitor.getHistoricalData(startTime);
|
|
389
383
|
|
|
390
384
|
// Analyze trends if requested
|
|
391
385
|
let trends = null;
|
|
392
386
|
if (includeTrends) {
|
|
393
387
|
// Add current data for trend analysis
|
|
394
|
-
|
|
388
|
+
this.analytics.addDataPoint(this.collector.collectCurrentMetrics());
|
|
395
389
|
trends = this.analytics.analyzeTrends();
|
|
396
390
|
|
|
397
391
|
// Filter trends by requested metrics
|
|
398
392
|
if (requestedMetrics && Array.isArray(requestedMetrics)) {
|
|
399
|
-
trends = trends.filter((trend) =>
|
|
400
|
-
requestedMetrics.includes(trend.metric),
|
|
401
|
-
);
|
|
393
|
+
trends = trends.filter((trend) => requestedMetrics.includes(trend.metric));
|
|
402
394
|
}
|
|
403
395
|
}
|
|
404
396
|
|
|
405
397
|
// Process historical data for charting
|
|
406
|
-
|
|
407
|
-
historicalData,
|
|
408
|
-
requestedMetrics,
|
|
409
|
-
);
|
|
398
|
+
const chartData = this.processHistoricalDataForChart(historicalData, requestedMetrics as string[] | undefined);
|
|
410
399
|
|
|
411
400
|
return {
|
|
412
401
|
success: true,
|
|
@@ -416,21 +405,12 @@ export default class PerformanceTools {
|
|
|
416
405
|
historicalData: chartData,
|
|
417
406
|
trends: trends || [],
|
|
418
407
|
summary: {
|
|
419
|
-
averageResponseTime: this.calculateAverage(
|
|
420
|
-
|
|
421
|
-
),
|
|
422
|
-
averageCacheHitRate: this.calculateAverage(
|
|
423
|
-
historicalData.map((d) => d.cache.hitRate),
|
|
424
|
-
),
|
|
408
|
+
averageResponseTime: this.calculateAverage(historicalData.map((d) => d.requests.averageResponseTime)),
|
|
409
|
+
averageCacheHitRate: this.calculateAverage(historicalData.map((d) => d.cache.hitRate)),
|
|
425
410
|
averageErrorRate: this.calculateAverage(
|
|
426
|
-
historicalData.map((d) =>
|
|
427
|
-
d.requests.total > 0 ? d.requests.failed / d.requests.total : 0,
|
|
428
|
-
),
|
|
429
|
-
),
|
|
430
|
-
totalRequests: historicalData.reduce(
|
|
431
|
-
(sum, d) => sum + d.requests.total,
|
|
432
|
-
0,
|
|
411
|
+
historicalData.map((d) => (d.requests.total > 0 ? d.requests.failed / d.requests.total : 0)),
|
|
433
412
|
),
|
|
413
|
+
totalRequests: historicalData.reduce((sum, d) => sum + d.requests.total, 0),
|
|
434
414
|
},
|
|
435
415
|
metadata: {
|
|
436
416
|
timestamp: new Date().toISOString(),
|
|
@@ -445,12 +425,12 @@ export default class PerformanceTools {
|
|
|
445
425
|
/**
|
|
446
426
|
* Get benchmark comparison
|
|
447
427
|
*/
|
|
448
|
-
private async getBenchmarkComparison(params:
|
|
428
|
+
private async getBenchmarkComparison(_client: WordPressClient, params: Record<string, unknown>): Promise<unknown> {
|
|
449
429
|
return toolWrapper(async () => {
|
|
450
|
-
const { site, category = "all", includeRecommendations = true } = params;
|
|
430
|
+
const { site, category = "all", includeRecommendations = true } = params as { site?: string; category?: string; includeRecommendations?: boolean };
|
|
451
431
|
|
|
452
432
|
// Get benchmark comparisons
|
|
453
|
-
|
|
433
|
+
const benchmarks = this.analytics.benchmarkPerformance() as BenchmarkComparison[];
|
|
454
434
|
|
|
455
435
|
// Filter by category if specified
|
|
456
436
|
let filteredBenchmarks = benchmarks;
|
|
@@ -461,11 +441,9 @@ export default class PerformanceTools {
|
|
|
461
441
|
error_rate: "Error Rate",
|
|
462
442
|
system_resources: "Memory Usage",
|
|
463
443
|
};
|
|
464
|
-
|
|
444
|
+
const targetCategory = categoryMap[category as string];
|
|
465
445
|
if (targetCategory) {
|
|
466
|
-
filteredBenchmarks = benchmarks.filter(
|
|
467
|
-
(b) => b.category === targetCategory,
|
|
468
|
-
);
|
|
446
|
+
filteredBenchmarks = benchmarks.filter((b) => b.category === targetCategory);
|
|
469
447
|
}
|
|
470
448
|
}
|
|
471
449
|
|
|
@@ -494,8 +472,7 @@ export default class PerformanceTools {
|
|
|
494
472
|
benchmark.improvement > 0
|
|
495
473
|
? {
|
|
496
474
|
needed: benchmark.improvement,
|
|
497
|
-
description:
|
|
498
|
-
this.getBenchmarkImprovementDescription(benchmark),
|
|
475
|
+
description: this.getBenchmarkImprovementDescription(benchmark),
|
|
499
476
|
}
|
|
500
477
|
: null,
|
|
501
478
|
})),
|
|
@@ -515,18 +492,12 @@ export default class PerformanceTools {
|
|
|
515
492
|
/**
|
|
516
493
|
* Get performance alerts and anomalies
|
|
517
494
|
*/
|
|
518
|
-
private async getPerformanceAlerts(params:
|
|
495
|
+
private async getPerformanceAlerts(_client: WordPressClient, params: Record<string, unknown>): Promise<unknown> {
|
|
519
496
|
return toolWrapper(async () => {
|
|
520
|
-
const {
|
|
521
|
-
site,
|
|
522
|
-
severity,
|
|
523
|
-
category,
|
|
524
|
-
limit = 20,
|
|
525
|
-
includeAnomalies = true,
|
|
526
|
-
} = params;
|
|
497
|
+
const { site, severity, category, limit = 20, includeAnomalies = true } = params as { site?: string; severity?: string; category?: string; limit?: number; includeAnomalies?: boolean };
|
|
527
498
|
|
|
528
499
|
// Get alerts from monitor
|
|
529
|
-
|
|
500
|
+
let alerts = this.monitor.getAlerts(severity) as PerformanceAlert[];
|
|
530
501
|
|
|
531
502
|
// Filter by category if specified
|
|
532
503
|
if (category) {
|
|
@@ -534,12 +505,12 @@ export default class PerformanceTools {
|
|
|
534
505
|
}
|
|
535
506
|
|
|
536
507
|
// Limit results
|
|
537
|
-
|
|
508
|
+
alerts = alerts.slice(-(limit as number));
|
|
538
509
|
|
|
539
510
|
// Get anomalies if requested
|
|
540
|
-
let anomalies:
|
|
511
|
+
let anomalies: PerformanceAnomaly[] = [];
|
|
541
512
|
if (includeAnomalies) {
|
|
542
|
-
anomalies = this.analytics.getAnomalies(severity);
|
|
513
|
+
anomalies = this.analytics.getAnomalies(severity) as PerformanceAnomaly[];
|
|
543
514
|
}
|
|
544
515
|
|
|
545
516
|
// Calculate alert summary
|
|
@@ -575,10 +546,7 @@ export default class PerformanceTools {
|
|
|
575
546
|
summary: {
|
|
576
547
|
alerts: alertSummary,
|
|
577
548
|
anomalies: anomalySummary,
|
|
578
|
-
overallStatus: this.calculateAlertStatus(
|
|
579
|
-
alertSummary,
|
|
580
|
-
anomalySummary,
|
|
581
|
-
),
|
|
549
|
+
overallStatus: this.calculateAlertStatus(alertSummary, anomalySummary),
|
|
582
550
|
},
|
|
583
551
|
metadata: {
|
|
584
552
|
timestamp: new Date().toISOString(),
|
|
@@ -593,21 +561,15 @@ export default class PerformanceTools {
|
|
|
593
561
|
/**
|
|
594
562
|
* Get optimization recommendations
|
|
595
563
|
*/
|
|
596
|
-
private async getOptimizationRecommendations(params:
|
|
564
|
+
private async getOptimizationRecommendations(_client: WordPressClient, params: Record<string, unknown>): Promise<unknown> {
|
|
597
565
|
return toolWrapper(async () => {
|
|
598
|
-
const {
|
|
599
|
-
site,
|
|
600
|
-
focus = "speed",
|
|
601
|
-
priority = "all",
|
|
602
|
-
includeROI = true,
|
|
603
|
-
includePredictions = true,
|
|
604
|
-
} = params;
|
|
566
|
+
const { site, focus = "speed", priority = "all", includeROI = true, includePredictions = true } = params as { site?: string; focus?: string; priority?: string; includeROI?: boolean; includePredictions?: boolean };
|
|
605
567
|
|
|
606
568
|
// Generate optimization plan
|
|
607
569
|
const optimizationPlan = this.analytics.generateOptimizationPlan();
|
|
608
570
|
|
|
609
571
|
// Filter by priority
|
|
610
|
-
|
|
572
|
+
let recommendations: Array<{ priority: string; impact: string; implementationEffort: string; [key: string]: unknown }> = [];
|
|
611
573
|
if (priority === "quick_wins" || priority === "all") {
|
|
612
574
|
recommendations.push(
|
|
613
575
|
...optimizationPlan.quickWins.map((r) => ({
|
|
@@ -634,20 +596,18 @@ export default class PerformanceTools {
|
|
|
634
596
|
}
|
|
635
597
|
|
|
636
598
|
// Filter by focus area
|
|
637
|
-
|
|
599
|
+
if (focus !== "speed") {
|
|
638
600
|
const focusMap: Record<string, string[]> = {
|
|
639
601
|
reliability: ["reliability"],
|
|
640
602
|
efficiency: ["cost", "performance"],
|
|
641
603
|
scaling: ["performance", "reliability"],
|
|
642
604
|
};
|
|
643
605
|
const targetImpacts = focusMap[focus] || [];
|
|
644
|
-
recommendations = recommendations.filter((r) =>
|
|
645
|
-
targetImpacts.includes(r.impact),
|
|
646
|
-
);
|
|
606
|
+
recommendations = recommendations.filter((r) => targetImpacts.includes(r.impact));
|
|
647
607
|
}
|
|
648
608
|
|
|
649
609
|
// Get predictions if requested
|
|
650
|
-
|
|
610
|
+
let predictions: Record<string, unknown> | null = null;
|
|
651
611
|
if (includePredictions) {
|
|
652
612
|
predictions = this.analytics.predictPerformance(60); // 1 hour prediction
|
|
653
613
|
}
|
|
@@ -683,21 +643,15 @@ export default class PerformanceTools {
|
|
|
683
643
|
/**
|
|
684
644
|
* Export comprehensive performance report
|
|
685
645
|
*/
|
|
686
|
-
private async exportPerformanceReport(params:
|
|
646
|
+
private async exportPerformanceReport(_client: WordPressClient, params: Record<string, unknown>): Promise<unknown> {
|
|
687
647
|
return toolWrapper(async () => {
|
|
688
|
-
const {
|
|
689
|
-
site,
|
|
690
|
-
format = "json",
|
|
691
|
-
includeHistorical = true,
|
|
692
|
-
includeAnalytics = true,
|
|
693
|
-
timeRange = "24h",
|
|
694
|
-
} = params;
|
|
648
|
+
const { site, format = "json", includeHistorical = true, includeAnalytics = true, timeRange = "24h" } = params as { site?: string; format?: string; includeHistorical?: boolean; includeAnalytics?: boolean; timeRange?: string };
|
|
695
649
|
|
|
696
650
|
// Generate comprehensive analytics report
|
|
697
651
|
const report = this.analytics.exportAnalyticsReport();
|
|
698
652
|
|
|
699
653
|
// Add additional data based on parameters
|
|
700
|
-
|
|
654
|
+
const exportData: { currentMetrics: PerformanceMetrics; [key: string]: unknown } = {
|
|
701
655
|
metadata: {
|
|
702
656
|
generatedAt: new Date().toISOString(),
|
|
703
657
|
site: site || "all",
|
|
@@ -706,7 +660,7 @@ export default class PerformanceTools {
|
|
|
706
660
|
version: "1.0.0",
|
|
707
661
|
},
|
|
708
662
|
summary: report.summary,
|
|
709
|
-
|
|
663
|
+
currentMetrics: this.collector.collectCurrentMetrics(),
|
|
710
664
|
};
|
|
711
665
|
|
|
712
666
|
if (includeHistorical) {
|
|
@@ -738,7 +692,7 @@ export default class PerformanceTools {
|
|
|
738
692
|
}
|
|
739
693
|
|
|
740
694
|
// Format output based on requested format
|
|
741
|
-
let formattedOutput:
|
|
695
|
+
let formattedOutput: unknown;
|
|
742
696
|
if (format === "csv") {
|
|
743
697
|
formattedOutput = this.convertToCSV(exportData);
|
|
744
698
|
} else if (format === "summary") {
|
|
@@ -762,14 +716,13 @@ export default class PerformanceTools {
|
|
|
762
716
|
|
|
763
717
|
// Helper methods
|
|
764
718
|
|
|
765
|
-
private calculateHealthStatus(metrics:
|
|
719
|
+
private calculateHealthStatus(metrics: PerformanceMetrics): string {
|
|
766
720
|
let score = 100;
|
|
767
721
|
|
|
768
722
|
if (metrics.requests.averageResponseTime > 2000) score -= 30;
|
|
769
723
|
else if (metrics.requests.averageResponseTime > 1000) score -= 15;
|
|
770
724
|
|
|
771
|
-
const errorRate =
|
|
772
|
-
metrics.requests.failed / Math.max(metrics.requests.total, 1);
|
|
725
|
+
const errorRate = metrics.requests.failed / Math.max(metrics.requests.total, 1);
|
|
773
726
|
if (errorRate > 0.05) score -= 30;
|
|
774
727
|
else if (errorRate > 0.02) score -= 15;
|
|
775
728
|
|
|
@@ -785,7 +738,7 @@ export default class PerformanceTools {
|
|
|
785
738
|
return "Critical";
|
|
786
739
|
}
|
|
787
740
|
|
|
788
|
-
private calculatePerformanceScore(metrics:
|
|
741
|
+
private calculatePerformanceScore(metrics: PerformanceMetrics): number {
|
|
789
742
|
let score = 100;
|
|
790
743
|
|
|
791
744
|
// Response time scoring
|
|
@@ -794,8 +747,7 @@ export default class PerformanceTools {
|
|
|
794
747
|
else if (metrics.requests.averageResponseTime > 800) score -= 10;
|
|
795
748
|
|
|
796
749
|
// Error rate scoring
|
|
797
|
-
const errorRate =
|
|
798
|
-
metrics.requests.failed / Math.max(metrics.requests.total, 1);
|
|
750
|
+
const errorRate = metrics.requests.failed / Math.max(metrics.requests.total, 1);
|
|
799
751
|
if (errorRate > 0.1) score -= 30;
|
|
800
752
|
else if (errorRate > 0.05) score -= 20;
|
|
801
753
|
else if (errorRate > 0.02) score -= 10;
|
|
@@ -812,11 +764,9 @@ export default class PerformanceTools {
|
|
|
812
764
|
return Math.max(0, Math.min(100, score));
|
|
813
765
|
}
|
|
814
766
|
|
|
815
|
-
private calculateCacheEfficiency(cacheMetrics:
|
|
767
|
+
private calculateCacheEfficiency(cacheMetrics: PerformanceMetrics["cache"]): string {
|
|
816
768
|
const efficiency =
|
|
817
|
-
cacheMetrics.hitRate * 100 +
|
|
818
|
-
(cacheMetrics.totalSize > 0 ? 10 : 0) -
|
|
819
|
-
(cacheMetrics.evictions > 100 ? 10 : 0);
|
|
769
|
+
cacheMetrics.hitRate * 100 + (cacheMetrics.totalSize > 0 ? 10 : 0) - (cacheMetrics.evictions > 100 ? 10 : 0);
|
|
820
770
|
|
|
821
771
|
if (efficiency >= 95) return "Excellent";
|
|
822
772
|
if (efficiency >= 85) return "Good";
|
|
@@ -848,22 +798,13 @@ export default class PerformanceTools {
|
|
|
848
798
|
return map[timeframe] || map["24h"];
|
|
849
799
|
}
|
|
850
800
|
|
|
851
|
-
private processHistoricalDataForChart(
|
|
852
|
-
data: any[],
|
|
853
|
-
requestedMetrics?: string[],
|
|
854
|
-
): any {
|
|
801
|
+
private processHistoricalDataForChart(data: PerformanceMetrics[], requestedMetrics?: string[]): Record<string, unknown> {
|
|
855
802
|
if (!data.length) return {};
|
|
856
803
|
|
|
857
|
-
const allMetrics = [
|
|
858
|
-
"responseTime",
|
|
859
|
-
"cacheHitRate",
|
|
860
|
-
"errorRate",
|
|
861
|
-
"memoryUsage",
|
|
862
|
-
"requestVolume",
|
|
863
|
-
];
|
|
804
|
+
const allMetrics = ["responseTime", "cacheHitRate", "errorRate", "memoryUsage", "requestVolume"];
|
|
864
805
|
const metricsToProcess = requestedMetrics || allMetrics;
|
|
865
806
|
|
|
866
|
-
const result:
|
|
807
|
+
const result: Record<string, unknown> = {};
|
|
867
808
|
|
|
868
809
|
for (const metric of metricsToProcess) {
|
|
869
810
|
result[metric] = data.map((point, index) => ({
|
|
@@ -876,17 +817,14 @@ export default class PerformanceTools {
|
|
|
876
817
|
return result;
|
|
877
818
|
}
|
|
878
819
|
|
|
879
|
-
private extractMetricValue(dataPoint:
|
|
820
|
+
private extractMetricValue(dataPoint: PerformanceMetrics, metric: string): number {
|
|
880
821
|
switch (metric) {
|
|
881
822
|
case "responseTime":
|
|
882
823
|
return dataPoint.requests.averageResponseTime;
|
|
883
824
|
case "cacheHitRate":
|
|
884
825
|
return dataPoint.cache.hitRate * 100;
|
|
885
826
|
case "errorRate":
|
|
886
|
-
return (
|
|
887
|
-
(dataPoint.requests.failed / Math.max(dataPoint.requests.total, 1)) *
|
|
888
|
-
100
|
|
889
|
-
);
|
|
827
|
+
return (dataPoint.requests.failed / Math.max(dataPoint.requests.total, 1)) * 100;
|
|
890
828
|
case "memoryUsage":
|
|
891
829
|
return dataPoint.system.memoryUsage;
|
|
892
830
|
case "requestVolume":
|
|
@@ -912,19 +850,17 @@ export default class PerformanceTools {
|
|
|
912
850
|
return statusMap[status] || status;
|
|
913
851
|
}
|
|
914
852
|
|
|
915
|
-
private getBenchmarkImprovementDescription(benchmark:
|
|
853
|
+
private getBenchmarkImprovementDescription(benchmark: BenchmarkComparison): string {
|
|
916
854
|
const improvements: Record<string, string> = {
|
|
917
855
|
"Response Time": `Reduce by ${benchmark.improvement.toFixed(0)}ms`,
|
|
918
856
|
"Cache Hit Rate": `Increase by ${benchmark.improvement.toFixed(1)}%`,
|
|
919
857
|
"Error Rate": `Reduce by ${benchmark.improvement.toFixed(2)}%`,
|
|
920
858
|
"Memory Usage": `Reduce by ${benchmark.improvement.toFixed(0)}%`,
|
|
921
859
|
};
|
|
922
|
-
return
|
|
923
|
-
improvements[benchmark.category] || `Improve by ${benchmark.improvement}`
|
|
924
|
-
);
|
|
860
|
+
return improvements[benchmark.category] || `Improve by ${benchmark.improvement}`;
|
|
925
861
|
}
|
|
926
862
|
|
|
927
|
-
private calculateOverallRanking(benchmarks:
|
|
863
|
+
private calculateOverallRanking(benchmarks: BenchmarkComparison[]): {
|
|
928
864
|
percentile: number;
|
|
929
865
|
status: string;
|
|
930
866
|
} {
|
|
@@ -932,8 +868,7 @@ export default class PerformanceTools {
|
|
|
932
868
|
const excellentCount = statuses.filter((s) => s === "excellent").length;
|
|
933
869
|
const goodCount = statuses.filter((s) => s === "good").length;
|
|
934
870
|
|
|
935
|
-
const percentile =
|
|
936
|
-
((excellentCount + goodCount * 0.8) / statuses.length) * 100;
|
|
871
|
+
const percentile = ((excellentCount + goodCount * 0.8) / statuses.length) * 100;
|
|
937
872
|
|
|
938
873
|
let status = "Needs Improvement";
|
|
939
874
|
if (percentile >= 90) status = "Top Performer";
|
|
@@ -943,24 +878,22 @@ export default class PerformanceTools {
|
|
|
943
878
|
return { percentile: Math.round(percentile), status };
|
|
944
879
|
}
|
|
945
880
|
|
|
946
|
-
private formatAlertMessage(alert:
|
|
881
|
+
private formatAlertMessage(alert: PerformanceAlert): string {
|
|
947
882
|
return `${alert.severity.toUpperCase()}: ${alert.message} (${alert.metric}: ${alert.actualValue} vs threshold: ${alert.threshold})`;
|
|
948
883
|
}
|
|
949
884
|
|
|
950
|
-
private formatAnomalyDescription(anomaly:
|
|
951
|
-
const direction =
|
|
952
|
-
anomaly.actualValue > anomaly.expectedValue ? "higher" : "lower";
|
|
885
|
+
private formatAnomalyDescription(anomaly: PerformanceAnomaly): string {
|
|
886
|
+
const direction = anomaly.actualValue > anomaly.expectedValue ? "higher" : "lower";
|
|
953
887
|
return `${anomaly.metric} is ${Math.abs(anomaly.deviation).toFixed(1)}% ${direction} than expected (${anomaly.expectedValue.toFixed(2)} vs ${anomaly.actualValue.toFixed(2)})`;
|
|
954
888
|
}
|
|
955
889
|
|
|
956
|
-
private calculateAlertStatus(alertSummary:
|
|
890
|
+
private calculateAlertStatus(alertSummary: { critical: number; error: number; warning: number }, anomalySummary: { critical: number; major: number; moderate: number; minor: number }): string {
|
|
957
891
|
const critical = alertSummary.critical + anomalySummary.critical;
|
|
958
892
|
const high = alertSummary.error + anomalySummary.major;
|
|
959
893
|
|
|
960
894
|
if (critical > 0) return "Critical Issues Detected";
|
|
961
895
|
if (high > 2) return "High Priority Issues";
|
|
962
|
-
if (alertSummary.warning + anomalySummary.moderate > 5)
|
|
963
|
-
return "Performance Warnings";
|
|
896
|
+
if (alertSummary.warning + anomalySummary.moderate > 5) return "Performance Warnings";
|
|
964
897
|
return "System Healthy";
|
|
965
898
|
}
|
|
966
899
|
|
|
@@ -983,10 +916,10 @@ export default class PerformanceTools {
|
|
|
983
916
|
return map[effort] || effort;
|
|
984
917
|
}
|
|
985
918
|
|
|
986
|
-
private calculateEstimatedImpact(
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
).length;
|
|
919
|
+
private calculateEstimatedImpact(
|
|
920
|
+
recommendations: Array<{ priority: string }>,
|
|
921
|
+
): string {
|
|
922
|
+
const highImpact = recommendations.filter((r) => ["critical", "high"].includes(r.priority)).length;
|
|
990
923
|
const totalImpact = recommendations.length;
|
|
991
924
|
|
|
992
925
|
if (highImpact >= 3) return "Significant Performance Gains Expected";
|
|
@@ -995,7 +928,7 @@ export default class PerformanceTools {
|
|
|
995
928
|
return "System Already Optimized";
|
|
996
929
|
}
|
|
997
930
|
|
|
998
|
-
private convertToCSV(data:
|
|
931
|
+
private convertToCSV(data: { currentMetrics: PerformanceMetrics }): string {
|
|
999
932
|
// Simplified CSV conversion for current metrics
|
|
1000
933
|
const metrics = data.currentMetrics;
|
|
1001
934
|
const csv = [
|
|
@@ -1012,7 +945,7 @@ export default class PerformanceTools {
|
|
|
1012
945
|
return csv.join("\n");
|
|
1013
946
|
}
|
|
1014
947
|
|
|
1015
|
-
private createSummaryReport(data:
|
|
948
|
+
private createSummaryReport(data: { currentMetrics: PerformanceMetrics; analytics?: { insights?: unknown[] } }): Record<string, unknown> {
|
|
1016
949
|
const metrics = data.currentMetrics;
|
|
1017
950
|
return {
|
|
1018
951
|
summary: `Performance Report - ${new Date().toISOString()}`,
|
|
@@ -1024,16 +957,48 @@ export default class PerformanceTools {
|
|
|
1024
957
|
errorRate: `${((metrics.requests.failed / Math.max(metrics.requests.total, 1)) * 100).toFixed(2)}%`,
|
|
1025
958
|
},
|
|
1026
959
|
recommendations: data.analytics?.insights?.slice(0, 3) || [],
|
|
1027
|
-
nextSteps:
|
|
1028
|
-
"Review detailed metrics and implement high-priority optimizations",
|
|
960
|
+
nextSteps: "Review detailed metrics and implement high-priority optimizations",
|
|
1029
961
|
};
|
|
1030
962
|
}
|
|
1031
963
|
|
|
1032
964
|
private startHistoricalDataCollection(): void {
|
|
1033
|
-
//
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
}
|
|
965
|
+
// Skip in test environments to prevent performance issues
|
|
966
|
+
if (ConfigHelpers.isTest() || ConfigHelpers.isCI()) {
|
|
967
|
+
this.logger.debug("Skipping historical data collection in test/CI environment");
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// Adjust collection frequency based on environment
|
|
972
|
+
const interval = ConfigHelpers.isDev() ? 60000 : 30000; // 1 minute in dev, 30 seconds in prod
|
|
973
|
+
|
|
974
|
+
this.logger.info("Starting historical data collection", {
|
|
975
|
+
interval: `${interval / 1000}s`,
|
|
976
|
+
environment: ConfigHelpers.get().get().app.nodeEnv,
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
this.historicalDataInterval = setInterval(() => {
|
|
980
|
+
try {
|
|
981
|
+
const currentMetrics = this.collector.collectCurrentMetrics();
|
|
982
|
+
this.analytics.addDataPoint(currentMetrics);
|
|
983
|
+
this.logger.debug("Historical metrics collected", {
|
|
984
|
+
timestamp: new Date().toISOString(),
|
|
985
|
+
});
|
|
986
|
+
} catch (error) {
|
|
987
|
+
this.logger.error("Failed to collect historical metrics", {
|
|
988
|
+
error: error instanceof Error ? error.message : String(error),
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
}, interval);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* Stop historical data collection and cleanup resources
|
|
996
|
+
*/
|
|
997
|
+
public destroy(): void {
|
|
998
|
+
if (this.historicalDataInterval) {
|
|
999
|
+
clearInterval(this.historicalDataInterval);
|
|
1000
|
+
this.historicalDataInterval = undefined;
|
|
1001
|
+
this.logger.info("Historical data collection stopped");
|
|
1002
|
+
}
|
|
1038
1003
|
}
|
|
1039
1004
|
}
|