Class: Tasker::Registry::StatisticsCollector

Inherits:
Object
  • Object
show all
Includes:
Concerns::StructuredLogging
Defined in:
lib/tasker/registry/statistics_collector.rb

Overview

Comprehensive statistics collection for all registry systems

Provides unified observability, performance monitoring, and health checking across all registry components.

Constant Summary

Constants included from Concerns::StructuredLogging

Concerns::StructuredLogging::CORRELATION_ID_KEY

Class Method Summary collapse

Methods included from Concerns::StructuredLogging

#correlation_id, #correlation_id=, #log_exception, #log_orchestration_event, #log_performance_event, #log_step_event, #log_structured, #log_task_event, #with_correlation_id

Class Method Details

.collect_all_registry_statsHash

Collect comprehensive statistics from all registries

Returns:

  • (Hash)

    Complete statistics for all registries



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tasker/registry/statistics_collector.rb', line 19

def collect_all_registry_stats
  registries = discover_all_registries

  stats = {
    collection_timestamp: Time.current,
    total_registries: registries.size,
    registries: {}
  }

  registries.each do |registry|
    registry_stats = collect_registry_stats(registry)
    stats[:registries][registry_stats[:registry_name]] = registry_stats
  end

  # Calculate aggregated metrics
  stats[:aggregated] = calculate_aggregated_metrics(stats[:registries])

  stats
end

.collect_registry_stats(registry) ⇒ Hash

Collect statistics from a specific registry

Parameters:

  • registry (BaseRegistry)

    Registry to collect stats from

Returns:

  • (Hash)

    Registry statistics with performance metrics



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tasker/registry/statistics_collector.rb', line 43

def collect_registry_stats(registry)
  base_stats = registry.stats
  health_check = registry.health_check

  {
    **base_stats,
    health: health_check,
    performance: measure_registry_performance(registry),
    usage_patterns: analyze_usage_patterns(registry),
    recommendations: generate_recommendations(registry)
  }
end

.find_registries(criteria = {}) ⇒ Array<BaseRegistry>

Find registries matching criteria

Parameters:

  • criteria (Hash) (defaults to: {})

    Search criteria

Options Hash (criteria):

  • :name_pattern (String)

    Registry name pattern

  • :health_status (Symbol)

    Health status filter (:healthy, :unhealthy)

  • :min_items (Integer)

    Minimum item count

Returns:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/tasker/registry/statistics_collector.rb', line 87

def find_registries(criteria = {})
  registries = discover_all_registries

  if criteria[:name_pattern]
    pattern = Regexp.new(criteria[:name_pattern], Regexp::IGNORECASE)
    registries = registries.select { |registry| registry.class.name.match?(pattern) }
  end

  if criteria[:health_status]
    case criteria[:health_status]
    when :healthy
      registries = registries.select(&:healthy?)
    when :unhealthy
      registries = registries.reject(&:healthy?)
    end
  end

  if criteria[:min_items]
    registries = registries.select do |registry|
      registry.stats[:total_handlers] ||
        registry.stats[:total_plugins] ||
        registry.stats[:total_subscribers] || criteria[:min_items] <= 0
    end
  end

  registries
end

.health_summaryHash

Get health status for all registries

Returns:

  • (Hash)

    Health status summary



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/tasker/registry/statistics_collector.rb', line 59

def health_summary
  registries = discover_all_registries

  health_results = registries.map do |registry|
    {
      registry_name: registry.class.name.demodulize.underscore,
      healthy: registry.healthy?,
      health_details: registry.health_check
    }
  end

  {
    overall_healthy: health_results.all? { |result| result[:healthy] },
    registry_count: registries.size,
    healthy_registries: health_results.count { |result| result[:healthy] },
    unhealthy_registries: health_results.reject { |result| result[:healthy] },
    registries: health_results,
    checked_at: Time.current
  }
end

.performance_reportHash

Generate performance report

Returns:

  • (Hash)

    Performance analysis across all registries



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/tasker/registry/statistics_collector.rb', line 118

def performance_report
  registries = discover_all_registries

  performance_data = registries.map do |registry|
    {
      registry_name: registry.class.name.demodulize.underscore,
      performance: measure_registry_performance(registry),
      item_count: calculate_registry_item_count(registry)
    }
  end

  {
    report_timestamp: Time.current,
    total_registries: registries.size,
    performance_data: performance_data,
    performance_summary: calculate_performance_summary(performance_data)
  }
end