-
Notifications
You must be signed in to change notification settings - Fork 44
/
capsule_sync_report.rake
46 lines (35 loc) · 2.01 KB
/
capsule_sync_report.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace :katello do
task :generate_content_view_capsule_sync_metrics => ["environment"] do
puts "Task started. This may take a while depending on the amount of tasks."
# By default query last 7 days
number_of_days_to_query = 7.days
# If DAYS is supplied by the user, use it
if not ENV['DAYS'].nil?
number_of_days_to_query = ENV['DAYS'].to_i.days
end
output_file = '/tmp/content_view_sync_metrics.txt'
f = File.new(output_file, 'w')
f.write "ForemanTaskId Start Time End Time Duration(min) Total planning(min) Total execution(min)\n"
# Query only Actions::Katello::CapsuleContent::Sync tasks with state = stopped and started_at > number_of_days_to_query
tasks = ForemanTasks::Task.where(:label => "Actions::Katello::CapsuleContent::Sync").where(:state => 'stopped').where("result !=?", 'error').where("started_at > ?", DateTime.now - number_of_days_to_query).order(:ended_at); 0
tasks.each do |task|
#puts "foreman_task_id is #{task.id}"
execplan = task.execution_plan
plan_values = execplan.steps.values
plansteps = plan_values.select { |plan| plan.class == Dynflow::ExecutionPlan::Steps::PlanStep}
runsteps = plan_values.select { |plan| plan.class == Dynflow::ExecutionPlan::Steps::RunStep}
if plansteps.count != 0
started_at = plansteps.map(&:started_at).min
ended_at = plansteps.map(&:ended_at).max
total_planning_time = ((ended_at - started_at)/60).round(2)
end; 0
if runsteps.count != 0
started_at = runsteps.map(&:started_at).min
ended_at = runsteps.map(&:ended_at).max
total_running_time = ((ended_at - started_at)/60).ceil
end; 0
f.write "#{task.id} #{task.started_at} #{task.ended_at} #{((task.ended_at - task.started_at)/60).ceil} #{total_planning_time} #{total_running_time}\n"
end.count
puts "Task completed. Output stored in /tmp/content_view_sync_metrics.txt"
end
end