Class: Kdeploy::Statistics
- Inherits:
-
Object
- Object
- Kdeploy::Statistics
- Defined in:
- lib/kdeploy/statistics.rb
Overview
Handles deployment statistics collection and analysis
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#clear_statistics! ⇒ Object
Clear all statistics.
-
#deployment_summary(days: 30) ⇒ Hash
Get deployment statistics summary.
-
#export_statistics(file_path, format: :json) ⇒ Object
Export statistics to file.
-
#global_summary ⇒ Hash
Get global statistics.
-
#initialize(stats_file: nil) ⇒ Statistics
constructor
A new instance of Statistics.
-
#performance_trends(days: 7) ⇒ Hash
Get performance trends.
-
#record_command(command_name, host, success, duration) ⇒ Object
Record a command execution.
-
#record_deployment(result) ⇒ Object
Record a deployment execution.
-
#record_task(task_name, result) ⇒ Object
Record a task execution.
-
#task_summary(days: 30) ⇒ Hash
Get task statistics summary.
-
#top_failed_tasks(limit: 10, days: 30) ⇒ Array
Get top failed tasks.
Constructor Details
#initialize(stats_file: nil) ⇒ Statistics
Returns a new instance of Statistics.
8 9 10 11 12 |
# File 'lib/kdeploy/statistics.rb', line 8 def initialize(stats_file: nil) @stats_file = stats_file || default_stats_file @data = load_statistics @session_start_time = Time.now end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/kdeploy/statistics.rb', line 6 def data @data end |
Instance Method Details
#clear_statistics! ⇒ Object
Clear all statistics
112 113 114 115 |
# File 'lib/kdeploy/statistics.rb', line 112 def clear_statistics! @data = default_statistics_structure save_statistics end |
#deployment_summary(days: 30) ⇒ Hash
Get deployment statistics summary
48 49 50 51 52 53 54 55 |
# File 'lib/kdeploy/statistics.rb', line 48 def deployment_summary(days: 30) cutoff_time = calculate_cutoff_time(days) recent_deployments = filter_recent_data(@data[:deployments], cutoff_time) return empty_summary if recent_deployments.empty? build_deployment_summary(recent_deployments, days) end |
#export_statistics(file_path, format: :json) ⇒ Object
Export statistics to file
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/kdeploy/statistics.rb', line 120 def export_statistics(file_path, format: :json) case format when :json export_to_json(file_path) when :csv export_to_csv(file_path) else raise ArgumentError, "Unsupported export format: #{format}" end end |
#global_summary ⇒ Hash
Get global statistics
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/kdeploy/statistics.rb', line 71 def global_summary { total_deployments: @data[:global][:deployments][:total], successful_deployments: @data[:global][:deployments][:successful], failed_deployments: @data[:global][:deployments][:failed], total_tasks: @data[:global][:tasks][:total], successful_tasks: @data[:global][:tasks][:successful], failed_tasks: @data[:global][:tasks][:failed], total_commands: @data[:global][:commands][:total], successful_commands: @data[:global][:commands][:successful], failed_commands: @data[:global][:commands][:failed], total_execution_time: @data[:global][:total_execution_time].round(2), session_start_time: @session_start_time, session_duration: (Time.now - @session_start_time).round(2) } end |
#performance_trends(days: 7) ⇒ Hash
Get performance trends
102 103 104 105 106 107 108 109 |
# File 'lib/kdeploy/statistics.rb', line 102 def performance_trends(days: 7) cutoff_time = calculate_cutoff_time(days) recent_deployments = filter_recent_data(@data[:deployments], cutoff_time) return { period_days: days, trends: {} } if recent_deployments.empty? build_performance_trends(recent_deployments, days) end |
#record_command(command_name, host, success, duration) ⇒ Object
Record a command execution
38 39 40 41 42 43 |
# File 'lib/kdeploy/statistics.rb', line 38 def record_command(command_name, host, success, duration) command_data = build_command_data(command_name, host, success, duration) @data[:commands] << command_data update_command_stats(command_data) save_statistics end |
#record_deployment(result) ⇒ Object
Record a deployment execution
16 17 18 19 20 21 |
# File 'lib/kdeploy/statistics.rb', line 16 def record_deployment(result) deployment_data = build_deployment_data(result) @data[:deployments] << deployment_data update_global_stats(deployment_data) save_statistics end |
#record_task(task_name, result) ⇒ Object
Record a task execution
26 27 28 29 30 31 |
# File 'lib/kdeploy/statistics.rb', line 26 def record_task(task_name, result) task_data = build_task_data(task_name, result) @data[:tasks] << task_data update_task_stats(task_data) save_statistics end |
#task_summary(days: 30) ⇒ Hash
Get task statistics summary
60 61 62 63 64 65 66 67 |
# File 'lib/kdeploy/statistics.rb', line 60 def task_summary(days: 30) cutoff_time = calculate_cutoff_time(days) recent_tasks = filter_recent_data(@data[:tasks], cutoff_time) return empty_task_summary(days) if recent_tasks.empty? build_task_summary(recent_tasks, days) end |
#top_failed_tasks(limit: 10, days: 30) ⇒ Array
Get top failed tasks
92 93 94 95 96 97 |
# File 'lib/kdeploy/statistics.rb', line 92 def top_failed_tasks(limit: 10, days: 30) cutoff_time = calculate_cutoff_time(days) recent_tasks = filter_recent_failed_tasks(cutoff_time) build_top_failed_tasks(recent_tasks, limit) end |