-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
capsyle sync report utility as sourced from https://github.com/sthiru…
- Loading branch information
Mike McCune
authored
Feb 5, 2021
1 parent
a93c2e8
commit a393566
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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 | ||
|