escoffier 0.1.1 → 0.1.2
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/VERSION +1 -1
- data/bin/loads +68 -31
- data/config/load_config.yaml +6 -0
- data/escoffier.gemspec +2 -1
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/bin/loads
CHANGED
@@ -1,26 +1,51 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# loads uses Simple Network Management Protocol (SNMP) configured for the
|
4
|
+
# WADRC site to display load information of computer utilization to allow
|
5
|
+
# people to know where to process.
|
6
|
+
#
|
7
|
+
# Originally based off of a script written by John Ollinger @ Waisman,
|
8
|
+
# this uses SNMP instead of ssh and displays color based on percent
|
9
|
+
# utilization.
|
10
|
+
#
|
11
|
+
# EKK / WADRC Neuroimaging Core / Sept. 20, 2010
|
2
12
|
|
3
13
|
require 'rubygems'
|
4
|
-
require 'pp'
|
5
14
|
require 'snmp'
|
6
15
|
require 'term/ansicolor'
|
16
|
+
LOAD_PATHS = %w{. ~/.loads /etc /Data/vtrak1/data1/lab_scripts }
|
7
17
|
|
8
|
-
|
18
|
+
# Load in the list of hosts to monitor.
|
19
|
+
# Look for a file called "load_config.yaml" first in the current directory, then
|
20
|
+
def host_list
|
9
21
|
if ARGV.size >= 1
|
10
22
|
hosts = ARGV
|
11
|
-
else
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
else
|
24
|
+
LOAD_PATHS.each do |path|
|
25
|
+
hosts = read_config File.join(path, "load_config.yaml")
|
26
|
+
if hosts
|
27
|
+
# puts "Using hosts listed in load_config.yaml from #{path}"
|
28
|
+
return hosts
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# If no host config was found, just use localhost.
|
33
|
+
if hosts.nil?
|
34
|
+
puts "Warning: Unable to find host information."
|
35
|
+
hosts = {:localhost => 0}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Read YAML file if it exists.
|
41
|
+
def read_config(file)
|
42
|
+
if File.readable? file
|
43
|
+
require 'yaml'
|
44
|
+
YAML::load_file file
|
21
45
|
end
|
22
46
|
end
|
23
47
|
|
48
|
+
# Gather CPU Utilization Data from a list of Hosts using SNMP
|
24
49
|
def gather_data_on(hosts)
|
25
50
|
load_data = {}
|
26
51
|
|
@@ -40,13 +65,12 @@ def gather_data_on(hosts)
|
|
40
65
|
# just list the required OID's directly.
|
41
66
|
SNMP::Manager.open(:Host => hostname, :Community => 'brainmap', :MibModules => mibs, :retries => 1, :timeout => 1) do |manager|
|
42
67
|
name = manager.get("sysName.0").varbind_list.first.value.split(".").first.to_s
|
68
|
+
oids = ["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"]
|
69
|
+
load_data[name] = { :loads => manager.get(oids).each_varbind.collect {|vb| vb.value.to_s }, :cpu_count => cpus }
|
43
70
|
# 1-min: UCD-SNMP-MIB::laLoad.1 => "1.3.6.1.4.1.2021.10.1.3.1"
|
44
71
|
# 5-min: UCD-SNMP-MIB::laLoad.2 => "1.3.6.1.4.1.2021.10.1.3.2"
|
45
72
|
# 15-min: UCD-SNMP-MIB::laLoad.3 => "1.3.6.1.4.1.2021.10.1.3.3"
|
46
|
-
#
|
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
|
73
|
+
# oids = ["UCD-SNMP-MIB::laLoad.1", "UCD-SNMP-MIB::laLoad.2", "UCD-SNMP-MIB::laLoad.3"]
|
50
74
|
end
|
51
75
|
rescue SNMP::RequestTimeout => e
|
52
76
|
puts "Warning: #{e}"
|
@@ -55,34 +79,47 @@ def gather_data_on(hosts)
|
|
55
79
|
end
|
56
80
|
end
|
57
81
|
|
58
|
-
|
82
|
+
unless load_data.empty?
|
83
|
+
build_display(load_data)
|
84
|
+
else
|
85
|
+
puts Term::ANSIColor.bold {"\nError: No CPU load data available."}
|
86
|
+
puts "Please check that SNMP is running on all machines and that they are "
|
87
|
+
"configured correctly in load_config.yaml\n\n"
|
88
|
+
end
|
59
89
|
end
|
60
90
|
|
61
|
-
|
62
|
-
|
63
|
-
display
|
64
|
-
display << Term::ANSIColor.bold
|
65
|
-
display <<
|
91
|
+
# Header Information for the CPU Table
|
92
|
+
def header
|
93
|
+
display = "\nLoad Averages over three intervals:\n\n"
|
94
|
+
display << Term::ANSIColor.bold
|
95
|
+
display << "\t%-15s\t%-4s\t" % ["Server (CPUs)", "% Util"]
|
96
|
+
display << "%s\t%s\t%s\n" % ["1-minute", "5-minutes", "15-minutes"]
|
66
97
|
display << "\t%-15s\t%-4s\t%s\t%s\t%s\n" % ["-"*13, "-"*6, "-" * 8, "-" * 8, "-" * 8]
|
67
|
-
|
68
|
-
|
69
|
-
|
98
|
+
display << Term::ANSIColor.clear
|
99
|
+
end
|
100
|
+
|
101
|
+
# Build Output for the CPU Table
|
102
|
+
def build_display(load_data)
|
103
|
+
display = header
|
104
|
+
load_data.sort_by{|data| data.last[:loads][1].to_f / data.last[:cpu_count]}.reverse.each do |hostname, averages|
|
105
|
+
utilization = (averages[:loads][1].to_f / averages[:cpu_count]) * 100
|
106
|
+
low = 50; high = 80
|
70
107
|
case utilization
|
71
|
-
when 0
|
108
|
+
when 0...low
|
72
109
|
color = "green"
|
73
|
-
when
|
110
|
+
when low..high
|
74
111
|
color = "yellow"
|
75
112
|
else
|
76
113
|
color = "red"
|
77
114
|
end
|
78
115
|
display << eval("Term::ANSIColor.#{color}")
|
79
|
-
display << "\t%-15s\t" % "#{
|
116
|
+
display << "\t%-15s\t" % "#{hostname} (#{averages[:cpu_count]})"
|
80
117
|
display << "%-2.2f\t" % utilization
|
81
|
-
|
118
|
+
averages[:loads].collect {|la| display << "%s\t\t" % la }
|
82
119
|
display << "\n"
|
83
120
|
end
|
84
121
|
display << Term::ANSIColor.clear
|
85
122
|
end
|
86
123
|
|
87
|
-
|
88
|
-
puts gather_data_on
|
124
|
+
# Run Main Program
|
125
|
+
puts gather_data_on host_list
|
data/escoffier.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{escoffier}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
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"]
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
"bin/loads",
|
26
26
|
"bin/mise",
|
27
27
|
"bin/normalize_directory.rb",
|
28
|
+
"config/load_config.yaml",
|
28
29
|
"escoffier.gemspec",
|
29
30
|
"lib/escoffier.rb",
|
30
31
|
"lib/escoffier/compressible.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Erik Kastman
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- bin/loads
|
86
86
|
- bin/mise
|
87
87
|
- bin/normalize_directory.rb
|
88
|
+
- config/load_config.yaml
|
88
89
|
- escoffier.gemspec
|
89
90
|
- lib/escoffier.rb
|
90
91
|
- lib/escoffier/compressible.rb
|