Skip to content

Instantly share code, notes, and snippets.

@trlinkin
Last active July 30, 2020 19:00
Show Gist options
  • Save trlinkin/4bdc2a30e24e5315b7e7d88a760cb438 to your computer and use it in GitHub Desktop.
Save trlinkin/4bdc2a30e24e5315b7e7d88a760cb438 to your computer and use it in GitHub Desktop.
require 'json'
require 'time'
times_file = ARGV[0]
if File.file?(times_file)
times = JSON.parse(File.read(times_file))
else
puts "The argument provided was is either incorrect or not a file."
exit 1
end
starts = []
node_count = 0
times.map! do |time|
node_count += 1
start_time = Time.iso8601(time['start_time']).to_i
end_time = Time.iso8601(time['end_time']).to_i
starts << start_time.to_i
(end_time.to_i - start_time.to_i)
end
puts "#{node_count} nodes in this job analysis"
puts "Average Agent Run time:"
avg_times = times.inject{ |sum, el| sum + el }.to_f / times.size
puts "#{avg_times.truncate(4)} seconds"
puts "or"
puts "#{(avg_times / 60).truncate(4)} minutes"
puts "######################"
puts "Maximum Run Time:"
puts times.max
puts 'or'
puts "#{(times.max.to_f / 60).truncate(4)} minutes"
puts "######################"
puts "Earliest Start Time: " + Time.at(starts.min).iso8601
puts "Latest Start Time: " + Time.at(starts.max).iso8601
time_diff = (starts.max - starts.min)
puts "Difference of: "
puts "#{time_diff.truncate(4)} seconds"
puts "or"
puts "#{(time_diff.to_f / 60).truncate(4)} minutes"

Some Example Output

447 nodes in this job analysis
Average Agent Run time:
206.4653 seconds
or
3.441 minutes
######################
Maximum Run Time:
1111
or
18.5166 minutes
######################
Earliest Start Time: 2020-07-28T03:07:23-04:00
Latest Start Time: 2020-07-28T03:13:46-04:00
Difference of:
383 seconds
or
6.3833 minutes

puppet query 'reports[start_time, end_time] {noop = false and job_id = "###"}'

Where "###" above is replaced with a job UUID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment