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