puppet-profiler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tim Sharpe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Puppet-profiler
2
+
3
+ Find out what's making your Puppet runs so bloody slow!
4
+
5
+ ## Installation
6
+
7
+ gem install puppet-profiler
8
+
9
+ ## Generating a report
10
+
11
+ Just run the puppet-profiler command and wait
12
+
13
+ puppet-profiler
14
+
15
+ It'll eventually return a report of the slowest resources in your manifest for
16
+ this host. This gives you a good idea of where to start optimising.
17
+
18
+ Top 5 Puppet resources by runtime
19
+ =================================
20
+
21
+ 0.78s - Edit_grub_for_serial[serialconsole]
22
+ 0.55s - File[/usr/share/logstash/outputs]
23
+ 0.35s - File[/etc/nginx/common]
24
+ 0.35s - Service[haproxy]
25
+ 0.34s - Exec[accept_sun_dlj]
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'optparse'
6
+ require 'puppet-profiler'
7
+
8
+ help = <<HELP
9
+ Puppet-profiler
10
+
11
+ Analyses your Puppet run on this host and returns a list of resources that are
12
+ taking the longest time to apply.
13
+
14
+ Basic Command Line Usage:
15
+ puppet-profiler [OPTIONS]
16
+
17
+ Options:
18
+ HELP
19
+
20
+ options = {:number => 10}
21
+ opts = OptionParser.new do |opts|
22
+ opts.banner = help
23
+
24
+ opts.on('-n' '--number NUMBER', 'Number of results to return') do |v|
25
+ options[:number] = v.to_i
26
+ end
27
+ end
28
+
29
+ begin
30
+ opts.parse!
31
+ rescue OptionParser::InvalidOption
32
+ puts "puppet-profiler: #{$!.message}"
33
+ puts "puppet-profiler: try 'puppet-profiler --help' for more information"
34
+ exit 1
35
+ end
36
+
37
+ PuppetProfiler.run(options[:number])
@@ -0,0 +1,28 @@
1
+ class PuppetProfiler
2
+ def self.run(num_res)
3
+ output = `puppet agent --test --evaltrace --color=false`.split("\n")
4
+
5
+ times = []
6
+ resources = output.select { |line|
7
+ line =~ /.+: Evaluated in [\d\.]+ seconds$/
8
+ }.each { |line|
9
+ res_line, junk, eval_line = line.rpartition(':')
10
+ if eval_line =~ / Evaluated in ([\d\.]+) seconds$/
11
+ time = $1.to_f
12
+ end
13
+ junk, junk, res_line = res_line.partition(':')
14
+ if res_line =~ /.*([A-Z][^\[]+)\[(.+?)\]$/
15
+ type = $1
16
+ title = $2
17
+ end
18
+ times << [type, title, time]
19
+ }
20
+
21
+ puts "Top #{num_res} Puppet resources by runtime"
22
+ puts "=================================="
23
+ puts ""
24
+ times.sort { |a, b| a[2] <=> b[2] }.reverse[0..num_res].each { |item|
25
+ puts "#{format('%4s', item[2])}s - #{item[0]}[#{item[1]}]"
26
+ }
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'puppet-profiler'
3
+ s.version = '0.0.1'
4
+ s.homepage = 'https://github.com/rodjek/puppet-profiler/'
5
+ s.summary = 'Find the slow resources in your Puppet manifests'
6
+ s.description = 'Analyses your Puppet runs on a host and returns a list of
7
+ resources that are slowing down your Puppet runs.'
8
+
9
+ s.executables = ['puppet-profiler']
10
+ s.files = [
11
+ 'bin/puppet-profiler',
12
+ 'LICENSE',
13
+ 'lib/puppet-profiler.rb',
14
+ 'puppet-profiler.gemspec',
15
+ 'README.md',
16
+ ]
17
+
18
+ s.authors = ['Tim Sharpe']
19
+ s.email = 'tim@sharpe.id.au'
20
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-profiler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Tim Sharpe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-29 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: |-
22
+ Analyses your Puppet runs on a host and returns a list of
23
+ resources that are slowing down your Puppet runs.
24
+ email: tim@sharpe.id.au
25
+ executables:
26
+ - puppet-profiler
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - bin/puppet-profiler
33
+ - LICENSE
34
+ - lib/puppet-profiler.rb
35
+ - puppet-profiler.gemspec
36
+ - README.md
37
+ homepage: https://github.com/rodjek/puppet-profiler/
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.6
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Find the slow resources in your Puppet manifests
70
+ test_files: []
71
+