# Import the module
from tmll.ml.modules.anomaly_detection.anomaly_detection_module import AnomalyDetection
# If you want to check all of the outputs that your experiment contains
for output in experiment.outputs:
print(f'Name: {output.name}') # Name of the output (e.g., CPU Usage, Disk I/O View, etc.)
print(f'Description: {output.description}') # Description of the output
print(f'Type: {output.type}') # Type of the output (e.g., TREE_TIME_XY, TABLE, etc.)
print(f'ID: {output.id}') # ID of the output
# Assuming your trace data already has information on "CPU Usage" and "Disk Usage"
outputs = experiment.find_outputs(keyword=['cpu usage', 'disk'], type=['xy'], match_any=True)
# Initialize the module
ad = AnomalyDetection(client=client, experiment=experiment, outputs=outputs, # Required params
resample=True, resample_freq='100ms') # Optional params (Check the API documentation to see the list of them)anomalies = ad.find_anomalies(method='zscore', zscore_threshold=3.5)anomalies = ad.find_anomalies(method='iqr')anomalies = ad.find_anomalies(method='moving_average',
moving_average_window_size=10,
moving_average_threshold=3)anomalies = ad.find_anomalies(method='combined',
moving_average_threshold=2,
zscore_threshold=3)anomalies = ad.find_anomalies(method='iforest',
iforest_window_size=100,
iforest_contamination=0.1,
iforest_random_state=42)anomalies = ad.find_anomalies(method='seasonality',
seasonality_seasonal_period=10,
seasonality_arima_order=(1,2,1),
seasonality_seasonal_order=(1,1,1),
seasonality_confidence_level=0.05)ad.plot_anomalies(anomalies, fig_size=(15,4), fig_dpi=300)# Import the module
from tmll.ml.modules.anomaly_detection.memory_leak_detection_module import MemoryLeakDetection
# Initialize the module
# Here, we don't need custom outputs, as the module automatically fetches the proper outputs of memory analysis
mld = MemoryLeakDetection(client=client, experiment=experiment)mem_leaks = mld.analyze_memory_leaks(window_size='1s', # The window size for trend analysis
fragmentation_threshold=0.70, # The threshold for memory fragmentation (%)
slope_threshold=0.5) # The threshold for memory growth slope (linear regression)mld.plot_memory_leak_analysis(mem_leaks)mld.interpret(mem_leaks)╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ Memory Leak Analysis Results │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Analysis Overview ──────────────────────────────────────────────────────────╮
│ │
│ Severity : MEDIUM │
│ Confidence Score: 1.00 │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Memory Metrics ─────────────────────────────────────────────────────────────╮
│ │
│ Unreleased Allocations : 3609 │
│ Total Allocations : 37707 │
│ Leak Rate : 0.54 B/s │
│ Average Allocation Size: 149.85 B │
│ Max Continuous Growth : 1.24 s │
│ Memory Fragmentation : 9.61% │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Detected Patterns ──────────────────────────────────────────────────────────╮
│ │
│ 1: Systematic memory growth detected: 0.54 B/s │
│ 2: Irregular allocation pattern detected │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯ Top 5 Suspicious Locations
╭───────────────────┬───────────┬────────────────────┬─────────────────────────╮
│ │ │ │ │
│ Pointer │Size │Allocation Count │Event Context │
├───────────────────┼───────────┼────────────────────┼─────────────────────────┤
│ │ │ │ │
│ 0x5629b645f860 │32.00 KB │1 │lttng_ust_libc:malloc │
│ │ │ │ │
│ 0x5629b6432100 │32.00 KB │1 │lttng_ust_libc:malloc │
│ │ │ │ │
│ 0x5629b6495590 │32.00 KB │1 │lttng_ust_libc:malloc │
│ │ │ │ │
│ 0x5629b6419030 │32.00 KB │1 │lttng_ust_libc:malloc │
│ │ │ │ │
│ 0x5629b644c4c0 │32.00 KB │1 │lttng_ust_libc:malloc │
│ │ │ │ │
╰───────────────────┴───────────┴────────────────────┴─────────────────────────╯╭─ Memory Usage Statistics ────────────────────────────────────────────────────╮
│ │
│ Peak Memory Usage : 626.10 KB │
│ Average Memory Usage: 79.55 KB │
│ Memory Usage Std Dev: 205.31 KB │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Allocation Statistics ──────────────────────────────────────────────────────╮
│ │
│ Total Allocations : 37,707 │
│ Total Deallocations : 202,468 │
│ Unmatched Allocations: 3,609 │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Pointer Lifetime Statistics ────────────────────────────────────────────────╮
│ │
│ Average Lifetime: 206.21 ms │
│ Median Lifetime : 9.59 ms │
│ Maximum Lifetime: 2.24 s │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯# Import the module
from tmll.ml.modules.root_cause.correlation_analysis_module import CorrelationAnalysis
# Get the outputs of CPU, Memory, Disk usage, and Histogram (i.e., number of events in each timestamp)
outputs = experiment.find_outputs(keyword=['cpu usage', 'memory usage', 'disk', 'histogram'], type=['xy'], match_any=True)
# Initialize the module
ca = CorrelationAnalysis(client, experiment, outputs)# Analyze the correlations
correlations = ca.analyze_correlations()
# You may also indicate specific start/end times to
# analyze the correlations only during that period
correlations = ca.analyze_correlations(start_time=pd.Timestamp("2025-01-01 18:00:00"),
end_time=pd.Timestamp("2025-01-01 18:30:00"))ca.plot_correlation_matrix(correlations)ca.plot_time_series(series=["CPU Usage", "Memory Usage", "Histogram", "Disk I/O View"])lag_analysis = ca.analyze_lags(series1_name="Histogram", series2_name="Memory Usage", max_lag=10)# Import the module
from tmll.ml.modules.performance_trend.change_point_module import ChangePointAnalysis
# Get the outputs of CPU, Memory, Disk usage, and Histogram (i.e., number of events in each timestamp)
outputs = experiment.find_outputs(keyword=['cpu usage', 'memory usage', 'disk', 'histogram'], type=['xy'], match_any=True)
# Initialize the module
cpa = ChangePointAnalysis(client, experiment, outputs)# Find the top-2 change points in the data
# Since we are using tune_hyperparameters, all the optional params are indicated automatically
change_points = cpa.get_change_points(n_change_points=2, tune_hyperparameters=True)# Import the module
from tmll.ml.modules.predictive_maintenance.capacity_planning_module import CapacityPlanning
# Initialize the module
# You don't need to specify outputs for this module as it automatically fetches CPU, memory, and disk usage
cp = CapacityPlanning(client, experiment)forecasts = cp.forecast_capacity(method="moving_average", # Which method to use
warning_period='50ms', # Mark as an alarm if exceeds the threshold beyond this period
forecast_steps=1000, # How many steps (time units) to forecast
disk_threshold=275*1024*1024, # 275MB/s
memory_threshold=1024*1024*1024, # 1GB
cpu_threshold=130) # 130% (i.e., for 2 cores)cp.plot_capacity_forecast(forecasts, zoomed=False) # Set True to focus more on forecastscp.interpret(forecasts)╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ Capacity Planning Analysis Results │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ CPU Capacity Analysis │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Analysis Parameters ────────────────────────────────────────────────────────╮
│ │
│ Analysis Period Start: 2024-04-24 02:13:11.827000 │
│ Analysis Period End : 2024-04-24 02:13:12.826000 │
│ Forecast Method : MOVING_AVERAGE │
│ CPU Threshold : 130.00% │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Resource: CPU Usage ────────────────────────────────────────────────────────╮
│ │
│ Current Usage : 100.00% │
│ Peak Usage : 200.00% │
│ Average Usage : 121.77% │
│ Utilization Pattern : Moderate variation │
│ Next Threshold Violation: 2024-04-24 02:13:12.101000 │
│ Total Violations : 7 │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯ Top Threshold Violations for CPU Usage
╭────────────────────────┬────────────────────────┬──────────┬─────────────────╮
│ │ │ │ │
│ Start │End │Duration │Forecasted Usage │
├────────────────────────┼────────────────────────┼──────────┼─────────────────┤
│ │ │ │ │
│ 2024-04-24 │2024-04-24 │250.00 ms │200.00% │
│ 02:13:12.101000 │02:13:12.351000 │ │ │
│ │ │ │ │
│ 2024-04-24 │2024-04-24 │39.00 ms │200.00% │
│ 02:13:12.701000 │02:13:12.740000 │ │ │
│ │ │ │ │
│ 2024-04-24 │2024-04-24 │26.00 ms │200.00% │
│ 02:13:12.800000 │02:13:12.826000 │ │ │
│ │ │ │ │
│ 2024-04-24 │2024-04-24 │20.00 ms │199.14% │
│ 02:13:11.827000 │02:13:11.847000 │ │ │
│ │ │ │ │
│ 2024-04-24 │2024-04-24 │5.00 ms │173.68% │
│ 02:13:12.785000 │02:13:12.790000 │ │ │
│ │ │ │ │
╰────────────────────────┴────────────────────────┴──────────┴─────────────────╯╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ MEMORY Capacity Analysis │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Analysis Parameters ────────────────────────────────────────────────────────╮
│ │
│ Analysis Period Start: 2024-04-24 02:13:11.827000 │
│ Analysis Period End : 2024-04-24 02:13:12.826000 │
│ Forecast Method : MOVING_AVERAGE │
│ MEMORY Threshold : 1.00GB │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Resource: Memory Usage ─────────────────────────────────────────────────────╮
│ │
│ Current Usage : 647.77MB │
│ Peak Usage : 650.94MB │
│ Average Usage : 509.47MB │
│ Utilization Pattern: Moderate variation │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ DISK Capacity Analysis │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Analysis Parameters ────────────────────────────────────────────────────────╮
│ │
│ Analysis Period Start: 2024-04-24 02:13:11.827000 │
│ Analysis Period End : 2024-04-24 02:13:12.826000 │
│ Forecast Method : MOVING_AVERAGE │
│ DISK Threshold : 275.00MB/s │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Resource: Disk I/O View ────────────────────────────────────────────────────╮
│ │
│ Current Usage : 0.00B/s │
│ Peak Usage : 470.12MB/s │
│ Average Usage : 57.31MB/s │
│ Utilization Pattern : Highly variable │
│ Next Threshold Violation: 2024-04-24 02:13:12.104000 │
│ Total Violations : 5 │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯ Top Threshold Violations for Disk I/O View
╭─────────────────────────┬────────────────────────┬─────────┬─────────────────╮
│ │ │ │ │
│ Start │End │Duration │Forecasted Usage │
├─────────────────────────┼────────────────────────┼─────────┼─────────────────┤
│ │ │ │ │
│ 2024-04-24 │2024-04-24 │92.00 ms │362.87MB/s │
│ 02:13:12.104000 │02:13:12.196000 │ │ │
│ │ │ │ │
│ 2024-04-24 │2024-04-24 │33.00 ms │328.86MB/s │
│ 02:13:12.788000 │02:13:12.821000 │ │ │
│ │ │ │ │
│ 2024-04-24 │2024-04-24 │31.00 ms │381.01MB/s │
│ 02:13:12.209000 │02:13:12.240000 │ │ │
│ │ │ │ │
│ 2024-04-24 │2024-04-24 │1.00 ms │281.15MB/s │
│ 02:13:12.749000 │02:13:12.750000 │ │ │
│ │ │ │ │
╰─────────────────────────┴────────────────────────┴─────────┴─────────────────╯╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ Capacity Planning Recommendations │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Immediate Actions ──────────────────────────────────────────────────────────╮
│ │
│ 1: Critical: CPU Usage will exceed 130.00% in 275.00 ms. Consider immediate │
│ load balancing or scaling up CPU capacity. │
│ 2: Critical: Disk I/O View will exceed 275.00MB/s in 278.00 ms. Consider │
│ cleanup or adding storage capacity. │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Short-term Planning ────────────────────────────────────────────────────────╮
│ │
│ 1: Resource utilization is within acceptable limits. No immediate action │
│ required. │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Long-term Strategy ─────────────────────────────────────────────────────────╮
│ │
│ 1: CPU Usage has peak usage (200.00%) approaching or bypassing the threshold │
│ (130.00%). Consider increasing capacity or implementing load balancing. │
│ 2: Disk I/O View shows highly variable usage patterns. Consider implementing │
│ auto-scaling or dynamic resource allocation. │
│ 3: Disk I/O View has peak usage (470.12MB/s) approaching or bypassing the │
│ threshold (275.00MB/s). Consider increasing capacity or implementing load │
│ balancing. │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Optimization Opportunities ─────────────────────────────────────────────────╮
│ │
│ 1: Resource utilization is within acceptable limits. No immediate action │
│ required. │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯# Import the module
from tmll.ml.modules.resource_optimization.idle_resource_detection_module import IdleResourceDetection
# Find the outputs for CPU, memory, and disk usage
outputs = experiment.find_outputs(match_any=True, keyword=['cpu usage', 'memory usage', 'disk'], type=['xy'])
# Also find the outputs for Resources, so we can analyze CPU scheduling
outputs.extend(experiment.find_outputs(match_any=True, keyword=['resources'], type=['time_graph']))
# Initialize the module
ird = IdleResourceDetection(client, experiment, outputs)res_idle = ird.analyze_idle_resources(idle_time='750ms', # 750ms idle time
cpu_idle_threshold=130, # 130% (i.e., for 2 cores)
disk_idle_threshold=275*1024*1024, # 275MB/s
memory_idle_threshold=600*1024*1024) # 600MBird.plot_resource_utilization(res_idle)res_sched = ird.analyze_cpu_scheduling()ird.plot_cpu_scheduling(res_sched)ird.interpret(res_idle, res_sched)╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ Idle Resource Detection Analysis Results │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Overall Resources Utilization ──────────────────────────────────────────────╮
│ │
│ CPU Average Usage : 121.77% │
│ CPU Monitoring Duration : 2.24s │
│ MEMORY Average Usage : 509.47MB │
│ MEMORY Monitoring Duration: 2.24s │
│ DISK Average Usage : 57.31MB/s │
│ DISK Monitoring Duration : 2.24s │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ CPU Resource Analysis │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Analysis Parameters ────────────────────────────────────────────────────────╮
│ │
│ Analysis Period Start: 2024-04-24 02:13:09.586000 │
│ Analysis Period End : 2024-04-24 02:13:11.826000 │
│ CPU Idle Threshold : 130.00% │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Resource: CPU Usage ────────────────────────────────────────────────────────╮
│ │
│ Average Usage : 121.77% │
│ Peak Usage : 200.00% │
│ Idle Time Percentage : 44.0% │
│ Total Duration : 2.24s │
│ Usage Pattern : Moderate variation │
│ Number of Idle Periods: 1 │
│ Longest Idle Period : 0.98s │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯ Top Idle Periods for CPU Usage
╭─────────────────────────────────┬────────────────────────────────┬───────────╮
│ │ │ │
│ Start Time │End Time │Duration │
├─────────────────────────────────┼────────────────────────────────┼───────────┤
│ │ │ │
│ 2024-04-24 02:13:09.703000 │2024-04-24 02:13:10.688000 │985.00 ms │
│ │ │ │
╰─────────────────────────────────┴────────────────────────────────┴───────────╯╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ MEMORY Resource Analysis │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Analysis Parameters ────────────────────────────────────────────────────────╮
│ │
│ Analysis Period Start: 2024-04-24 02:13:09.586000 │
│ Analysis Period End : 2024-04-24 02:13:11.826000 │
│ MEMORY Idle Threshold: 600.00MB │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Resource: Memory Usage ─────────────────────────────────────────────────────╮
│ │
│ Average Usage : 509.47MB │
│ Peak Usage : 650.94MB │
│ Idle Time Percentage : 52.5% │
│ Total Duration : 2.24s │
│ Usage Pattern : Moderate variation │
│ Number of Idle Periods: 1 │
│ Longest Idle Period : 1.18s │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯ Top Idle Periods for Memory Usage
╭──────────────────────────────────┬────────────────────────────────┬──────────╮
│ │ │ │
│ Start Time │End Time │Duration │
├──────────────────────────────────┼────────────────────────────────┼──────────┤
│ │ │ │
│ 2024-04-24 02:13:09.586000 │2024-04-24 02:13:10.763000 │1.18 s │
│ │ │ │
╰──────────────────────────────────┴────────────────────────────────┴──────────╯╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ DISK Resource Analysis │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Analysis Parameters ────────────────────────────────────────────────────────╮
│ │
│ Analysis Period Start: 2024-04-24 02:13:09.586000 │
│ Analysis Period End : 2024-04-24 02:13:11.826000 │
│ DISK Idle Threshold : 275.00MB/s │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Resource: Disk I/O View ────────────────────────────────────────────────────╮
│ │
│ Average Usage : 57.31MB/s │
│ Peak Usage : 470.12MB/s │
│ Idle Time Percentage : 55.7% │
│ Total Duration : 2.24s │
│ Usage Pattern : Highly variable │
│ Number of Idle Periods: 1 │
│ Longest Idle Period : 1.25s │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯ Top Idle Periods for Disk I/O View
╭──────────────────────────────────┬────────────────────────────────┬──────────╮
│ │ │ │
│ Start Time │End Time │Duration │
├──────────────────────────────────┼────────────────────────────────┼──────────┤
│ │ │ │
│ 2024-04-24 02:13:09.586000 │2024-04-24 02:13:10.833000 │1.25 s │
│ │ │ │
╰──────────────────────────────────┴────────────────────────────────┴──────────╯╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ CPU Scheduling Analysis │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Overall Scheduling Metrics ─────────────────────────────────────────────────╮
│ │
│ Total CPUs : 2 │
│ Total Context Switches: 2,824 │
│ Total Unique Tasks : 83 │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ CPU 1 Scheduling Metrics ───────────────────────────────────────────────────╮
│ │
│ CPU Utilization : 94.8% │
│ Context Switches/s : 921.6 │
│ Unique Tasks : 36 │
│ Active/Idle Samples : 2,826/155 │
│ Number of Idle Periods: 117 │
│ Average Idle Period : 132.48 us │
│ Longest Idle Period : 800.00 us │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯ Top Tasks for CPU 1
╭─────────────────────────────────────────────────┬────────────────────────────╮
│ │ │
│ Task │Active Time % │
├─────────────────────────────────────────────────┼────────────────────────────┤
│ │ │
│ ssh (34286) │55.7% │
│ │ │
│ kworker/u4:1 (27955) │33.2% │
│ │ │
│ lttng-consumerd (1781) │3.5% │
│ │ │
│ Application not (749) │1.3% │
│ │ │
│ rcu_sched (14) │1.0% │
│ │ │
╰─────────────────────────────────────────────────┴────────────────────────────╯╭─ CPU 2 Scheduling Metrics ───────────────────────────────────────────────────╮
│ │
│ CPU Utilization : 82.0% │
│ Context Switches/s : 340.2 │
│ Unique Tasks : 47 │
│ Active/Idle Samples : 1,700/373 │
│ Number of Idle Periods: 319 │
│ Average Idle Period : 116.93 us │
│ Longest Idle Period : 1.50 ms │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯ Top Tasks for CPU 2
╭─────────────────────────────────────────────────┬────────────────────────────╮
│ │ │
│ Task │Active Time % │
├─────────────────────────────────────────────────┼────────────────────────────┤
│ │ │
│ lttng-consumerd (1782) │67.6% │
│ │ │
│ kworker/u4:1 (27955) │12.8% │
│ │ │
│ ssh-ust (34287) │2.8% │
│ │ │
│ kworker/u4:4 (17233) │2.2% │
│ │ │
│ systemd (1) │1.8% │
│ │ │
╰─────────────────────────────────────────────────┴────────────────────────────╯╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ Resource Optimization Recommendations │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Workload Distribution ──────────────────────────────────────────────────────╮
│ │
│ 1: Consider consolidating workloads on the following CPUs: │
│ • CPU Usage (44.0% idle) │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Resource Utilization ───────────────────────────────────────────────────────╮
│ │
│ 1: Peak CPU usage exceeds 90% on: │
│ • CPU Usage (200.0%) │
│ Consider implementing load balancing or scaling resources │
│ 2: Memory allocation could be optimized for: │
│ • Memory Usage (Using 509.47 MB, 52.5% idle) │
│ 3: High CPU utilization detected: │
│ • CPU 1 (94.8%) │
│ • CPU 2 (82.0%) │
│ Recommended actions: │
│ - Implement dynamic load balancing │
│ - Configure task prioritization │
│ - Consider resource scaling │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ Performance Optimization ───────────────────────────────────────────────────╮
│ │
│ 1: High context switch rates detected: │
│ • CPU 1 (921.6/s) │
│ • CPU 2 (340.2/s) │
│ Recommended actions: │
│ - Review task scheduling policy │
│ - Implement task affinity │
│ - Adjust time slice duration │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯╭─ System Configuration ───────────────────────────────────────────────────────╮
│ │
│ 1: Everything looks good! No specific recommendations at this time. │
│ │
╰──────────────────────────────────────────────────────────────────────────────╯



























