escoffier 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -10,6 +10,8 @@ begin
10
10
  gemspec.homepage = "http://github.com/kastman/escoffier"
11
11
  gemspec.authors = ["Erik Kastman"]
12
12
  gemspec.add_dependency('bzip2-ruby')
13
+ gemspec.add_dependency('snmp')
14
+ gemspec.add_dependency('term-ansicolor')
13
15
  gemspec.add_development_dependency('rspec')
14
16
  end
15
17
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'pp'
5
+ require 'snmp'
6
+ require 'term/ansicolor'
7
+
8
+ def hosts
9
+ if ARGV.size >= 1
10
+ hosts = ARGV
11
+ else
12
+ # Key-value pairs are hostname and number of CPUs
13
+ hosts = {
14
+ :miho => 4,
15
+ :pebbles => 4,
16
+ :schroeder => 8,
17
+ :nelson => 8,
18
+ :jimbo => 8,
19
+ :kearney => 8,
20
+ :stella => 16}
21
+ end
22
+ end
23
+
24
+ def gather_data_on(hosts)
25
+ load_data = {}
26
+
27
+ hosts.each do |host|
28
+ begin
29
+ if host.kind_of? String
30
+ hostname = host
31
+ cpus = 0
32
+ elsif host.kind_of? Array
33
+ hostname = host.first.to_s
34
+ cpus = host.last
35
+ end
36
+ # mibs = ["SNMPv2-MIB", "UCD-SNMP-MIB"]
37
+ mibs = ["SNMPv2-MIB"]
38
+ # Since the UCD-SNMP MIB is included by default in the SNMP gem, and it
39
+ # does not correctly import, and we don't need dynamic lookup anyway,
40
+ # just list the required OID's directly.
41
+ SNMP::Manager.open(:Host => hostname, :Community => 'brainmap', :MibModules => mibs, :retries => 1, :timeout => 1) do |manager|
42
+ name = manager.get("sysName.0").varbind_list.first.value.split(".").first.to_s
43
+ # 1-min: UCD-SNMP-MIB::laLoad.1 => "1.3.6.1.4.1.2021.10.1.3.1"
44
+ # 5-min: UCD-SNMP-MIB::laLoad.2 => "1.3.6.1.4.1.2021.10.1.3.2"
45
+ # 15-min: UCD-SNMP-MIB::laLoad.3 => "1.3.6.1.4.1.2021.10.1.3.3"
46
+ # load_data[name] = [manager.get(["UCD-SNMP-MIB::laLoad.1", "UCD-SNMP-MIB::laLoad.2", "UCD-SNMP-MIB::laLoad.3"]).each_varbind.collect{|vb| vb.value.to_s }, cpus]
47
+ load_data[name] = [manager.get(["1.3.6.1.4.1.2021.10.1.3.1", "1.3.6.1.4.1.2021.10.1.3.2", "1.3.6.1.4.1.2021.10.1.3.3"]).each_varbind.collect{|vb| vb.value.to_s }, cpus]
48
+ # response = manager.get(["sysName.0", "UCD-SNMP-MIB::laLoad.1", "UCD-SNMP-MIB::laLoad.2", "UCD-SNMP-MIB::laLoad.3"])
49
+ # pp response
50
+ end
51
+ rescue SNMP::RequestTimeout => e
52
+ puts "Warning: #{e}"
53
+ rescue SocketError
54
+ puts "Warning: Host #{hostname} not recognized. #{e}"
55
+ end
56
+ end
57
+
58
+ display_data(load_data)
59
+ end
60
+
61
+ def display_data(load_data)
62
+ display = ""
63
+ display << "\nLoad Averages over three intervals:\n\n"
64
+ display << Term::ANSIColor.bold {"\t%-15s\t%-4s\t" % ["Server (CPUs)", "% Util"] }
65
+ display << Term::ANSIColor.bold {"%s\t%s\t%s\n" % ["1-minute", "5-minutes", "15-minutes"] }
66
+ display << "\t%-15s\t%-4s\t%s\t%s\t%s\n" % ["-"*13, "-"*6, "-" * 8, "-" * 8, "-" * 8]
67
+ load_data.sort_by{|la| la.last.first}.reverse.each do |average_hash|
68
+ cpus = average_hash.last.last
69
+ utilization = (average_hash.last.first[1].to_f / cpus) * 100
70
+ case utilization
71
+ when 0.0...50.0
72
+ color = "green"
73
+ when 50.0..100
74
+ color = "yellow"
75
+ else
76
+ color = "red"
77
+ end
78
+ display << eval("Term::ANSIColor.#{color}")
79
+ display << "\t%-15s\t" % "#{average_hash.first} (#{average_hash.last.last})"
80
+ display << "%-2.2f\t" % utilization
81
+ average_hash.last.first.collect {|la| display << "%s\t\t" % la }
82
+ display << "\n"
83
+ end
84
+ display << Term::ANSIColor.clear
85
+ end
86
+
87
+
88
+ puts gather_data_on hosts
data/bin/mise CHANGED
@@ -11,7 +11,7 @@ require 'escoffier'
11
11
  def parse_options
12
12
  options = Hash.new
13
13
  parser = OptionParser.new do |opts|
14
- opts.banner = "Usage: #{__FILE__} [options] source_paths destination"
14
+ opts.banner = "Usage: #{File.basename(__FILE__)} [options] source_paths destination"
15
15
 
16
16
  # opts.on('-o', '--output OUTPUT_DIRECTORY', "Output Destination Directory") do |dir|
17
17
  # options[:output] = dir
@@ -49,7 +49,7 @@ def normalize!(options)
49
49
  directories = ARGV.to_a
50
50
  directories.each do |directory|
51
51
  unless File.directory?(directory)
52
- puts "Error: Cannot find directory #{dir}."
52
+ puts "Error: Cannot find directory #{directory}."
53
53
  next
54
54
  end
55
55
  normalizer = Normalizer.new(directory, options)
@@ -61,8 +61,8 @@ if File.basename(__FILE__) == File.basename($PROGRAM_NAME)
61
61
  $LOG = Logger.new(STDOUT)
62
62
 
63
63
  options = parse_options
64
- if options[:spec]
65
- directories =
66
- end
64
+ # if options[:spec]
65
+ # directories =
66
+ # end
67
67
  normalize!(options)
68
68
  end
@@ -5,14 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{escoffier}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Erik Kastman"]
12
- s.date = %q{2010-05-11}
12
+ s.date = %q{2010-09-20}
13
13
  s.description = %q{Administrative prep tasks, from mother sauces to hotel pans.}
14
14
  s.email = %q{ekk@medicine.wisc.edu}
15
- s.executables = ["normalize_directory.rb", "mise~", "mise"]
15
+ s.executables = ["normalize_directory.rb", "mise~", "mise", "loads"]
16
16
  s.extra_rdoc_files = [
17
17
  "README.rdoc"
18
18
  ]
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  "README.rdoc",
23
23
  "Rakefile",
24
24
  "VERSION",
25
+ "bin/loads",
25
26
  "bin/mise",
26
27
  "bin/normalize_directory.rb",
27
28
  "escoffier.gemspec",
@@ -55,13 +56,19 @@ Gem::Specification.new do |s|
55
56
 
56
57
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
58
  s.add_runtime_dependency(%q<bzip2-ruby>, [">= 0"])
59
+ s.add_runtime_dependency(%q<snmp>, [">= 0"])
60
+ s.add_runtime_dependency(%q<term-ansicolor>, [">= 0"])
58
61
  s.add_development_dependency(%q<rspec>, [">= 0"])
59
62
  else
60
63
  s.add_dependency(%q<bzip2-ruby>, [">= 0"])
64
+ s.add_dependency(%q<snmp>, [">= 0"])
65
+ s.add_dependency(%q<term-ansicolor>, [">= 0"])
61
66
  s.add_dependency(%q<rspec>, [">= 0"])
62
67
  end
63
68
  else
64
69
  s.add_dependency(%q<bzip2-ruby>, [">= 0"])
70
+ s.add_dependency(%q<snmp>, [">= 0"])
71
+ s.add_dependency(%q<term-ansicolor>, [">= 0"])
65
72
  s.add_dependency(%q<rspec>, [">= 0"])
66
73
  end
67
74
  end
@@ -1,5 +1,13 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__)) unless
2
+ $LOAD_PATH.include?(File.dirname(__FILE__)) || $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ begin
5
+ require 'bzip2_ext'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ gem 'bzip2-ruby'
9
+ require 'bzip2_ext'
10
+ end
3
11
 
4
12
  require 'escoffier/core_additions'
5
13
  require 'escoffier/normalizer'
@@ -3,7 +3,7 @@ require 'escoffier/smepable'
3
3
  class Pathname
4
4
  include Smepable
5
5
 
6
- def prep_mise_to(output_dir)
7
- self.prep_mise(self.to_s, output_dir)
6
+ def prep_mise_to(output_dir, &block)
7
+ self.prep_mise(self.to_s, output_dir, &block)
8
8
  end
9
9
  end
@@ -5,7 +5,9 @@ require 'escoffier/compressible'
5
5
 
6
6
  class Normalizer
7
7
  COMPRESSION_REGEXES = /\.bz2$/
8
+ PFILE_REGEXES = [/^P\d{5}\.7$/]
8
9
  DICOM_REGEXES = [/\d{3,5}.dcm$/, /I?.\d{4}$/ ]
10
+ IMAGE_REGEXES = [PFILE_REGEXES, DICOM_REGEXES].flatten
9
11
 
10
12
  include Compressible
11
13
  attr_reader :entry_path
@@ -53,7 +55,7 @@ class Normalizer
53
55
  end
54
56
 
55
57
  def normalize_compression(file)
56
- DICOM_REGEXES.each do |regex|
58
+ IMAGE_REGEXES.each do |regex|
57
59
  if file =~ regex
58
60
  file = zip(file) unless @dry_run
59
61
  end
@@ -9,7 +9,7 @@ module Smepable
9
9
  $LOG ||= Logger.new(STDOUT)
10
10
  include Compressible
11
11
 
12
- def prep_mise(input_entry, output_directory = Dir.mktmpdir)
12
+ def prep_mise(input_entry, output_directory = Dir.mktmpdir, &block)
13
13
  # destination_dirname = File.dirname(output_directory)
14
14
  FileUtils.mkdir_p(output_directory) unless File.exist?(output_directory)
15
15
  $LOG.info "Copying #{input_entry} to #{output_directory}"
@@ -19,7 +19,17 @@ module Smepable
19
19
  $LOG.info "Unzipping #{output_directory}"
20
20
  unzip(output_directory, :recursive => true)
21
21
 
22
- return output_directory
22
+ if block
23
+ begin
24
+ yield output_directory
25
+ ensure
26
+ File.delete(output_directory)
27
+ end
28
+
29
+ else
30
+ return output_directory
31
+ end
32
+
23
33
  end
24
34
 
25
35
  end
@@ -1,6 +1,6 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
2
 
3
- # require 'rubygems'
3
+ require 'rubygems'
4
4
  require 'spec'
5
5
  require 'fileutils'
6
6
  require 'logger'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Erik Kastman
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-11 00:00:00 -05:00
17
+ date: 2010-09-20 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  type: :runtime
31
31
  version_requirements: *id001
32
32
  - !ruby/object:Gem::Dependency
33
- name: rspec
33
+ name: snmp
34
34
  prerelease: false
35
35
  requirement: &id002 !ruby/object:Gem::Requirement
36
36
  requirements:
@@ -39,14 +39,39 @@ dependencies:
39
39
  segments:
40
40
  - 0
41
41
  version: "0"
42
- type: :development
42
+ type: :runtime
43
43
  version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: term-ansicolor
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :development
67
+ version_requirements: *id004
44
68
  description: Administrative prep tasks, from mother sauces to hotel pans.
45
69
  email: ekk@medicine.wisc.edu
46
70
  executables:
47
71
  - normalize_directory.rb
48
72
  - mise~
49
73
  - mise
74
+ - loads
50
75
  extensions: []
51
76
 
52
77
  extra_rdoc_files:
@@ -57,6 +82,7 @@ files:
57
82
  - README.rdoc
58
83
  - Rakefile
59
84
  - VERSION
85
+ - bin/loads
60
86
  - bin/mise
61
87
  - bin/normalize_directory.rb
62
88
  - escoffier.gemspec