mcp-wordpress 2.11.13 → 3.0.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 +14 -29
- package/dist/cache/CacheInvalidation.js.map +1 -1
- package/dist/cache/CacheManager.d.ts +7 -0
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +21 -7
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/HttpCacheWrapper.js.map +1 -1
- package/dist/cache/SEOCacheManager.d.ts.map +1 -1
- package/dist/cache/SEOCacheManager.js +6 -1
- package/dist/cache/SEOCacheManager.js.map +1 -1
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js.map +1 -1
- package/dist/client/CachedWordPressClient.d.ts.map +1 -1
- package/dist/client/CachedWordPressClient.js.map +1 -1
- package/dist/client/MockWordPressClient.d.ts.map +1 -1
- package/dist/client/MockWordPressClient.js.map +1 -1
- package/dist/client/SEOWordPressClient.d.ts.map +1 -1
- package/dist/client/SEOWordPressClient.js.map +1 -1
- package/dist/client/api.d.ts +11 -26
- package/dist/client/api.d.ts.map +1 -1
- package/dist/client/api.js +111 -203
- package/dist/client/api.js.map +1 -1
- package/dist/client/auth.d.ts.map +1 -1
- package/dist/client/auth.js.map +1 -1
- package/dist/client/managers/AuthManager.d.ts.map +1 -1
- package/dist/client/managers/RequestManager.d.ts.map +1 -1
- package/dist/client/managers/RequestManager.js +6 -5
- package/dist/client/managers/RequestManager.js.map +1 -1
- package/dist/client/managers/composed/MigrationAdapter.d.ts +3 -3
- package/dist/client/managers/composed/MigrationAdapter.d.ts.map +1 -1
- package/dist/client/managers/composed/MigrationAdapter.js +2 -2
- package/dist/client/managers/composed/MigrationAdapter.js.map +1 -1
- package/dist/client/managers/composed/index.d.ts +7 -7
- package/dist/client/managers/composed/index.d.ts.map +1 -1
- package/dist/client/managers/composed/index.js +6 -6
- package/dist/client/managers/composed/index.js.map +1 -1
- package/dist/client/managers/implementations/ConfigurationProviderImpl.d.ts +1 -1
- package/dist/client/managers/implementations/ConfigurationProviderImpl.d.ts.map +1 -1
- package/dist/client/managers/implementations/ErrorHandlerImpl.d.ts +1 -1
- package/dist/client/managers/implementations/ErrorHandlerImpl.d.ts.map +1 -1
- package/dist/client/managers/implementations/ParameterValidatorImpl.d.ts +1 -1
- package/dist/client/managers/implementations/ParameterValidatorImpl.d.ts.map +1 -1
- package/dist/client/operations/comments.d.ts +58 -0
- package/dist/client/operations/comments.d.ts.map +1 -0
- package/dist/client/operations/comments.js +74 -0
- package/dist/client/operations/comments.js.map +1 -0
- package/dist/client/operations/index.d.ts +12 -0
- package/dist/client/operations/index.d.ts.map +1 -0
- package/dist/client/operations/index.js +12 -0
- package/dist/client/operations/index.js.map +1 -0
- package/dist/client/operations/media.d.ts +55 -0
- package/dist/client/operations/media.d.ts.map +1 -0
- package/dist/client/operations/media.js +132 -0
- package/dist/client/operations/media.js.map +1 -0
- package/dist/client/operations/pages.d.ts +50 -0
- package/dist/client/operations/pages.d.ts.map +1 -0
- package/dist/client/operations/pages.js +56 -0
- package/dist/client/operations/pages.js.map +1 -0
- package/dist/client/operations/posts.d.ts +50 -0
- package/dist/client/operations/posts.d.ts.map +1 -0
- package/dist/client/operations/posts.js +53 -0
- package/dist/client/operations/posts.js.map +1 -0
- package/dist/client/operations/site.d.ts +60 -0
- package/dist/client/operations/site.d.ts.map +1 -0
- package/dist/client/operations/site.js +83 -0
- package/dist/client/operations/site.js.map +1 -0
- package/dist/client/operations/taxonomies.d.ts +69 -0
- package/dist/client/operations/taxonomies.d.ts.map +1 -0
- package/dist/client/operations/taxonomies.js +87 -0
- package/dist/client/operations/taxonomies.js.map +1 -0
- package/dist/client/operations/users.d.ts +50 -0
- package/dist/client/operations/users.d.ts.map +1 -0
- package/dist/client/operations/users.js +57 -0
- package/dist/client/operations/users.js.map +1 -0
- package/dist/config/ServerConfiguration.d.ts.map +1 -1
- package/dist/config/ServerConfiguration.js.map +1 -1
- package/dist/docs/DocumentationGenerator.js.map +1 -1
- package/dist/performance/MetricsCollector.d.ts.map +1 -1
- package/dist/performance/MetricsCollector.js.map +1 -1
- package/dist/performance/PerformanceMonitor.js.map +1 -1
- package/dist/security/AISecurityScanner.d.ts.map +1 -1
- package/dist/security/AISecurityScanner.js +3 -2
- package/dist/security/AISecurityScanner.js.map +1 -1
- package/dist/security/AutomatedRemediation.js.map +1 -1
- package/dist/security/InputValidator.d.ts.map +1 -1
- package/dist/security/InputValidator.js +30 -18
- package/dist/security/InputValidator.js.map +1 -1
- package/dist/security/SecurityCIPipeline.d.ts +19 -196
- package/dist/security/SecurityCIPipeline.d.ts.map +1 -1
- package/dist/security/SecurityCIPipeline.js +95 -639
- package/dist/security/SecurityCIPipeline.js.map +1 -1
- package/dist/security/SecurityConfig.js.map +1 -1
- package/dist/security/SecurityConfigManager.js.map +1 -1
- package/dist/security/SecurityGateExecutor.d.ts +67 -0
- package/dist/security/SecurityGateExecutor.d.ts.map +1 -0
- package/dist/security/SecurityGateExecutor.js +363 -0
- package/dist/security/SecurityGateExecutor.js.map +1 -0
- package/dist/security/SecurityMonitoring.js.map +1 -1
- package/dist/security/SecurityReportGenerator.d.ts +65 -0
- package/dist/security/SecurityReportGenerator.d.ts.map +1 -0
- package/dist/security/SecurityReportGenerator.js +210 -0
- package/dist/security/SecurityReportGenerator.js.map +1 -0
- package/dist/security/SecurityReviewer.js.map +1 -1
- package/dist/security/SecurityTypes.d.ts +188 -0
- package/dist/security/SecurityTypes.d.ts.map +1 -0
- package/dist/security/SecurityTypes.js +6 -0
- package/dist/security/SecurityTypes.js.map +1 -0
- package/dist/security/index.d.ts +5 -28
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +4 -0
- package/dist/security/index.js.map +1 -1
- package/dist/server/ConnectionTester.d.ts.map +1 -1
- package/dist/server/ConnectionTester.js.map +1 -1
- package/dist/server/ToolRegistry.d.ts.map +1 -1
- package/dist/server/ToolRegistry.js.map +1 -1
- package/dist/tools/BaseToolManager.d.ts.map +1 -1
- package/dist/tools/BaseToolManager.js.map +1 -1
- package/dist/tools/auth.d.ts.map +1 -1
- package/dist/tools/auth.js.map +1 -1
- package/dist/tools/cache.d.ts.map +1 -1
- package/dist/tools/cache.js.map +1 -1
- package/dist/tools/comments.d.ts.map +1 -1
- package/dist/tools/comments.js.map +1 -1
- package/dist/tools/media.d.ts.map +1 -1
- package/dist/tools/media.js.map +1 -1
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/performance/PerformanceHelpers.d.ts +116 -0
- package/dist/tools/performance/PerformanceHelpers.d.ts.map +1 -0
- package/dist/tools/performance/PerformanceHelpers.js +298 -0
- package/dist/tools/performance/PerformanceHelpers.js.map +1 -0
- package/dist/tools/performance/PerformanceTools.d.ts +54 -0
- package/dist/tools/performance/PerformanceTools.d.ts.map +1 -0
- package/dist/tools/performance/PerformanceTools.js +687 -0
- package/dist/tools/performance/PerformanceTools.js.map +1 -0
- package/dist/tools/performance/index.d.ts +8 -0
- package/dist/tools/performance/index.d.ts.map +1 -0
- package/dist/tools/performance/index.js +8 -0
- package/dist/tools/performance/index.js.map +1 -0
- package/dist/tools/performance.d.ts +12 -69
- package/dist/tools/performance.d.ts.map +1 -1
- package/dist/tools/performance.js +12 -920
- package/dist/tools/performance.js.map +1 -1
- package/dist/tools/posts.d.ts.map +1 -1
- package/dist/tools/seo/analyzers/ContentAnalyzer.d.ts.map +1 -1
- package/dist/tools/seo/analyzers/ContentAnalyzer.js +14 -3
- package/dist/tools/seo/analyzers/ContentAnalyzer.js.map +1 -1
- package/dist/tools/seo/auditors/SiteAuditor.d.ts.map +1 -1
- package/dist/tools/seo/auditors/SiteAuditor.js +12 -3
- package/dist/tools/seo/auditors/SiteAuditor.js.map +1 -1
- package/dist/tools/seo/generators/MetaGenerator.d.ts.map +1 -1
- package/dist/tools/seo/generators/MetaGenerator.js +25 -8
- package/dist/tools/seo/generators/MetaGenerator.js.map +1 -1
- package/dist/tools/seo/generators/SchemaGenerator.d.ts.map +1 -1
- package/dist/tools/seo/generators/SchemaGenerator.js.map +1 -1
- package/dist/tools/seo/optimizers/InternalLinkingSuggester.d.ts.map +1 -1
- package/dist/tools/seo/optimizers/InternalLinkingSuggester.js.map +1 -1
- package/dist/tools/site.d.ts.map +1 -1
- package/dist/tools/site.js.map +1 -1
- package/dist/tools/taxonomies.d.ts.map +1 -1
- package/dist/tools/taxonomies.js.map +1 -1
- package/dist/tools/users.d.ts.map +1 -1
- package/dist/tools/users.js.map +1 -1
- package/dist/utils/CircuitBreaker.d.ts +243 -0
- package/dist/utils/CircuitBreaker.d.ts.map +1 -0
- package/dist/utils/CircuitBreaker.js +456 -0
- package/dist/utils/CircuitBreaker.js.map +1 -0
- package/dist/utils/debug.d.ts.map +1 -1
- package/dist/utils/debug.js.map +1 -1
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/toolWrapper.d.ts.map +1 -1
- package/docs/DEPRECATIONS.md +157 -0
- package/package.json +2 -3
- package/src/cache/CacheInvalidation.ts +1 -1
- package/src/cache/CacheManager.ts +25 -8
- package/src/cache/HttpCacheWrapper.ts +1 -1
- package/src/cache/SEOCacheManager.ts +9 -3
- package/src/cache/index.ts +1 -1
- package/src/client/CachedWordPressClient.ts +6 -6
- package/src/client/MockWordPressClient.ts +3 -3
- package/src/client/SEOWordPressClient.ts +6 -6
- package/src/client/api.ts +129 -215
- package/src/client/auth.ts +3 -3
- package/src/client/managers/AuthManager.ts +1 -1
- package/src/client/managers/RequestManager.ts +6 -7
- package/src/client/managers/composed/MigrationAdapter.ts +4 -4
- package/src/client/managers/composed/index.ts +7 -7
- package/src/client/managers/implementations/ConfigurationProviderImpl.ts +1 -1
- package/src/client/managers/implementations/ErrorHandlerImpl.ts +1 -1
- package/src/client/managers/implementations/ParameterValidatorImpl.ts +1 -1
- package/src/client/operations/comments.ts +96 -0
- package/src/client/operations/index.ts +12 -0
- package/src/client/operations/media.ts +162 -0
- package/src/client/operations/pages.ts +71 -0
- package/src/client/operations/posts.ts +68 -0
- package/src/client/operations/site.ts +106 -0
- package/src/client/operations/taxonomies.ts +115 -0
- package/src/client/operations/users.ts +72 -0
- package/src/config/ServerConfiguration.ts +6 -6
- package/src/docs/DocumentationGenerator.ts +3 -3
- package/src/performance/MetricsCollector.ts +4 -4
- package/src/performance/PerformanceMonitor.ts +1 -1
- package/src/security/AISecurityScanner.ts +4 -3
- package/src/security/AutomatedRemediation.ts +1 -1
- package/src/security/InputValidator.ts +36 -19
- package/src/security/SecurityCIPipeline.ts +130 -953
- package/src/security/SecurityConfig.ts +1 -1
- package/src/security/SecurityConfigManager.ts +1 -1
- package/src/security/SecurityGateExecutor.ts +485 -0
- package/src/security/SecurityMonitoring.ts +1 -1
- package/src/security/SecurityReportGenerator.ts +272 -0
- package/src/security/SecurityReviewer.ts +1 -1
- package/src/security/SecurityTypes.ts +199 -0
- package/src/security/index.ts +6 -1
- package/src/server/ConnectionTester.ts +4 -4
- package/src/server/ToolRegistry.ts +6 -6
- package/src/tools/BaseToolManager.ts +2 -2
- package/src/tools/auth.ts +3 -3
- package/src/tools/cache.ts +3 -3
- package/src/tools/comments.ts +3 -3
- package/src/tools/media.ts +3 -3
- package/src/tools/pages.ts +3 -3
- package/src/tools/performance/PerformanceHelpers.ts +330 -0
- package/src/tools/performance/PerformanceTools.ts +854 -0
- package/src/tools/performance/index.ts +8 -0
- package/src/tools/performance.ts +12 -1073
- package/src/tools/posts.ts +1 -1
- package/src/tools/seo/analyzers/ContentAnalyzer.ts +21 -7
- package/src/tools/seo/auditors/SiteAuditor.ts +18 -7
- package/src/tools/seo/generators/MetaGenerator.ts +33 -12
- package/src/tools/seo/generators/SchemaGenerator.ts +3 -3
- package/src/tools/seo/optimizers/InternalLinkingSuggester.ts +4 -4
- package/src/tools/site.ts +3 -3
- package/src/tools/taxonomies.ts +3 -3
- package/src/tools/users.ts +4 -4
- package/src/utils/CircuitBreaker.ts +572 -0
- package/src/utils/debug.ts +3 -3
- package/src/utils/error.ts +1 -1
- package/src/utils/index.ts +3 -0
- package/src/utils/logger.ts +1 -1
- package/src/utils/toolWrapper.ts +2 -2
- package/docs/BRANCH_PROTECTION.md +0 -0
|
@@ -1,924 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Performance Monitoring MCP Tools for WordPress Server
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* This module has been refactored into a modular structure.
|
|
5
|
+
* The implementation is now in ./performance/ directory:
|
|
6
|
+
* - PerformanceTools.ts: Main tool class with 6 MCP tools
|
|
7
|
+
* - PerformanceHelpers.ts: Extracted helper/utility functions
|
|
8
|
+
*
|
|
9
|
+
* This file re-exports for backward compatibility.
|
|
10
|
+
*
|
|
11
|
+
* @module tools/performance
|
|
4
12
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
import { PerformanceMonitor, } from "../performance/PerformanceMonitor.js";
|
|
10
|
-
import { MetricsCollector } from "../performance/MetricsCollector.js";
|
|
11
|
-
import { PerformanceAnalytics, } from "../performance/PerformanceAnalytics.js";
|
|
12
|
-
import { toolWrapper } from "../utils/toolWrapper.js";
|
|
13
|
-
import { ConfigHelpers } from "../config/Config.js";
|
|
14
|
-
import { LoggerFactory } from "../utils/logger.js";
|
|
15
|
-
// Using existing performance interfaces from PerformanceMonitor/PerformanceAnalytics
|
|
16
|
-
/**
|
|
17
|
-
* Performance Tools Class
|
|
18
|
-
*/
|
|
19
|
-
export default class PerformanceTools {
|
|
20
|
-
monitor;
|
|
21
|
-
collector;
|
|
22
|
-
analytics;
|
|
23
|
-
logger;
|
|
24
|
-
historicalDataInterval;
|
|
25
|
-
constructor(clients) {
|
|
26
|
-
// Initialize logger first
|
|
27
|
-
this.logger = LoggerFactory.performance();
|
|
28
|
-
// Initialize performance monitoring system
|
|
29
|
-
this.monitor = new PerformanceMonitor({
|
|
30
|
-
enableRealTimeMonitoring: true,
|
|
31
|
-
enableHistoricalData: true,
|
|
32
|
-
enableAlerts: true,
|
|
33
|
-
});
|
|
34
|
-
this.collector = new MetricsCollector(this.monitor, {
|
|
35
|
-
enableRealTime: true,
|
|
36
|
-
enableToolTracking: true,
|
|
37
|
-
enableCacheIntegration: true,
|
|
38
|
-
});
|
|
39
|
-
this.analytics = new PerformanceAnalytics(this.collector, {
|
|
40
|
-
enablePredictiveAnalysis: true,
|
|
41
|
-
enableAnomalyDetection: true,
|
|
42
|
-
enableTrendAnalysis: true,
|
|
43
|
-
});
|
|
44
|
-
// Register clients if provided
|
|
45
|
-
if (clients) {
|
|
46
|
-
for (const [siteId, client] of clients) {
|
|
47
|
-
this.collector.registerClient(siteId, client);
|
|
48
|
-
// Register cache manager if client has one
|
|
49
|
-
const possibleCacheMgr = client?.cacheManager;
|
|
50
|
-
if (possibleCacheMgr) {
|
|
51
|
-
this.collector.registerCacheManager(siteId, possibleCacheMgr);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// Only start historical data collection in production environments
|
|
56
|
-
if (ConfigHelpers.isProd() || ConfigHelpers.isDev()) {
|
|
57
|
-
this.startHistoricalDataCollection();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Get all performance monitoring tools
|
|
62
|
-
*/
|
|
63
|
-
getTools() {
|
|
64
|
-
return [
|
|
65
|
-
{
|
|
66
|
-
name: "wp_performance_stats",
|
|
67
|
-
description: "Get real-time performance statistics and metrics",
|
|
68
|
-
parameters: [
|
|
69
|
-
{
|
|
70
|
-
name: "site",
|
|
71
|
-
type: "string",
|
|
72
|
-
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
73
|
-
required: false,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: "category",
|
|
77
|
-
type: "string",
|
|
78
|
-
description: "Category of metrics to return (overview, requests, cache, system, tools, all)",
|
|
79
|
-
required: false,
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: "format",
|
|
83
|
-
type: "string",
|
|
84
|
-
description: "Detail level of the response (summary, detailed, raw)",
|
|
85
|
-
required: false,
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
handler: this.getPerformanceStats.bind(this),
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
name: "wp_performance_history",
|
|
92
|
-
description: "Get historical performance data and trends",
|
|
93
|
-
parameters: [
|
|
94
|
-
{
|
|
95
|
-
name: "site",
|
|
96
|
-
type: "string",
|
|
97
|
-
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
98
|
-
required: false,
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
name: "timeframe",
|
|
102
|
-
type: "string",
|
|
103
|
-
description: "Time period for historical data (1h, 6h, 12h, 24h, 7d)",
|
|
104
|
-
required: false,
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
name: "metrics",
|
|
108
|
-
type: "array",
|
|
109
|
-
description: "Specific metrics to include (responseTime, cacheHitRate, errorRate, memoryUsage, requestVolume)",
|
|
110
|
-
required: false,
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: "includeTrends",
|
|
114
|
-
type: "boolean",
|
|
115
|
-
description: "Include trend analysis (default: true)",
|
|
116
|
-
required: false,
|
|
117
|
-
},
|
|
118
|
-
],
|
|
119
|
-
handler: this.getPerformanceHistory.bind(this),
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
name: "wp_performance_benchmark",
|
|
123
|
-
description: "Compare current performance against industry benchmarks",
|
|
124
|
-
parameters: [
|
|
125
|
-
{
|
|
126
|
-
name: "site",
|
|
127
|
-
type: "string",
|
|
128
|
-
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
129
|
-
required: false,
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: "category",
|
|
133
|
-
type: "string",
|
|
134
|
-
description: "Benchmark category (response_time, cache_performance, error_rate, system_resources, all)",
|
|
135
|
-
required: false,
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
name: "includeRecommendations",
|
|
139
|
-
type: "boolean",
|
|
140
|
-
description: "Include improvement recommendations (default: true)",
|
|
141
|
-
required: false,
|
|
142
|
-
},
|
|
143
|
-
],
|
|
144
|
-
handler: this.getBenchmarkComparison.bind(this),
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: "wp_performance_alerts",
|
|
148
|
-
description: "Get performance alerts and anomaly detection results",
|
|
149
|
-
parameters: [
|
|
150
|
-
{
|
|
151
|
-
name: "site",
|
|
152
|
-
type: "string",
|
|
153
|
-
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
154
|
-
required: false,
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
name: "severity",
|
|
158
|
-
type: "string",
|
|
159
|
-
description: "Filter alerts by severity level (info, warning, error, critical)",
|
|
160
|
-
required: false,
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
name: "category",
|
|
164
|
-
type: "string",
|
|
165
|
-
description: "Filter alerts by category (performance, cache, system, wordpress)",
|
|
166
|
-
required: false,
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
name: "limit",
|
|
170
|
-
type: "number",
|
|
171
|
-
description: "Maximum number of alerts to return (default: 20)",
|
|
172
|
-
required: false,
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
name: "includeAnomalies",
|
|
176
|
-
type: "boolean",
|
|
177
|
-
description: "Include detected anomalies (default: true)",
|
|
178
|
-
required: false,
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
handler: this.getPerformanceAlerts.bind(this),
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
name: "wp_performance_optimize",
|
|
185
|
-
description: "Get optimization recommendations and insights",
|
|
186
|
-
parameters: [
|
|
187
|
-
{
|
|
188
|
-
name: "site",
|
|
189
|
-
type: "string",
|
|
190
|
-
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
191
|
-
required: false,
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
name: "focus",
|
|
195
|
-
type: "string",
|
|
196
|
-
description: "Optimization focus area (speed, reliability, efficiency, scaling)",
|
|
197
|
-
required: false,
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
name: "priority",
|
|
201
|
-
type: "string",
|
|
202
|
-
description: "Implementation timeline (quick_wins, medium_term, long_term, all)",
|
|
203
|
-
required: false,
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
name: "includeROI",
|
|
207
|
-
type: "boolean",
|
|
208
|
-
description: "Include ROI estimates (default: true)",
|
|
209
|
-
required: false,
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
name: "includePredictions",
|
|
213
|
-
type: "boolean",
|
|
214
|
-
description: "Include performance predictions (default: true)",
|
|
215
|
-
required: false,
|
|
216
|
-
},
|
|
217
|
-
],
|
|
218
|
-
handler: this.getOptimizationRecommendations.bind(this),
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
name: "wp_performance_export",
|
|
222
|
-
description: "Export comprehensive performance report",
|
|
223
|
-
parameters: [
|
|
224
|
-
{
|
|
225
|
-
name: "site",
|
|
226
|
-
type: "string",
|
|
227
|
-
description: "Specific site ID for multi-site setups (optional for single site)",
|
|
228
|
-
required: false,
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
name: "format",
|
|
232
|
-
type: "string",
|
|
233
|
-
description: "Export format (json, csv, summary)",
|
|
234
|
-
required: false,
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
name: "includeHistorical",
|
|
238
|
-
type: "boolean",
|
|
239
|
-
description: "Include historical data (default: true)",
|
|
240
|
-
required: false,
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
name: "includeAnalytics",
|
|
244
|
-
type: "boolean",
|
|
245
|
-
description: "Include analytics and insights (default: true)",
|
|
246
|
-
required: false,
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
name: "timeRange",
|
|
250
|
-
type: "string",
|
|
251
|
-
description: "Time range for data export (1h, 6h, 24h, 7d, 30d)",
|
|
252
|
-
required: false,
|
|
253
|
-
},
|
|
254
|
-
],
|
|
255
|
-
handler: this.exportPerformanceReport.bind(this),
|
|
256
|
-
},
|
|
257
|
-
];
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Get real-time performance statistics
|
|
261
|
-
*/
|
|
262
|
-
async getPerformanceStats(_client, params) {
|
|
263
|
-
return toolWrapper(async () => {
|
|
264
|
-
const { site, category = "overview", format = "summary", } = params;
|
|
265
|
-
// Get current metrics
|
|
266
|
-
const metrics = this.collector.collectCurrentMetrics();
|
|
267
|
-
// Get site-specific metrics if requested
|
|
268
|
-
let siteMetrics = null;
|
|
269
|
-
if (site) {
|
|
270
|
-
siteMetrics = this.collector.getSiteMetrics(site);
|
|
271
|
-
}
|
|
272
|
-
// Filter by category
|
|
273
|
-
const result = {};
|
|
274
|
-
if (category === "overview" || category === "all") {
|
|
275
|
-
result.overview = {
|
|
276
|
-
overallHealth: this.calculateHealthStatus(metrics),
|
|
277
|
-
performanceScore: this.calculatePerformanceScore(metrics),
|
|
278
|
-
totalRequests: metrics.requests.total,
|
|
279
|
-
averageResponseTime: `${metrics.requests.averageResponseTime.toFixed(0)}ms`,
|
|
280
|
-
cacheHitRate: `${(metrics.cache.hitRate * 100).toFixed(1)}%`,
|
|
281
|
-
errorRate: `${((metrics.requests.failed / Math.max(metrics.requests.total, 1)) * 100).toFixed(2)}%`,
|
|
282
|
-
uptime: this.formatUptime(metrics.system.uptime),
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
if (category === "requests" || category === "all") {
|
|
286
|
-
result.requests = {
|
|
287
|
-
...metrics.requests,
|
|
288
|
-
requestsPerSecond: metrics.requests.requestsPerSecond.toFixed(2),
|
|
289
|
-
p50ResponseTime: `${metrics.requests.p50ResponseTime}ms`,
|
|
290
|
-
p95ResponseTime: `${metrics.requests.p95ResponseTime}ms`,
|
|
291
|
-
p99ResponseTime: `${metrics.requests.p99ResponseTime}ms`,
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
if (category === "cache" || category === "all") {
|
|
295
|
-
result.cache = {
|
|
296
|
-
...metrics.cache,
|
|
297
|
-
hitRate: `${(metrics.cache.hitRate * 100).toFixed(1)}%`,
|
|
298
|
-
memoryUsage: `${metrics.cache.memoryUsageMB.toFixed(1)}MB`,
|
|
299
|
-
efficiency: this.calculateCacheEfficiency(metrics.cache),
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
if (category === "system" || category === "all") {
|
|
303
|
-
result.system = {
|
|
304
|
-
...metrics.system,
|
|
305
|
-
memoryUsage: `${metrics.system.memoryUsage}%`,
|
|
306
|
-
cpuUsage: `${metrics.system.cpuUsage}%`,
|
|
307
|
-
uptime: this.formatUptime(metrics.system.uptime),
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
if (category === "tools" || category === "all") {
|
|
311
|
-
result.tools = {
|
|
312
|
-
mostUsedTool: metrics.tools.mostUsedTool,
|
|
313
|
-
totalToolCalls: Object.values(metrics.tools.toolUsageCount).reduce((sum, count) => sum + (typeof count === "number" ? count : 0), 0),
|
|
314
|
-
topTools: Object.entries(metrics.tools.toolUsageCount)
|
|
315
|
-
.sort(([, a], [, b]) => b - a)
|
|
316
|
-
.slice(0, 5)
|
|
317
|
-
.map(([tool, count]) => ({ tool, count })),
|
|
318
|
-
toolPerformance: format === "detailed" ? metrics.tools.toolPerformance : undefined,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
// Add site-specific data if requested
|
|
322
|
-
if (siteMetrics && siteMetrics.isActive) {
|
|
323
|
-
result.siteSpecific = {
|
|
324
|
-
siteId: site,
|
|
325
|
-
cache: siteMetrics.cache,
|
|
326
|
-
client: siteMetrics.client,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
// Add metadata
|
|
330
|
-
result.metadata = {
|
|
331
|
-
timestamp: new Date().toISOString(),
|
|
332
|
-
category,
|
|
333
|
-
format,
|
|
334
|
-
site: site || "all",
|
|
335
|
-
monitoringEnabled: true,
|
|
336
|
-
};
|
|
337
|
-
return {
|
|
338
|
-
success: true,
|
|
339
|
-
data: result,
|
|
340
|
-
};
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Get historical performance data and trends
|
|
345
|
-
*/
|
|
346
|
-
async getPerformanceHistory(_client, params) {
|
|
347
|
-
return toolWrapper(async () => {
|
|
348
|
-
const { site, timeframe = "24h", metrics: requestedMetrics, includeTrends = true, } = params;
|
|
349
|
-
// Convert timeframe to milliseconds
|
|
350
|
-
const timeframMs = this.parseTimeframe(timeframe);
|
|
351
|
-
const startTime = Date.now() - timeframMs;
|
|
352
|
-
// Get historical data
|
|
353
|
-
const historicalData = this.monitor.getHistoricalData(startTime);
|
|
354
|
-
// Analyze trends if requested
|
|
355
|
-
let trends = null;
|
|
356
|
-
if (includeTrends) {
|
|
357
|
-
// Add current data for trend analysis
|
|
358
|
-
this.analytics.addDataPoint(this.collector.collectCurrentMetrics());
|
|
359
|
-
trends = this.analytics.analyzeTrends();
|
|
360
|
-
// Filter trends by requested metrics
|
|
361
|
-
if (requestedMetrics && Array.isArray(requestedMetrics)) {
|
|
362
|
-
trends = trends.filter((trend) => requestedMetrics.includes(trend.metric));
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
// Process historical data for charting
|
|
366
|
-
const chartData = this.processHistoricalDataForChart(historicalData, requestedMetrics);
|
|
367
|
-
return {
|
|
368
|
-
success: true,
|
|
369
|
-
data: {
|
|
370
|
-
timeframe,
|
|
371
|
-
dataPoints: historicalData.length,
|
|
372
|
-
historicalData: chartData,
|
|
373
|
-
trends: trends || [],
|
|
374
|
-
summary: {
|
|
375
|
-
averageResponseTime: this.calculateAverage(historicalData.map((d) => d.requests.averageResponseTime)),
|
|
376
|
-
averageCacheHitRate: this.calculateAverage(historicalData.map((d) => d.cache.hitRate)),
|
|
377
|
-
averageErrorRate: this.calculateAverage(historicalData.map((d) => (d.requests.total > 0 ? d.requests.failed / d.requests.total : 0))),
|
|
378
|
-
totalRequests: historicalData.reduce((sum, d) => sum + d.requests.total, 0),
|
|
379
|
-
},
|
|
380
|
-
metadata: {
|
|
381
|
-
timestamp: new Date().toISOString(),
|
|
382
|
-
site: site || "all",
|
|
383
|
-
requestedMetrics: requestedMetrics || ["all"],
|
|
384
|
-
},
|
|
385
|
-
},
|
|
386
|
-
};
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Get benchmark comparison
|
|
391
|
-
*/
|
|
392
|
-
async getBenchmarkComparison(_client, params) {
|
|
393
|
-
return toolWrapper(async () => {
|
|
394
|
-
const { site, category = "all", includeRecommendations = true, } = params;
|
|
395
|
-
// Get benchmark comparisons
|
|
396
|
-
const benchmarks = this.analytics.benchmarkPerformance();
|
|
397
|
-
// Filter by category if specified
|
|
398
|
-
let filteredBenchmarks = benchmarks;
|
|
399
|
-
if (category !== "all") {
|
|
400
|
-
const categoryMap = {
|
|
401
|
-
response_time: "Response Time",
|
|
402
|
-
cache_performance: "Cache Hit Rate",
|
|
403
|
-
error_rate: "Error Rate",
|
|
404
|
-
system_resources: "Memory Usage",
|
|
405
|
-
};
|
|
406
|
-
const targetCategory = categoryMap[category];
|
|
407
|
-
if (targetCategory) {
|
|
408
|
-
filteredBenchmarks = benchmarks.filter((b) => b.category === targetCategory);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
// Get recommendations if requested
|
|
412
|
-
let recommendations = null;
|
|
413
|
-
if (includeRecommendations) {
|
|
414
|
-
const insights = this.analytics.generateInsights();
|
|
415
|
-
recommendations = insights
|
|
416
|
-
.filter((insight) => insight.category === "optimization")
|
|
417
|
-
.map((insight) => ({
|
|
418
|
-
title: insight.title,
|
|
419
|
-
description: insight.description,
|
|
420
|
-
priority: insight.priority,
|
|
421
|
-
estimatedImprovement: insight.estimatedImprovement,
|
|
422
|
-
implementationEffort: insight.implementationEffort,
|
|
423
|
-
}));
|
|
424
|
-
}
|
|
425
|
-
return {
|
|
426
|
-
success: true,
|
|
427
|
-
data: {
|
|
428
|
-
benchmarks: filteredBenchmarks.map((benchmark) => ({
|
|
429
|
-
...benchmark,
|
|
430
|
-
status: this.formatBenchmarkStatus(benchmark.status),
|
|
431
|
-
improvement: benchmark.improvement > 0
|
|
432
|
-
? {
|
|
433
|
-
needed: benchmark.improvement,
|
|
434
|
-
description: this.getBenchmarkImprovementDescription(benchmark),
|
|
435
|
-
}
|
|
436
|
-
: null,
|
|
437
|
-
})),
|
|
438
|
-
overallRanking: this.calculateOverallRanking(benchmarks),
|
|
439
|
-
recommendations: recommendations || [],
|
|
440
|
-
metadata: {
|
|
441
|
-
timestamp: new Date().toISOString(),
|
|
442
|
-
category,
|
|
443
|
-
site: site || "all",
|
|
444
|
-
benchmarkVersion: "2024-industry-standards",
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
};
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Get performance alerts and anomalies
|
|
452
|
-
*/
|
|
453
|
-
async getPerformanceAlerts(_client, params) {
|
|
454
|
-
return toolWrapper(async () => {
|
|
455
|
-
const { site, severity, category, limit = 20, includeAnomalies = true, } = params;
|
|
456
|
-
// Get alerts from monitor
|
|
457
|
-
let alerts = this.monitor.getAlerts(severity);
|
|
458
|
-
// Filter by category if specified
|
|
459
|
-
if (category) {
|
|
460
|
-
alerts = alerts.filter((alert) => alert.category === category);
|
|
461
|
-
}
|
|
462
|
-
// Limit results
|
|
463
|
-
alerts = alerts.slice(-limit);
|
|
464
|
-
// Get anomalies if requested
|
|
465
|
-
let anomalies = [];
|
|
466
|
-
if (includeAnomalies) {
|
|
467
|
-
anomalies = this.analytics.getAnomalies(severity);
|
|
468
|
-
}
|
|
469
|
-
// Calculate alert summary
|
|
470
|
-
const alertSummary = {
|
|
471
|
-
total: alerts.length,
|
|
472
|
-
critical: alerts.filter((a) => a.severity === "critical").length,
|
|
473
|
-
error: alerts.filter((a) => a.severity === "error").length,
|
|
474
|
-
warning: alerts.filter((a) => a.severity === "warning").length,
|
|
475
|
-
info: alerts.filter((a) => a.severity === "info").length,
|
|
476
|
-
};
|
|
477
|
-
const anomalySummary = {
|
|
478
|
-
total: anomalies.length,
|
|
479
|
-
critical: anomalies.filter((a) => a.severity === "critical").length,
|
|
480
|
-
major: anomalies.filter((a) => a.severity === "major").length,
|
|
481
|
-
moderate: anomalies.filter((a) => a.severity === "moderate").length,
|
|
482
|
-
minor: anomalies.filter((a) => a.severity === "minor").length,
|
|
483
|
-
};
|
|
484
|
-
return {
|
|
485
|
-
success: true,
|
|
486
|
-
data: {
|
|
487
|
-
alerts: alerts.map((alert) => ({
|
|
488
|
-
...alert,
|
|
489
|
-
timestamp: new Date(alert.timestamp).toISOString(),
|
|
490
|
-
formattedMessage: this.formatAlertMessage(alert),
|
|
491
|
-
})),
|
|
492
|
-
anomalies: anomalies.map((anomaly) => ({
|
|
493
|
-
...anomaly,
|
|
494
|
-
timestamp: new Date(anomaly.timestamp).toISOString(),
|
|
495
|
-
formattedDescription: this.formatAnomalyDescription(anomaly),
|
|
496
|
-
})),
|
|
497
|
-
summary: {
|
|
498
|
-
alerts: alertSummary,
|
|
499
|
-
anomalies: anomalySummary,
|
|
500
|
-
overallStatus: this.calculateAlertStatus(alertSummary, anomalySummary),
|
|
501
|
-
},
|
|
502
|
-
metadata: {
|
|
503
|
-
timestamp: new Date().toISOString(),
|
|
504
|
-
filters: { severity, category, site: site || "all" },
|
|
505
|
-
limit,
|
|
506
|
-
},
|
|
507
|
-
},
|
|
508
|
-
};
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Get optimization recommendations
|
|
513
|
-
*/
|
|
514
|
-
async getOptimizationRecommendations(_client, params) {
|
|
515
|
-
return toolWrapper(async () => {
|
|
516
|
-
const { site, focus = "speed", priority = "all", includeROI = true, includePredictions = true, } = params;
|
|
517
|
-
// Generate optimization plan
|
|
518
|
-
const optimizationPlan = this.analytics.generateOptimizationPlan();
|
|
519
|
-
// Filter by priority
|
|
520
|
-
let recommendations = [];
|
|
521
|
-
if (priority === "quick_wins" || priority === "all") {
|
|
522
|
-
recommendations.push(...optimizationPlan.quickWins.map((r) => ({
|
|
523
|
-
...r,
|
|
524
|
-
timeline: "quick_wins",
|
|
525
|
-
})));
|
|
526
|
-
}
|
|
527
|
-
if (priority === "medium_term" || priority === "all") {
|
|
528
|
-
recommendations.push(...optimizationPlan.mediumTerm.map((r) => ({
|
|
529
|
-
...r,
|
|
530
|
-
timeline: "medium_term",
|
|
531
|
-
})));
|
|
532
|
-
}
|
|
533
|
-
if (priority === "long_term" || priority === "all") {
|
|
534
|
-
recommendations.push(...optimizationPlan.longTerm.map((r) => ({
|
|
535
|
-
...r,
|
|
536
|
-
timeline: "long_term",
|
|
537
|
-
})));
|
|
538
|
-
}
|
|
539
|
-
// Filter by focus area
|
|
540
|
-
if (focus !== "speed") {
|
|
541
|
-
const focusMap = {
|
|
542
|
-
reliability: ["reliability"],
|
|
543
|
-
efficiency: ["cost", "performance"],
|
|
544
|
-
scaling: ["performance", "reliability"],
|
|
545
|
-
};
|
|
546
|
-
const targetImpacts = focusMap[focus] || [];
|
|
547
|
-
recommendations = recommendations.filter((r) => targetImpacts.includes(r.impact));
|
|
548
|
-
}
|
|
549
|
-
// Get predictions if requested
|
|
550
|
-
let predictions = null;
|
|
551
|
-
if (includePredictions) {
|
|
552
|
-
predictions = this.analytics.predictPerformance(60); // 1 hour prediction
|
|
553
|
-
}
|
|
554
|
-
return {
|
|
555
|
-
success: true,
|
|
556
|
-
data: {
|
|
557
|
-
recommendations: recommendations.map((rec) => ({
|
|
558
|
-
...rec,
|
|
559
|
-
formattedPriority: this.formatPriority(rec.priority),
|
|
560
|
-
formattedEffort: this.formatEffort(rec.implementationEffort),
|
|
561
|
-
})),
|
|
562
|
-
roi: includeROI ? optimizationPlan.estimatedROI : null,
|
|
563
|
-
predictions: predictions || null,
|
|
564
|
-
summary: {
|
|
565
|
-
totalRecommendations: recommendations.length,
|
|
566
|
-
quickWins: optimizationPlan.quickWins.length,
|
|
567
|
-
mediumTerm: optimizationPlan.mediumTerm.length,
|
|
568
|
-
longTerm: optimizationPlan.longTerm.length,
|
|
569
|
-
estimatedImpact: this.calculateEstimatedImpact(recommendations),
|
|
570
|
-
},
|
|
571
|
-
metadata: {
|
|
572
|
-
timestamp: new Date().toISOString(),
|
|
573
|
-
focus,
|
|
574
|
-
priority,
|
|
575
|
-
site: site || "all",
|
|
576
|
-
},
|
|
577
|
-
},
|
|
578
|
-
};
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* Export comprehensive performance report
|
|
583
|
-
*/
|
|
584
|
-
async exportPerformanceReport(_client, params) {
|
|
585
|
-
return toolWrapper(async () => {
|
|
586
|
-
const { site, format = "json", includeHistorical = true, includeAnalytics = true, timeRange = "24h", } = params;
|
|
587
|
-
// Generate comprehensive analytics report
|
|
588
|
-
const report = this.analytics.exportAnalyticsReport();
|
|
589
|
-
// Add additional data based on parameters
|
|
590
|
-
const exportData = {
|
|
591
|
-
metadata: {
|
|
592
|
-
generatedAt: new Date().toISOString(),
|
|
593
|
-
site: site || "all",
|
|
594
|
-
timeRange,
|
|
595
|
-
format,
|
|
596
|
-
version: "1.0.0",
|
|
597
|
-
},
|
|
598
|
-
summary: report.summary,
|
|
599
|
-
currentMetrics: this.collector.collectCurrentMetrics(),
|
|
600
|
-
};
|
|
601
|
-
if (includeHistorical) {
|
|
602
|
-
const timeframMs = this.parseTimeframe(timeRange);
|
|
603
|
-
const startTime = Date.now() - timeframMs;
|
|
604
|
-
exportData.historicalData = this.monitor.getHistoricalData(startTime);
|
|
605
|
-
}
|
|
606
|
-
if (includeAnalytics) {
|
|
607
|
-
exportData.analytics = {
|
|
608
|
-
trends: report.trends,
|
|
609
|
-
benchmarks: report.benchmarks,
|
|
610
|
-
insights: report.insights,
|
|
611
|
-
anomalies: report.anomalies,
|
|
612
|
-
predictions: report.predictions,
|
|
613
|
-
optimizationPlan: report.optimizationPlan,
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
// Add aggregated statistics
|
|
617
|
-
exportData.aggregatedStats = {
|
|
618
|
-
cache: this.collector.getAggregatedCacheStats(),
|
|
619
|
-
client: this.collector.getAggregatedClientStats(),
|
|
620
|
-
};
|
|
621
|
-
// Add site comparison if multi-site
|
|
622
|
-
if (!site) {
|
|
623
|
-
exportData.siteComparison = this.collector.compareSitePerformance();
|
|
624
|
-
}
|
|
625
|
-
// Format output based on requested format
|
|
626
|
-
let formattedOutput;
|
|
627
|
-
if (format === "csv") {
|
|
628
|
-
formattedOutput = this.convertToCSV(exportData);
|
|
629
|
-
}
|
|
630
|
-
else if (format === "summary") {
|
|
631
|
-
formattedOutput = this.createSummaryReport(exportData);
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
formattedOutput = exportData;
|
|
635
|
-
}
|
|
636
|
-
return {
|
|
637
|
-
success: true,
|
|
638
|
-
data: formattedOutput,
|
|
639
|
-
metadata: {
|
|
640
|
-
timestamp: new Date().toISOString(),
|
|
641
|
-
format,
|
|
642
|
-
dataSize: JSON.stringify(exportData).length,
|
|
643
|
-
site: site || "all",
|
|
644
|
-
},
|
|
645
|
-
};
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
// Helper methods
|
|
649
|
-
calculateHealthStatus(metrics) {
|
|
650
|
-
let score = 100;
|
|
651
|
-
if (metrics.requests.averageResponseTime > 2000)
|
|
652
|
-
score -= 30;
|
|
653
|
-
else if (metrics.requests.averageResponseTime > 1000)
|
|
654
|
-
score -= 15;
|
|
655
|
-
const errorRate = metrics.requests.failed / Math.max(metrics.requests.total, 1);
|
|
656
|
-
if (errorRate > 0.05)
|
|
657
|
-
score -= 30;
|
|
658
|
-
else if (errorRate > 0.02)
|
|
659
|
-
score -= 15;
|
|
660
|
-
if (metrics.cache.hitRate < 0.7)
|
|
661
|
-
score -= 25;
|
|
662
|
-
else if (metrics.cache.hitRate < 0.85)
|
|
663
|
-
score -= 10;
|
|
664
|
-
if (metrics.system.memoryUsage > 85)
|
|
665
|
-
score -= 15;
|
|
666
|
-
if (score >= 90)
|
|
667
|
-
return "Excellent";
|
|
668
|
-
if (score >= 75)
|
|
669
|
-
return "Good";
|
|
670
|
-
if (score >= 60)
|
|
671
|
-
return "Fair";
|
|
672
|
-
if (score >= 40)
|
|
673
|
-
return "Poor";
|
|
674
|
-
return "Critical";
|
|
675
|
-
}
|
|
676
|
-
calculatePerformanceScore(metrics) {
|
|
677
|
-
let score = 100;
|
|
678
|
-
// Response time scoring
|
|
679
|
-
if (metrics.requests.averageResponseTime > 3000)
|
|
680
|
-
score -= 40;
|
|
681
|
-
else if (metrics.requests.averageResponseTime > 1500)
|
|
682
|
-
score -= 25;
|
|
683
|
-
else if (metrics.requests.averageResponseTime > 800)
|
|
684
|
-
score -= 10;
|
|
685
|
-
// Error rate scoring
|
|
686
|
-
const errorRate = metrics.requests.failed / Math.max(metrics.requests.total, 1);
|
|
687
|
-
if (errorRate > 0.1)
|
|
688
|
-
score -= 30;
|
|
689
|
-
else if (errorRate > 0.05)
|
|
690
|
-
score -= 20;
|
|
691
|
-
else if (errorRate > 0.02)
|
|
692
|
-
score -= 10;
|
|
693
|
-
// Cache performance scoring
|
|
694
|
-
if (metrics.cache.hitRate < 0.5)
|
|
695
|
-
score -= 20;
|
|
696
|
-
else if (metrics.cache.hitRate < 0.75)
|
|
697
|
-
score -= 10;
|
|
698
|
-
else if (metrics.cache.hitRate < 0.9)
|
|
699
|
-
score -= 5;
|
|
700
|
-
// System resource scoring
|
|
701
|
-
if (metrics.system.memoryUsage > 90)
|
|
702
|
-
score -= 10;
|
|
703
|
-
else if (metrics.system.memoryUsage > 80)
|
|
704
|
-
score -= 5;
|
|
705
|
-
return Math.max(0, Math.min(100, score));
|
|
706
|
-
}
|
|
707
|
-
calculateCacheEfficiency(cacheMetrics) {
|
|
708
|
-
const efficiency = cacheMetrics.hitRate * 100 + (cacheMetrics.totalSize > 0 ? 10 : 0) - (cacheMetrics.evictions > 100 ? 10 : 0);
|
|
709
|
-
if (efficiency >= 95)
|
|
710
|
-
return "Excellent";
|
|
711
|
-
if (efficiency >= 85)
|
|
712
|
-
return "Good";
|
|
713
|
-
if (efficiency >= 70)
|
|
714
|
-
return "Fair";
|
|
715
|
-
return "Poor";
|
|
716
|
-
}
|
|
717
|
-
formatUptime(uptimeMs) {
|
|
718
|
-
const seconds = Math.floor(uptimeMs / 1000);
|
|
719
|
-
const minutes = Math.floor(seconds / 60);
|
|
720
|
-
const hours = Math.floor(minutes / 60);
|
|
721
|
-
const days = Math.floor(hours / 24);
|
|
722
|
-
if (days > 0)
|
|
723
|
-
return `${days}d ${hours % 24}h ${minutes % 60}m`;
|
|
724
|
-
if (hours > 0)
|
|
725
|
-
return `${hours}h ${minutes % 60}m`;
|
|
726
|
-
if (minutes > 0)
|
|
727
|
-
return `${minutes}m ${seconds % 60}s`;
|
|
728
|
-
return `${seconds}s`;
|
|
729
|
-
}
|
|
730
|
-
parseTimeframe(timeframe) {
|
|
731
|
-
const map = {
|
|
732
|
-
"1h": 60 * 60 * 1000,
|
|
733
|
-
"6h": 6 * 60 * 60 * 1000,
|
|
734
|
-
"12h": 12 * 60 * 60 * 1000,
|
|
735
|
-
"24h": 24 * 60 * 60 * 1000,
|
|
736
|
-
"7d": 7 * 24 * 60 * 60 * 1000,
|
|
737
|
-
"30d": 30 * 24 * 60 * 60 * 1000,
|
|
738
|
-
};
|
|
739
|
-
return map[timeframe] || map["24h"];
|
|
740
|
-
}
|
|
741
|
-
processHistoricalDataForChart(data, requestedMetrics) {
|
|
742
|
-
if (!data.length)
|
|
743
|
-
return {};
|
|
744
|
-
const allMetrics = ["responseTime", "cacheHitRate", "errorRate", "memoryUsage", "requestVolume"];
|
|
745
|
-
const metricsToProcess = requestedMetrics || allMetrics;
|
|
746
|
-
const result = {};
|
|
747
|
-
for (const metric of metricsToProcess) {
|
|
748
|
-
result[metric] = data.map((point, index) => ({
|
|
749
|
-
timestamp: point.system.uptime,
|
|
750
|
-
value: this.extractMetricValue(point, metric),
|
|
751
|
-
index,
|
|
752
|
-
}));
|
|
753
|
-
}
|
|
754
|
-
return result;
|
|
755
|
-
}
|
|
756
|
-
extractMetricValue(dataPoint, metric) {
|
|
757
|
-
switch (metric) {
|
|
758
|
-
case "responseTime":
|
|
759
|
-
return dataPoint.requests.averageResponseTime;
|
|
760
|
-
case "cacheHitRate":
|
|
761
|
-
return dataPoint.cache.hitRate * 100;
|
|
762
|
-
case "errorRate":
|
|
763
|
-
return (dataPoint.requests.failed / Math.max(dataPoint.requests.total, 1)) * 100;
|
|
764
|
-
case "memoryUsage":
|
|
765
|
-
return dataPoint.system.memoryUsage;
|
|
766
|
-
case "requestVolume":
|
|
767
|
-
return dataPoint.requests.requestsPerSecond;
|
|
768
|
-
default:
|
|
769
|
-
return 0;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
calculateAverage(values) {
|
|
773
|
-
if (values.length === 0)
|
|
774
|
-
return 0;
|
|
775
|
-
return values.reduce((sum, val) => sum + val, 0) / values.length;
|
|
776
|
-
}
|
|
777
|
-
formatBenchmarkStatus(status) {
|
|
778
|
-
const statusMap = {
|
|
779
|
-
excellent: "🟢 Excellent",
|
|
780
|
-
good: "🟡 Good",
|
|
781
|
-
average: "🟠 Average",
|
|
782
|
-
below_average: "🔴 Below Average",
|
|
783
|
-
poor: "⚫ Poor",
|
|
784
|
-
};
|
|
785
|
-
return statusMap[status] || status;
|
|
786
|
-
}
|
|
787
|
-
getBenchmarkImprovementDescription(benchmark) {
|
|
788
|
-
const improvements = {
|
|
789
|
-
"Response Time": `Reduce by ${benchmark.improvement.toFixed(0)}ms`,
|
|
790
|
-
"Cache Hit Rate": `Increase by ${benchmark.improvement.toFixed(1)}%`,
|
|
791
|
-
"Error Rate": `Reduce by ${benchmark.improvement.toFixed(2)}%`,
|
|
792
|
-
"Memory Usage": `Reduce by ${benchmark.improvement.toFixed(0)}%`,
|
|
793
|
-
};
|
|
794
|
-
return improvements[benchmark.category] || `Improve by ${benchmark.improvement}`;
|
|
795
|
-
}
|
|
796
|
-
calculateOverallRanking(benchmarks) {
|
|
797
|
-
const statuses = benchmarks.map((b) => b.status);
|
|
798
|
-
const excellentCount = statuses.filter((s) => s === "excellent").length;
|
|
799
|
-
const goodCount = statuses.filter((s) => s === "good").length;
|
|
800
|
-
const percentile = ((excellentCount + goodCount * 0.8) / statuses.length) * 100;
|
|
801
|
-
let status = "Needs Improvement";
|
|
802
|
-
if (percentile >= 90)
|
|
803
|
-
status = "Top Performer";
|
|
804
|
-
else if (percentile >= 75)
|
|
805
|
-
status = "Above Average";
|
|
806
|
-
else if (percentile >= 50)
|
|
807
|
-
status = "Average";
|
|
808
|
-
return { percentile: Math.round(percentile), status };
|
|
809
|
-
}
|
|
810
|
-
formatAlertMessage(alert) {
|
|
811
|
-
return `${alert.severity.toUpperCase()}: ${alert.message} (${alert.metric}: ${alert.actualValue} vs threshold: ${alert.threshold})`;
|
|
812
|
-
}
|
|
813
|
-
formatAnomalyDescription(anomaly) {
|
|
814
|
-
const direction = anomaly.actualValue > anomaly.expectedValue ? "higher" : "lower";
|
|
815
|
-
return `${anomaly.metric} is ${Math.abs(anomaly.deviation).toFixed(1)}% ${direction} than expected (${anomaly.expectedValue.toFixed(2)} vs ${anomaly.actualValue.toFixed(2)})`;
|
|
816
|
-
}
|
|
817
|
-
calculateAlertStatus(alertSummary, anomalySummary) {
|
|
818
|
-
const critical = alertSummary.critical + anomalySummary.critical;
|
|
819
|
-
const high = alertSummary.error + anomalySummary.major;
|
|
820
|
-
if (critical > 0)
|
|
821
|
-
return "Critical Issues Detected";
|
|
822
|
-
if (high > 2)
|
|
823
|
-
return "High Priority Issues";
|
|
824
|
-
if (alertSummary.warning + anomalySummary.moderate > 5)
|
|
825
|
-
return "Performance Warnings";
|
|
826
|
-
return "System Healthy";
|
|
827
|
-
}
|
|
828
|
-
formatPriority(priority) {
|
|
829
|
-
const map = {
|
|
830
|
-
critical: "🔴 Critical",
|
|
831
|
-
high: "🟠 High",
|
|
832
|
-
medium: "🟡 Medium",
|
|
833
|
-
low: "🟢 Low",
|
|
834
|
-
};
|
|
835
|
-
return map[priority] || priority;
|
|
836
|
-
}
|
|
837
|
-
formatEffort(effort) {
|
|
838
|
-
const map = {
|
|
839
|
-
low: "⚡ Low Effort",
|
|
840
|
-
medium: "⚖️ Medium Effort",
|
|
841
|
-
high: "🏋️ High Effort",
|
|
842
|
-
};
|
|
843
|
-
return map[effort] || effort;
|
|
844
|
-
}
|
|
845
|
-
calculateEstimatedImpact(recommendations) {
|
|
846
|
-
const highImpact = recommendations.filter((r) => ["critical", "high"].includes(r.priority)).length;
|
|
847
|
-
const totalImpact = recommendations.length;
|
|
848
|
-
if (highImpact >= 3)
|
|
849
|
-
return "Significant Performance Gains Expected";
|
|
850
|
-
if (totalImpact >= 5)
|
|
851
|
-
return "Moderate Performance Improvements";
|
|
852
|
-
if (totalImpact > 0)
|
|
853
|
-
return "Minor Performance Optimizations";
|
|
854
|
-
return "System Already Optimized";
|
|
855
|
-
}
|
|
856
|
-
convertToCSV(data) {
|
|
857
|
-
// Simplified CSV conversion for current metrics
|
|
858
|
-
const metrics = data.currentMetrics;
|
|
859
|
-
const csv = [
|
|
860
|
-
"Metric,Value,Unit",
|
|
861
|
-
`Total Requests,${metrics.requests.total},count`,
|
|
862
|
-
`Average Response Time,${metrics.requests.averageResponseTime.toFixed(0)},ms`,
|
|
863
|
-
`Success Rate,${((metrics.requests.successful / Math.max(metrics.requests.total, 1)) * 100).toFixed(1)},%`,
|
|
864
|
-
`Cache Hit Rate,${(metrics.cache.hitRate * 100).toFixed(1)},%`,
|
|
865
|
-
`Cache Size,${metrics.cache.totalSize},entries`,
|
|
866
|
-
`Memory Usage,${metrics.system.memoryUsage},percent`,
|
|
867
|
-
`Uptime,${metrics.system.uptime},ms`,
|
|
868
|
-
];
|
|
869
|
-
return csv.join("\n");
|
|
870
|
-
}
|
|
871
|
-
createSummaryReport(data) {
|
|
872
|
-
const metrics = data.currentMetrics;
|
|
873
|
-
return {
|
|
874
|
-
summary: `Performance Report - ${new Date().toISOString()}`,
|
|
875
|
-
overallHealth: this.calculateHealthStatus(metrics),
|
|
876
|
-
keyMetrics: {
|
|
877
|
-
averageResponseTime: `${metrics.requests.averageResponseTime.toFixed(0)}ms`,
|
|
878
|
-
cacheEfficiency: `${(metrics.cache.hitRate * 100).toFixed(1)}%`,
|
|
879
|
-
systemLoad: `${metrics.system.memoryUsage}%`,
|
|
880
|
-
errorRate: `${((metrics.requests.failed / Math.max(metrics.requests.total, 1)) * 100).toFixed(2)}%`,
|
|
881
|
-
},
|
|
882
|
-
recommendations: data.analytics?.insights?.slice(0, 3) || [],
|
|
883
|
-
nextSteps: "Review detailed metrics and implement high-priority optimizations",
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
startHistoricalDataCollection() {
|
|
887
|
-
// Skip in test environments to prevent performance issues
|
|
888
|
-
if (ConfigHelpers.isTest() || ConfigHelpers.isCI()) {
|
|
889
|
-
this.logger.debug("Skipping historical data collection in test/CI environment");
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
// Adjust collection frequency based on environment
|
|
893
|
-
const interval = ConfigHelpers.isDev() ? 60000 : 30000; // 1 minute in dev, 30 seconds in prod
|
|
894
|
-
this.logger.info("Starting historical data collection", {
|
|
895
|
-
interval: `${interval / 1000}s`,
|
|
896
|
-
environment: ConfigHelpers.get().get().app.nodeEnv,
|
|
897
|
-
});
|
|
898
|
-
this.historicalDataInterval = setInterval(() => {
|
|
899
|
-
try {
|
|
900
|
-
const currentMetrics = this.collector.collectCurrentMetrics();
|
|
901
|
-
this.analytics.addDataPoint(currentMetrics);
|
|
902
|
-
this.logger.debug("Historical metrics collected", {
|
|
903
|
-
timestamp: new Date().toISOString(),
|
|
904
|
-
});
|
|
905
|
-
}
|
|
906
|
-
catch (_error) {
|
|
907
|
-
this.logger.error("Failed to collect historical metrics", {
|
|
908
|
-
_error: _error instanceof Error ? _error.message : String(_error),
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
}, interval);
|
|
912
|
-
}
|
|
913
|
-
/**
|
|
914
|
-
* Stop historical data collection and cleanup resources
|
|
915
|
-
*/
|
|
916
|
-
destroy() {
|
|
917
|
-
if (this.historicalDataInterval) {
|
|
918
|
-
clearInterval(this.historicalDataInterval);
|
|
919
|
-
this.historicalDataInterval = undefined;
|
|
920
|
-
this.logger.info("Historical data collection stopped");
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
}
|
|
13
|
+
export { default } from "./performance/index.js";
|
|
14
|
+
export { PerformanceTools } from "./performance/index.js";
|
|
15
|
+
export * from "./performance/PerformanceHelpers.js";
|
|
924
16
|
//# sourceMappingURL=performance.js.map
|