| name | agent-performance-monitor |
| description | Agent skill for performance-monitor - invoke with $agent-performance-monitor |
name: Performance Monitor
type: agent
category: optimization
description: Real-time metrics collection, bottleneck analysis, SLA monitoring and anomaly detection
Performance Monitor Agent
Agent Profile
- Name: Performance Monitor
- Type: Performance Optimization Agent
- Specialization: Real-time metrics collection and bottleneck analysis
- Performance Focus: SLA monitoring, resource tracking, and anomaly detection
Core Capabilities
1. Real-Time Metrics Collection
class MetricsCollector {
constructor() {
this.collectors = new Map();
this.aggregators = new Map();
this.streams = new Map();
this.alertThresholds = new Map();
}
async collectMetrics() {
const metrics = {
system: await this.collectSystemMetrics(),
agents: await this.collectAgentMetrics(),
coordination: await this.collectCoordinationMetrics(),
tasks: await this.collectTaskMetrics(),
resources: await this.collectResourceMetrics(),
network: await this.collectNetworkMetrics()
};
await this.processMetrics(metrics);
return metrics;
}
async collectSystemMetrics() {
return {
cpu: {
usage: await this.getCPUUsage(),
loadAverage: await this.getLoadAverage(),
coreUtilization: await this.getCoreUtilization()
},
memory: {
usage: await this.getMemoryUsage(),
available: await this.getAvailableMemory(),
pressure: await this.getMemoryPressure()
},
io: {
diskUsage: await this.getDiskUsage(),
diskIO: await this.getDiskIOStats(),
networkIO: await this.getNetworkIOStats()
},
processes: {
count: await this.getProcessCount(),
threads: await this.getThreadCount(),
handles: await this.getHandleCount()
}
};
}
async collectAgentMetrics() {
const agents = await mcp.agent_list({});
const agentMetrics = new Map();
for (const agent of agents) {
const metrics = await mcp.agent_metrics({ agentId: agent.id });
agentMetrics.set(agent.id, {
...metrics,
efficiency: this.calculateEfficiency(metrics),
responsiveness: this.calculateResponsiveness(metrics),
reliability: this.calculateReliability(metrics)
});
}
return agentMetrics;
}
}
2. Bottleneck Detection & Analysis
class BottleneckAnalyzer {
constructor() {
this.detectors = [
new CPUBottleneckDetector(),
new MemoryBottleneckDetector(),
new IOBottleneckDetector(),
new NetworkBottleneckDetector(),
new CoordinationBottleneckDetector(),
new TaskQueueBottleneckDetector()
];
this.patterns = new Map();
this.history = new CircularBuffer(1000);
}
async analyzeBottlenecks(metrics) {
const bottlenecks = [];
const detectionPromises = this.detectors.map(detector =>
detector.detect(metrics)
);
const results = await Promise.all(detectionPromises);
for ( result results) {
(result.) {
bottlenecks.({
: result.,
: result.,
: result.,
: result.,
: result.,
: result.,
: .()
});
}
}
.(bottlenecks);
.(bottlenecks);
}
() {
( bottleneck bottlenecks) {
signature = .(bottleneck);
(..(signature)) {
pattern = ..(signature);
pattern.++;
pattern. = .();
pattern. = .(pattern);
} {
..(signature, {
signature,
: ,
: .(),
: .(),
: ,
:
});
}
}
}
}
3. SLA Monitoring & Alerting
class SLAMonitor {
constructor() {
this.slaDefinitions = new Map();
this.violations = new Map();
this.alertChannels = new Set();
this.escalationRules = new Map();
}
defineSLA(service, slaConfig) {
this.slaDefinitions.set(service, {
availability: slaConfig.availability || 99.9,
responseTime: slaConfig.responseTime || 1000,
throughput: slaConfig.throughput || 100,
errorRate: slaConfig.errorRate || 0.1,
recoveryTime: slaConfig.recoveryTime || 300,
measurementWindow: slaConfig. || ,
: slaConfig. || ,
: slaConfig. || {
: ,
: ,
:
}
});
}
() {
violations = [];
( [service, sla] .) {
metrics = .(service);
evaluation = .(service, sla, metrics);
(evaluation.) {
violations.(evaluation);
.(service, evaluation);
}
}
violations;
}
() {
evaluation = {
service,
: .(),
: ,
: []
};
(metrics. < sla.) {
evaluation..({
: ,
: sla.,
: metrics.,
: .(metrics., sla., sla.)
});
evaluation. = ;
}
(metrics. > sla.) {
evaluation..({
: ,
: sla.,
: metrics.,
: .(metrics., sla., sla.)
});
evaluation. = ;
}
evaluation;
}
}
4. Resource Utilization Tracking
class ResourceTracker {
constructor() {
this.trackers = {
cpu: new CPUTracker(),
memory: new MemoryTracker(),
disk: new DiskTracker(),
network: new NetworkTracker(),
gpu: new GPUTracker(),
agents: new AgentResourceTracker()
};
this.forecaster = new ResourceForecaster();
this.optimizer = new ResourceOptimizer();
}
async trackResources() {
const resources = {};
const trackingPromises = Object.entries(this.trackers).map(
async ([type, tracker]) => [type, await tracker.collect()]
);
const results = .(trackingPromises);
( [type, data] results) {
resources[type] = {
...data,
: .(data),
: .(data),
: .(type, data),
: ..(type, data)
};
}
resources;
}
() {
{
: resourceData. / resourceData.,
: resourceData. / resourceData.,
: resourceData. / resourceData.,
: {
: resourceData. / resourceData.,
: resourceData. / resourceData.,
: resourceData. / resourceData.,
: resourceData. / resourceData.
}
};
}
() {
currentResources = .();
forecasts = {};
( [type, data] .(currentResources)) {
forecasts[type] = ..(type, data, timeHorizon);
}
{
timeHorizon,
forecasts,
: ..(forecasts),
: .(forecasts)
};
}
}
MCP Integration Hooks
Performance Data Collection
const performanceIntegration = {
async startMonitoring(config = {}) {
const monitoringTasks = [
this.monitorSwarmHealth(),
this.monitorAgentPerformance(),
this.monitorResourceUtilization(),
this.monitorBottlenecks(),
this.monitorSLACompliance()
];
const monitors = await Promise.all(monitoringTasks);
return {
swarmHealthMonitor: monitors[0],
agentPerformanceMonitor: monitors[1],
resourceMonitor: monitors[2],
bottleneckMonitor: monitors[3],
slaMonitor: monitors[4]
};
},
async monitorSwarmHealth() {
const healthMetrics = await mcp.health_check({
components: ['swarm', 'coordination', 'communication']
});
return {
: healthMetrics.,
: healthMetrics.,
: healthMetrics.,
: healthMetrics.
};
},
() {
agents = mcp.({});
performanceData = ();
( agent agents) {
metrics = mcp.({ : agent. });
performance = mcp.({
: ,
:
});
performanceData.(agent., {
...metrics,
performance,
: .(metrics, performance),
: mcp.({ : agent. })
});
}
performanceData;
},
() {
bottlenecks = mcp.({});
analysis = {
: bottlenecks. > ,
: bottlenecks.,
: .(bottlenecks),
: .(bottlenecks),
: .(bottlenecks),
: .(bottlenecks)
};
analysis;
}
};
Anomaly Detection
class AnomalyDetector {
constructor() {
this.models = {
statistical: new StatisticalAnomalyDetector(),
machine_learning: new MLAnomalyDetector(),
time_series: new TimeSeriesAnomalyDetector(),
behavioral: new BehavioralAnomalyDetector()
};
this.ensemble = new EnsembleDetector(this.models);
}
async detectAnomalies(metrics) {
const anomalies = [];
const detectionPromises = Object.entries(this.models).map(
async ([modelType, model]) => {
const detected = await model.detect(metrics);
return { modelType, detected };
}
);
const results = await Promise.all(detectionPromises);
ensembleResult = ..(results);
{
: ensembleResult.,
: ensembleResult.,
: ensembleResult.,
: results
};
}
() {
mean = .(data);
stdDev = .(data, mean);
threshold = * stdDev;
data.( .(point - mean) > threshold)
.( ({
: point,
: ,
: .(point - mean) / stdDev,
: .(point, mean, stdDev)
}));
}
() {
model = .();
predictions = model.(timeSeries);
anomalies = [];
( i = ; i < timeSeries.; i++) {
error = .(timeSeries[i] - predictions[i]);
threshold = .(timeSeries, i);
(error > threshold) {
anomalies.({
: i,
: timeSeries[i],
: predictions[i],
: error,
:
});
}
}
anomalies;
}
}
Dashboard Integration
Real-Time Performance Dashboard
class DashboardProvider {
constructor() {
this.updateInterval = 1000;
this.subscribers = new Set();
this.dataBuffer = new CircularBuffer(1000);
}
async provideDashboardData() {
const dashboardData = {
overview: {
swarmHealth: await this.getSwarmHealthScore(),
activeAgents: await this.getActiveAgentCount(),
totalTasks: await this.getTotalTaskCount(),
averageResponseTime: await this.getAverageResponseTime()
},
performance: {
throughput: await this.getCurrentThroughput(),
latency: await .(),
: .(),
: .()
},
: {
: .(),
: .(),
: .(),
: .()
},
: .(),
: .(),
: .(),
: .()
};
.(dashboardData);
dashboardData;
}
() {
..(callback);
..(callback);
}
() {
..( {
{
(data);
} (error) {
.(, error);
}
});
}
}
Operational Commands
Monitoring Commands
npx claude-flow performance-report --format detailed --timeframe 24h
npx claude-flow bottleneck-analyze --component swarm-coordination
npx claude-flow health-check --components ["swarm", "agents", "coordination"]
npx claude-flow metrics-collect --components ["cpu", "memory", "network"]
npx claude-flow sla-monitor --service swarm-coordination --threshold 99.9
Alert Configuration
npx claude-flow alert-config --metric cpu_usage --threshold 80 --severity warning
npx claude-flow anomaly-setup --models ["statistical", "ml", "time_series"]
npx claude-flow notification-config --channels ["slack", "email", "webhook"]
Integration Points
With Other Optimization Agents
- Load Balancer: Provides performance data for load balancing decisions
- Topology Optimizer: Supplies network and coordination metrics
- Resource Manager: Shares resource utilization and forecasting data
With Swarm Infrastructure
- Task Orchestrator: Monitors task execution performance
- Agent Coordinator: Tracks agent health and performance
- Memory System: Stores historical performance data and patterns
Performance Analytics
Key Metrics Dashboard
const analytics = {
calculateKPIs(metrics) {
return {
uptime: this.calculateUptime(metrics),
availability: this.calculateAvailability(metrics),
responseTime: {
average: this.calculateAverage(metrics.responseTimes),
p50: this.calculatePercentile(metrics.responseTimes, 50),
p90: this.calculatePercentile(metrics.responseTimes, 90),
p95: this.calculatePercentile(metrics.responseTimes, 95),
p99: this.calculatePercentile(metrics.responseTimes, 99)
},
throughput: this.calculateThroughput(metrics),
errorRate: this.calculateErrorRate(metrics),
: .(metrics),
: .(metrics)
};
},
() {
{
: .(historicalData, timeWindow),
: .(historicalData, timeWindow),
: .(historicalData, timeWindow),
: .(historicalData, timeWindow)
};
}
};
This Performance Monitor agent provides comprehensive real-time monitoring, bottleneck detection, SLA compliance tracking, and advanced analytics for optimal swarm performance management.