Performance Monitoring
The Rhema CLI includes a comprehensive performance monitoring system that helps you understand how the CLI performs and identify optimization opportunities.
Quick Start
Basic Usage
# Start performance monitoring
rhema performance start
# Check current system status
rhema performance status
# Generate a performance report
rhema performance report
# Stop monitoring
rhema performance stopDemo
Run the performance monitoring demo to see all features in action:
./examples/performance-monitoring-demo.shFeatures
System Performance Monitoring
Tracks real-time system metrics:
-
CPU Usage: Percentage of CPU utilization
-
Memory Usage: Current memory consumption in bytes and percentage
-
Disk I/O: Operations per second and bytes transferred
-
Network I/O: Bytes transferred and latency measurements
-
File System: Operations per second and latency
-
Process/Thread Count: Number of active processes and threads
-
Open File Descriptors: Current file descriptor usage
User Experience Monitoring
Measures user interaction quality:
-
Command Execution Time: How long commands take to complete
-
Success/Failure Rates: Percentage of successful vs failed commands
-
Response Time: Time from user input to first response
-
User Interaction Time: Time spent in interactive mode
-
User Satisfaction: Optional satisfaction scores (0-10)
-
Error Recovery Time: Time to recover from errors
Usage Analytics
Tracks how users interact with the CLI:
-
Command Frequency: Which commands are used most often
-
Feature Adoption: How quickly new features are adopted
-
Session Duration: How long users stay in interactive mode
-
Workflow Completion: Success rate of multi-step workflows
-
User Behavior Patterns: Common usage patterns and preferences
Performance Reporting
Generates comprehensive reports with:
-
System Performance Summary: Average and peak resource usage
-
User Experience Summary: Command performance and satisfaction metrics
-
Usage Analytics Summary: User behavior and feature usage
-
Performance Trends: Direction and magnitude of performance changes
-
Optimization Recommendations: Prioritized suggestions for improvements
-
Impact Assessment: Overall performance score and risk assessment
Configuration
Default Configuration
The performance monitoring system comes with sensible defaults:
# Performance thresholds
cpu_threshold: 80.0% # Alert when CPU > 80%
memory_threshold: 85.0% # Alert when memory > 85%
command_execution_threshold: 5000ms # Alert when commands > 5s
response_time_threshold: 1000ms # Alert when response > 1s
# Collection intervals
metrics_interval: 60s # Collect metrics every minute
report_interval: 24h # Generate reports every 24 hours
# Storage
retention_days: 30 # Keep metrics for 30 daysCustom Configuration
Create a custom configuration file:
# Copy the example configuration
cp examples/performance-config.yaml .rhema/performance-config.yaml
# Edit the configuration
nano .rhema/performance-config.yamlExample custom configuration:
# Development environment (lower thresholds)
thresholds:
cpu_threshold: 70.0
memory_threshold: 80.0
command_execution_threshold: 3000
# More frequent reporting
reporting:
report_interval: 6 # Every 6 hours
# Shorter retention for development
storage:
retention:
retention_days: 7Commands Reference
rhema performance start
Start performance monitoring with current configuration.
Options:
--config <file>: Use custom configuration file
Example:
rhema performance start --config .rhema/performance-config.yamlrhema performance stop
Stop performance monitoring and save current metrics.
rhema performance status
Display current system performance status with threshold alerts.
Output includes:
-
Current CPU and memory usage
-
Disk and network I/O rates
-
File system performance
-
Process and thread counts
-
Threshold violations (if any)
rhema performance report
Generate a comprehensive performance report.
Options:
-
--hours <number>: Hours to include in report (default: 24) -
--format <format>: Output format (json, yaml, html, markdown)
Example:
# Generate report for last 48 hours
rhema performance report --hours 48
# Generate HTML report
rhema performance report --format htmlrhema performance config
Display current performance monitoring configuration.
Understanding Reports
System Performance Summary
π» System Performance Summary
βββββββββββββββββββββββββββββββββββββββββββββββββ
CPU Usage: 25.3% avg, 75.2% peak
Memory Usage: 45.1% avg, 78.9% peak
Network Latency: 12.3 ms avg
Total Disk I/O: 156.7 MB
Total Network I/O: 89.2 MB
π¨ Performance Bottlenecks:
β’ High memory usage during peak hoursUser Experience Summary
π€ User Experience Summary
βββββββββββββββββββββββββββββββββββββββββββββββββ
Command Execution Time: 234.1 ms avg
Command Success Rate: 96.8%
Response Time: 45.2 ms avg
User Satisfaction: 8.7/10 avg
Error Rate: 3.2%
π¨ Common Errors:
β’ File not found
β’ Permission denied
π§ UX Improvements Needed:
β’ Reduce command execution timePerformance Trends
π Performance Trends
βββββββββββββββββββββββββββββββββββββββββββββββββ
π Command execution time: -15.2% change (confidence: 95.0%)
Command execution time has improved by 15% over the reporting period
β‘οΈ Memory usage: 2.1% change (confidence: 90.0%)
Memory usage has remained stable with only 2% increaseOptimization Recommendations
π§ Optimization Recommendations
βββββββββββββββββββββββββββββββββββββββββββββββββ
π΄ Optimize query execution (Priority: High)
Implement query caching to reduce execution time
Expected Impact: Reduce query execution time by 30%
Implementation Effort: Medium
π‘ Improve memory management (Priority: Medium)
Implement memory pooling for large operations
Expected Impact: Reduce memory usage by 20%
Implementation Effort: HighIntegration Examples
CI/CD Integration
Add performance monitoring to your CI/CD pipeline:
# .github/workflows/performance-check.yml
name: Performance Check
on: [push, pull_request]
jobs:
performance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Run Performance Tests
run: |
cargo test performance_monitoring_tests
rhema performance report --hours 1 --format json
- name: Upload Performance Report
uses: actions/upload-artifact@v3
with:
name: performance-report
path: performance-report.jsonAutomated Monitoring
Set up automated performance monitoring:
#!/bin/bash
# monitor-performance.sh
# Start monitoring
rhema performance start
# Wait for some activity
sleep 3600 # 1 hour
# Generate report
rhema performance report --format html
# Check for critical issues
if rhema performance status | grep -q "CPU usage exceeds threshold"; then
echo "WARNING: High CPU usage detected"
# Send alert
fi
# Stop monitoring
rhema performance stopCustom Metrics Integration
Integrate with external monitoring systems:
# Export metrics in Prometheus format
rhema performance report --format prometheus > metrics.prom
# Send to monitoring system
curl -X POST http://monitoring-system:9090/api/v1/write \
--data-binary @metrics.promBest Practices
Threshold Configuration
Development Environment:
-
CPU: 70-80%
-
Memory: 80-85%
-
Command execution: 3-5 seconds
-
Response time: 500ms-1s
Production Environment:
-
CPU: 60-70%
-
Memory: 70-80%
-
Command execution: 1-3 seconds
-
Response time: 200-500ms
Data Retention
-
Development: 7-14 days
-
Staging: 30 days
-
Production: 90+ days
Alert Configuration
Set up alerts for:
-
CPU usage > 80%
-
Memory usage > 85%
-
Error rate > 5%
-
Command execution time > 5 seconds
Regular Maintenance
-
Review performance reports weekly
-
Update thresholds based on usage patterns
-
Clean up old metrics data
-
Monitor trend analysis for degradation
Troubleshooting
Common Issues
High CPU Usage:
-
Check for long-running commands
-
Review query complexity
-
Consider implementing caching
High Memory Usage:
-
Look for memory leaks in long sessions
-
Review large data processing operations
-
Consider implementing pagination
Slow Command Execution:
-
Check system resources
-
Review command complexity
-
Consider optimizing queries
High Error Rates:
-
Review error logs
-
Check file permissions
-
Verify configuration files
Debug Mode
Enable debug logging for performance monitoring:
export RUST_LOG=debug
rhema performance startReset Performance Data
Clear all performance data:
rm -rf .rhema/performance/*API Reference
Performance Monitor
use rhema::PerformanceMonitor;
// Create monitor with default config
let monitor = PerformanceMonitor::new(PerformanceConfig::default())?;
// Start monitoring
monitor.start().await?;
// Record system metrics
monitor.record_system_metrics(data).await?;
// Record UX metrics
monitor.record_ux_metrics(data).await?;
// Generate report
let report = monitor.generate_performance_report(period).await?;Configuration Types
use rhema::performance::{
PerformanceConfig,
PerformanceThresholds,
ReportingConfig,
StorageConfig
};Contributing
To contribute to the performance monitoring system:
-
Review the current implementation in
src/performance.rs -
Add tests in
tests/performance_monitoring_tests.rs -
Update documentation in
docs/performance-monitoring.md -
Follow the existing code style and patterns
Support
For issues and questions:
-
Check the troubleshooting section above
-
Review the performance monitoring summary in
PERFORMANCE_MONITORING_SUMMARY.md -
Run the demo script to verify functionality
-
Check the test suite for examples of proper usage