gri 10.0.1 → 10.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.drone.yml +7 -0
- data/Gemfile +2 -0
- data/gri.gemspec +1 -3
- data/lib/gri/builtindefs.rb +27 -2
- data/lib/gri/collector.rb +61 -11
- data/lib/gri/fake_snmp.rb +96 -0
- data/lib/gri/graph.rb +1 -1
- data/lib/gri/grapher.rb +2 -2
- data/lib/gri/ldb.rb +1 -0
- data/lib/gri/list.rb +1 -1
- data/lib/gri/log.rb +1 -1
- data/lib/gri/main.rb +10 -5
- data/lib/gri/msnmp.rb +3 -0
- data/lib/gri/plugin.rb +5 -5
- data/lib/gri/plugin/bootstrap.rb +4 -4
- data/lib/gri/plugin/ucdavis.rb +8 -0
- data/lib/gri/polling_unit.rb +46 -11
- data/lib/gri/scheduler.rb +1 -0
- data/lib/gri/spark.rb +0 -1
- data/lib/gri/updater.rb +0 -1
- data/lib/gri/vendor.rb +1 -1
- data/lib/gri/version.rb +1 -1
- data/test/fake_snmp.txt +52 -0
- data/test/test_builtindefs.rb +10 -1
- data/test/test_collector.rb +15 -1
- data/test/test_polling_unit.rb +19 -0
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6ecf4515540adbc206c6edd80231b70ae252abf
|
4
|
+
data.tar.gz: e7137b4e6f903dc85815c59fe8af4cca4f23bdd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94603ec74475e84a731143d4331db05cfebbbcdad39c845ef24f0ffc0449645f5ab0a70eec151d529918815d11c12d6d199908b2040d56f9bc0efccd1a6998cd
|
7
|
+
data.tar.gz: c1458666f2d7d3735048471232f26649287cf62dd3c538328e89b78ca0c02cd611503e5bc3c5e984261589391567d8e9350add60818a8d0e488b36f32588cb72
|
data/.drone.yml
ADDED
data/Gemfile
ADDED
data/gri.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
require "gri/version"
|
4
3
|
|
@@ -15,7 +14,6 @@ Gem::Specification.new do |s|
|
|
15
14
|
) }
|
16
15
|
s.require_paths = ["lib"]
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
s.add_development_dependency "msgpack"
|
20
18
|
s.add_runtime_dependency "rack"
|
21
19
|
end
|
data/lib/gri/builtindefs.rb
CHANGED
@@ -24,6 +24,8 @@ module GRI
|
|
24
24
|
'ifInUcastPkts', 'ifOutUcastPkts',
|
25
25
|
'ifInNUcastPkts', 'ifOutNUcastPkts',],
|
26
26
|
:index_key => 'ifDescr',
|
27
|
+
:ignore? => proc {|record|
|
28
|
+
/(^(Loopback|Null|Async)\d+)|cef layer|atm subif/ === record['ifDescr']},
|
27
29
|
:exclude? => proc {|record|
|
28
30
|
record['ifOperStatus'].to_i != 1 or
|
29
31
|
record['ifSpeed'].to_i == 0 or
|
@@ -154,6 +156,8 @@ module GRI
|
|
154
156
|
|
155
157
|
'hrStorage'=>{
|
156
158
|
:oid=>['hrStorageEntry'],
|
159
|
+
:exclude? => proc {|record| record['hrStorageDescr'] =~ /devicemapper/},
|
160
|
+
:hidden? => proc {|record| record['hrStorageDescr'] =~ /devicemapper/},
|
157
161
|
:tdb=>['hrStorage', 'hrStorageDescr', 'hrStorageSize', 'hrStorageUsed'],
|
158
162
|
:fix_workhash=>lambda {|wh|
|
159
163
|
if (h = wh[:hrStorage])
|
@@ -175,6 +179,22 @@ module GRI
|
|
175
179
|
:composite=>['s', 'v', 't'],
|
176
180
|
},
|
177
181
|
|
182
|
+
'hrSWRunPerf'=>{
|
183
|
+
:puclass=>'HRSWRunPerf',
|
184
|
+
:oid=>['hrSWRunPath', 'hrSWRunParameters',
|
185
|
+
'hrSWRunPerfCPU', 'hrSWRunPerfMem'],
|
186
|
+
:tdb=>['hrSWRunPerf', 'name', 'hrSWRunPerfCPU', 'hrSWRunPerfMem'],
|
187
|
+
:ds=>['hrSWRunPerfMem,mem,GAUGE,MAX,AREA,#40ff40',
|
188
|
+
'hrSWRunPerfCPU,cputime,DERIVE,MAX,LINE1,#4444ff,,300',],
|
189
|
+
:prop=>{:name=>'hrSWRunPerfMatched',
|
190
|
+
:lastvalue=>'hrSWRunPerfMem', :cputime=>'hrSWRunPerfCPU'},
|
191
|
+
:list=>['RunPerf', '%N,%1024L\r'],
|
192
|
+
:composite=>['s', 'v', 't'],
|
193
|
+
:graph=>[['mem', 1024, nil, /mem/],
|
194
|
+
['centisecond', 0, [0, nil], /cputime/]
|
195
|
+
],
|
196
|
+
},
|
197
|
+
|
178
198
|
:term => {
|
179
199
|
:default=>[['Daily', 30*3600], ['Weekly', 8*24*3600],
|
180
200
|
['Monthly', 31*24*3600], ['Yearly', 365*24*3600]],
|
@@ -194,12 +214,17 @@ module GRI
|
|
194
214
|
@specs = {}
|
195
215
|
for k, dhash in self
|
196
216
|
next unless String === k
|
197
|
-
data_name = dhash[:data_name] || dhash[:cat] ||
|
217
|
+
data_name = dhash[:data_name] || dhash[:cat] || dhash[:pucat] ||
|
198
218
|
(dhash[:tdb] and dhash[:tdb].first) ||
|
199
219
|
k.gsub(/-/, '')
|
200
220
|
spec = (@specs[data_name.to_s] ||= {})
|
221
|
+
if dhash[:tdb]
|
222
|
+
dhash[:tdb] = dhash[:tdb].map {|item|
|
223
|
+
(item =~ /\s+\*\s+/) ? Regexp.last_match.pre_match : item
|
224
|
+
}
|
225
|
+
end
|
201
226
|
[:list, :index_key, :named_index, :tdb, :ds, :rra, :prop,
|
202
|
-
:graph, :composite, :exclude?, :hidden?].each {|symkey|
|
227
|
+
:graph, :composite, :ignore?, :exclude?, :hidden?].each {|symkey|
|
203
228
|
spec[symkey] = dhash[symkey] if dhash[symkey]
|
204
229
|
}
|
205
230
|
spec[:list] ||= dhash[:list_text] #XXX
|
data/lib/gri/collector.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#require 'gri/utils'
|
2
2
|
require 'gri/msnmp'
|
3
|
+
require 'gri/builtindefs'
|
3
4
|
require 'gri/vendor'
|
4
5
|
require 'gri/polling_unit'
|
5
6
|
|
@@ -77,8 +78,13 @@ module GRI
|
|
77
78
|
@tout = 5
|
78
79
|
@preq = nil
|
79
80
|
@snmp = SNMP.new(@cname || @host, options['port'])
|
80
|
-
|
81
|
-
|
81
|
+
if options['fake-snmp']
|
82
|
+
require 'gri/fake_snmp'
|
83
|
+
@snmp = FakeSNMP.new options['fake-snmp']
|
84
|
+
else
|
85
|
+
@snmp.version = options['ver'] if options['ver']
|
86
|
+
@snmp.community = options['community'] if options['community']
|
87
|
+
end
|
82
88
|
|
83
89
|
varbind = SYSOIDS
|
84
90
|
get(varbind) {|results|
|
@@ -90,7 +96,11 @@ module GRI
|
|
90
96
|
sysinfo['sysDescr'] and sysinfo['sysDescr'].gsub!("\n", ' ')
|
91
97
|
|
92
98
|
vendor = Vendor.check sysinfo, options
|
93
|
-
|
99
|
+
if $debug
|
100
|
+
puts "snmp: #{host} (#{vendor.name}): #{sysinfo['sysDescr']}"
|
101
|
+
puts vendor.options.inspect
|
102
|
+
end
|
103
|
+
|
94
104
|
@snmp.version = vendor.options['ver'] if vendor.options['ver']
|
95
105
|
punits = vendor.get_punits
|
96
106
|
punits_d = punits.dup
|
@@ -105,7 +115,12 @@ module GRI
|
|
105
115
|
hfdh = @fake_descr_hash[host]
|
106
116
|
|
107
117
|
@workhash[:interfaces] = @workhash[''] #
|
118
|
+
if $debug and ($debug['workhash'] or $debug['workhash0'])
|
119
|
+
puts " workhash0"
|
120
|
+
show_workhash @workhash
|
121
|
+
end
|
108
122
|
for pu in punits_d
|
123
|
+
pu.options = vendor.options
|
109
124
|
join_cat, join_key = pu.defs[:join]
|
110
125
|
if join_cat
|
111
126
|
for cat, wh in @workhash[pu.cat]
|
@@ -115,13 +130,22 @@ module GRI
|
|
115
130
|
end
|
116
131
|
end
|
117
132
|
end
|
133
|
+
puts " fix_workhash #{pu.class} #{pu.name}" if $debug
|
118
134
|
pu.fix_workhash @workhash
|
119
135
|
end
|
120
136
|
@workhash.delete :interfaces #
|
137
|
+
if $debug and ($debug['workhash'] or $debug['workhash1'])
|
138
|
+
puts " workhash1"
|
139
|
+
show_workhash @workhash
|
140
|
+
end
|
121
141
|
|
122
142
|
for cat, wh in @workhash
|
123
|
-
(specs = DEFS.get_specs cat)
|
143
|
+
if (specs = DEFS.get_specs cat)
|
124
144
|
(index_key = specs[:index_key] || specs[:named_index])
|
145
|
+
else
|
146
|
+
specs = {}
|
147
|
+
end
|
148
|
+
ign_proc = specs[:ignore?]
|
125
149
|
for ind, h in wh
|
126
150
|
h['_host'] = @hostname || host
|
127
151
|
h['_key'] = if index_key
|
@@ -140,7 +164,7 @@ module GRI
|
|
140
164
|
(prop = specs[:prop]) and (descr_k = prop[:description])
|
141
165
|
h[descr_k] = f_descr
|
142
166
|
end
|
143
|
-
|
167
|
+
next if ign_proc and ign_proc.call(h)
|
144
168
|
records.push h
|
145
169
|
end
|
146
170
|
end
|
@@ -164,9 +188,9 @@ module GRI
|
|
164
188
|
cb.call
|
165
189
|
else
|
166
190
|
pu = punits.shift
|
167
|
-
puts " poll #{host} #{pu.name}" if $debug
|
168
191
|
@get_oid_buf = []
|
169
192
|
oids = pu.oids.dup
|
193
|
+
puts " poll #{host} #{pu.name}" if $debug
|
170
194
|
walk1(pu, oids) {poll1 punits, &cb}
|
171
195
|
end
|
172
196
|
end
|
@@ -189,6 +213,7 @@ module GRI
|
|
189
213
|
walk1 pu, oids, &cb
|
190
214
|
else
|
191
215
|
walk(req_enoid) {|results|
|
216
|
+
show_results req_enoid, results if $debug and $debug['walk']
|
192
217
|
results.each {|enoid, tag, val| pu.feed wh, enoid, tag, val}
|
193
218
|
walk1 pu, oids, &cb
|
194
219
|
}
|
@@ -196,6 +221,28 @@ module GRI
|
|
196
221
|
end
|
197
222
|
end
|
198
223
|
|
224
|
+
def show_workhash workhash
|
225
|
+
for cat, wh in workhash
|
226
|
+
puts " cat: #{cat.inspect}"
|
227
|
+
for ind, h in wh
|
228
|
+
puts " index: #{ind}"
|
229
|
+
for k, v in h
|
230
|
+
puts " #{k}: #{v.inspect}"
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def show_results req_enoid, results
|
237
|
+
puts " req #{SNMP.enoid2name req_enoid}"
|
238
|
+
for enoid, tag, val in results
|
239
|
+
a = BER.dec_oid enoid
|
240
|
+
s = a[0..-2].join('.')
|
241
|
+
oid_ind = BER.enc_v_oid s
|
242
|
+
puts " res #{SNMP.enoid2name(enoid)} #{tag} #{val.inspect}"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
199
246
|
def walk enoid, &cb
|
200
247
|
@results.clear
|
201
248
|
@retry_count = 0
|
@@ -224,12 +271,15 @@ module GRI
|
|
224
271
|
|
225
272
|
def send_req arg
|
226
273
|
@preq = [@snmp.state, arg]
|
227
|
-
s = @snmp.make_req
|
228
|
-
|
229
|
-
|
274
|
+
if (s = @snmp.make_req(@snmp.state, arg))
|
275
|
+
if @retry_count > 0
|
276
|
+
Log.debug "retry send_req, #{@buffers.size}"
|
277
|
+
end
|
278
|
+
@buffers.push s
|
279
|
+
loop.watch @snmp.sock, :w, @tout, self
|
280
|
+
else
|
281
|
+
on_readable
|
230
282
|
end
|
231
|
-
@buffers.push s
|
232
|
-
loop.watch @snmp.sock, :w, @tout, self
|
233
283
|
end
|
234
284
|
|
235
285
|
def retry
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module GRI
|
2
|
+
class FakeSock
|
3
|
+
def recv *arg; end
|
4
|
+
end
|
5
|
+
|
6
|
+
class FakeSNMP
|
7
|
+
attr_reader :state
|
8
|
+
attr_accessor :version
|
9
|
+
|
10
|
+
def initialize path
|
11
|
+
lines = File.readlines path
|
12
|
+
@lines = []
|
13
|
+
lines.each {|line|
|
14
|
+
oid, value = line.split ' = '
|
15
|
+
value = vconv value
|
16
|
+
enoid = BER.enc_v_oid oid[1..-1]
|
17
|
+
@lines.push [enoid, value] if value
|
18
|
+
}
|
19
|
+
|
20
|
+
@sock = FakeSock.new
|
21
|
+
|
22
|
+
@roids = SNMP::ROIDS
|
23
|
+
@state = :IDLE
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_value enoid
|
27
|
+
(res = @lines.assoc enoid) ? res[1] : nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def sock; @sock; end
|
31
|
+
|
32
|
+
def recv_msg msg
|
33
|
+
for arg in @get_buf
|
34
|
+
@cb.call *arg
|
35
|
+
end
|
36
|
+
@get_buf.clear
|
37
|
+
@state = :SUCCESS
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_start msg, &cb
|
42
|
+
@cb = cb
|
43
|
+
@state = :GET_REQ
|
44
|
+
@get_buf = []
|
45
|
+
tag, msg, = BER.tlv msg
|
46
|
+
while msg.size > 0
|
47
|
+
tag, val, msg = BER.tlv msg
|
48
|
+
if val.getbyte(0) == 6
|
49
|
+
len = val.getbyte(1)
|
50
|
+
enoid = val[2, len]
|
51
|
+
if (value = get_value(enoid))
|
52
|
+
@get_buf.push [enoid, value[0], value[1]]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def walk_start enoid, &cb
|
59
|
+
@cb = cb
|
60
|
+
@state = :GETBULK_REQ
|
61
|
+
|
62
|
+
@get_buf = []
|
63
|
+
for k, v in @lines
|
64
|
+
if k.index(enoid) == 0
|
65
|
+
@get_buf.push [k, v[0], v[1]]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def make_req state, arg
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
def vconv str
|
75
|
+
case str
|
76
|
+
when /^INTEGER: (?:\w+\()?([-\d]+)/
|
77
|
+
[0x02, $1.to_i]
|
78
|
+
when /^STRING: "(.*)/
|
79
|
+
[0x04, $1[0..-2]]
|
80
|
+
when /^STRING: ([^"].*)/
|
81
|
+
[0x04, $1]
|
82
|
+
when /^OID: \.(1.*)/
|
83
|
+
enoid = BER.enc_v_oid $1
|
84
|
+
[0x06, enoid]
|
85
|
+
when /^Counter(?:32)?: (\d+)/
|
86
|
+
[0x41, $1.to_i]
|
87
|
+
when /^Gauge(?:\d+): ([-\d]+)/
|
88
|
+
[0x42, $1.to_i]
|
89
|
+
when /^Counter64: (\d+)/
|
90
|
+
[0x46, $1.to_i]
|
91
|
+
else
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/gri/graph.rb
CHANGED
@@ -213,7 +213,7 @@ module GRI
|
|
213
213
|
rrdpaths, total_ub = get_rrdpaths_and_ub rnames
|
214
214
|
|
215
215
|
args = []
|
216
|
-
if total_ub > 0
|
216
|
+
if total_ub > 0 and (params['p'] != 'v')
|
217
217
|
args.push "-u #{total_ub} --alt-autoscale-max" if params['y'] == 'u'
|
218
218
|
args.push "HRULE:#{total_ub}#ff0000"
|
219
219
|
end
|
data/lib/gri/grapher.rb
CHANGED
@@ -14,9 +14,9 @@ module GRI
|
|
14
14
|
def initialize
|
15
15
|
root_dir = Config['root-dir'] ||= Config::ROOT_PATH
|
16
16
|
log_dir = Config['log-dir'] || Config['root-dir'] + '/log'
|
17
|
-
Log.init "#{log_dir}/#{File.basename $0}.log"
|
17
|
+
Log.init "#{log_dir}/#{File.basename $0}.log", :no_dash=>true
|
18
18
|
rescue SystemCallError
|
19
|
-
Log.init '/tmp/grapher.log'
|
19
|
+
Log.init '/tmp/grapher.log', :no_dash=>true
|
20
20
|
end
|
21
21
|
|
22
22
|
def call env
|
data/lib/gri/ldb.rb
CHANGED
data/lib/gri/list.rb
CHANGED
data/lib/gri/log.rb
CHANGED
@@ -36,7 +36,7 @@ module Log
|
|
36
36
|
shift_size = options[:log_shift_size] || 100_000_000
|
37
37
|
logger = Logger.new logdev, shift_age, shift_size
|
38
38
|
logger.formatter = Log::Formatter.new
|
39
|
-
logger.add Logger::INFO, '-'
|
39
|
+
logger.add Logger::INFO, '-' unless options[:no_dash]
|
40
40
|
logger = Logger.new logdev
|
41
41
|
logger.formatter = Log::Formatter.new
|
42
42
|
logger.level = {'fatal'=>Logger::FATAL, 'error'=>Logger::ERROR,
|
data/lib/gri/main.rb
CHANGED
@@ -30,9 +30,12 @@ module GRI
|
|
30
30
|
GRI::Plugin.load_plugins plugin_dirs, @config
|
31
31
|
|
32
32
|
log_dir = @config['log-dir'] || root_dir + '/log'
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
begin
|
34
|
+
Dir.mkdir log_dir unless File.exist? log_dir
|
35
|
+
Log.init "#{log_dir}/#{optparser.program_name}.log",
|
36
|
+
:log_level=>@config['log-level']
|
37
|
+
rescue SystemCallError
|
38
|
+
end
|
36
39
|
|
37
40
|
@config['tra-dir'] ||= root_dir + '/tra'
|
38
41
|
@config['gra-dir'] ||= root_dir + '/gra'
|
@@ -78,15 +81,17 @@ module GRI
|
|
78
81
|
|
79
82
|
def optparse opts
|
80
83
|
op = OptionParser.new
|
81
|
-
op.on('--debug') {
|
84
|
+
op.on('--debug [FLAGS]', String) {|arg| STDOUT.sync = true
|
85
|
+
a = (arg || '').split(/,/)
|
86
|
+
$debug = Hash[*(a.zip([true]*a.size).flatten)]
|
82
87
|
opts['log-level'] = 'debug'}
|
83
|
-
op.on('--Doption=STR') {|arg| (opts['Doption'] ||= []).push arg}
|
84
88
|
|
85
89
|
op.on('--add-writer=WRITER') {|arg| (opts['writers'] ||= []).push arg}
|
86
90
|
op.on('-O OPT_STR') {|arg| (opts['O'] ||= []).push arg}
|
87
91
|
op.on('--collector') {opts['collector'] = true}
|
88
92
|
op.on('--config-path=PATH') {|arg| opts[:config_path] = arg}
|
89
93
|
op.on('--duration=SEC', Integer) {|arg| opts['duration'] = arg}
|
94
|
+
op.on('--fake-snmp=FILE') {|arg| opts['fake_snmp'] = arg}
|
90
95
|
op.on('--gritab-path=PATH') {|arg| opts['gritab-path'] = arg}
|
91
96
|
op.on('--host-pat=PAT', '-h') {|arg| (opts['host-pat'] ||= []).push arg}
|
92
97
|
op.on('--interval=SEC', Integer) {|arg| opts['interval'] = arg}
|
data/lib/gri/msnmp.rb
CHANGED
data/lib/gri/plugin.rb
CHANGED
@@ -4,8 +4,7 @@ module GRI
|
|
4
4
|
|
5
5
|
def load_plugins dirs=[], config=nil
|
6
6
|
@loaded = {}
|
7
|
-
dirs
|
8
|
-
dirs.push File.join(File.dirname(__FILE__), 'plugin')
|
7
|
+
dirs = [File.join(File.dirname(__FILE__), 'plugin')] + get_gem_dirs + dirs
|
9
8
|
dirs.each {|dir| load_plugin_dir dir, config}
|
10
9
|
end
|
11
10
|
|
@@ -49,13 +48,14 @@ module GRI
|
|
49
48
|
if defined?(::Gem::Specification) and
|
50
49
|
Gem::Specification.respond_to?(:find_all)
|
51
50
|
specs = Gem::Specification.find_all {|spec|
|
52
|
-
spec.
|
53
|
-
File.directory?(path
|
51
|
+
spec.require_paths.map {|path|
|
52
|
+
File.directory?("#{spec.gem_dir}/#{path}/gri/plugin")}.any?
|
54
53
|
}.sort_by {|spec| spec.version}.reverse
|
55
54
|
names = {}
|
56
55
|
specs.each {|spec| names[spec.name] ||= spec}
|
57
56
|
names.values.each {|spec|
|
58
|
-
dirs += spec.
|
57
|
+
dirs += spec.require_paths.map {|path|
|
58
|
+
"#{spec.gem_dir}/#{path}/gri/plugin"}
|
59
59
|
}
|
60
60
|
elsif Gem.respond_to?(:searcher)
|
61
61
|
specs = Gem.searcher.find_all 'gri/plugin/*.rb'
|
data/lib/gri/plugin/bootstrap.rb
CHANGED
@@ -16,8 +16,8 @@ background:linear-gradient(to bottom, #ffd8d8 0%,#ffcccc 45%,#ffc0c0 100%);
|
|
16
16
|
text-align:left;}
|
17
17
|
hr {border:none;border-top:1px #cccccc solid;}
|
18
18
|
</style>
|
19
|
-
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.
|
20
|
-
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.
|
19
|
+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css">
|
20
|
+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap-theme.min.css">
|
21
21
|
</head>
|
22
22
|
|
23
23
|
<body>
|
@@ -34,9 +34,9 @@ hr {border:none;border-top:1px #cccccc solid;}
|
|
34
34
|
<%= yield %>
|
35
35
|
</div>
|
36
36
|
|
37
|
-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.
|
37
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
|
38
38
|
</script>
|
39
|
-
<script src="//netdna.bootstrapcdn.com/bootstrap/3.
|
39
|
+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script>
|
40
40
|
</body>
|
41
41
|
</html>
|
42
42
|
EOS
|
data/lib/gri/plugin/ucdavis.rb
CHANGED
@@ -86,6 +86,8 @@ GRI::DEFS.update 'ucd-la'=>{:cat=>:l,
|
|
86
86
|
},
|
87
87
|
'ucd-dsk'=>{:cat=>:disk,
|
88
88
|
:oid=>['dskEntry'],
|
89
|
+
:exclude? => proc {|record| record['dskPath'] =~ /devicemapper/},
|
90
|
+
:hidden? => proc {|record| record['dskPath'] =~ /devicemapper/},
|
89
91
|
:tdb=>['d', 'dskPath', 'dskTotal', 'dskUsed', 'dskDevice'],
|
90
92
|
:fix_workhash=>proc {|wh|
|
91
93
|
for k, r in wh[:disk]
|
@@ -126,6 +128,12 @@ GRI::DEFS.update 'ucd-la'=>{:cat=>:l,
|
|
126
128
|
'ucd-diskio'=>{:cat=>:diskio, :puclass=>'UCDDiskIO',
|
127
129
|
:oid=>['diskIODevice', 'diskIOReads', 'diskIOWrites',
|
128
130
|
'diskIONReadX', 'diskIONWrittenX'],
|
131
|
+
:ignore? => proc {|record|
|
132
|
+
record['diskIODevice'] =~ /^(diskIODevice|loop|ram|dm-)/ or
|
133
|
+
!(record['diskIODevice'])},
|
134
|
+
#:exclude? => proc {|record| record['diskIODevice'] =~ /^(loop|ram|dm-)/},
|
135
|
+
:hidden? => proc {|record|
|
136
|
+
record['diskIODevice'] =~ /^(diskIODevice|loop|ram|dm-)/},
|
129
137
|
:tdb=>['diskIO', 'diskIODevice', 'diskIOReads', 'diskIOWrites',
|
130
138
|
'diskIONReadX', 'diskIONWrittenX'],
|
131
139
|
:ds=>['diskIOReads,reads,DERIVE,MAX,AREA,#90f090',
|
data/lib/gri/polling_unit.rb
CHANGED
@@ -3,7 +3,7 @@ module GRI
|
|
3
3
|
UNITS = {}
|
4
4
|
|
5
5
|
attr_reader :name, :cat, :oids
|
6
|
-
attr_accessor :dhash
|
6
|
+
attr_accessor :dhash, :ophash, :options
|
7
7
|
alias :defs :dhash
|
8
8
|
|
9
9
|
def self.all_units
|
@@ -12,15 +12,25 @@ module GRI
|
|
12
12
|
next unless String === name
|
13
13
|
pucat = dhash[:cat] || dhash[:pucat] ||
|
14
14
|
(dhash[:tdb] and dhash[:tdb].first.intern) || name.intern
|
15
|
-
|
16
|
-
if puclass
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
klass = self
|
16
|
+
if (puclass = dhash[:puclass])
|
17
|
+
if GRI.const_defined?("#{puclass}PollingUnit") or
|
18
|
+
Object.const_defined?("#{puclass}PollingUnit")
|
19
|
+
klass = eval("#{puclass}PollingUnit")
|
20
|
+
end
|
20
21
|
end
|
21
22
|
pu = klass.new name, pucat
|
22
23
|
pu.dhash = dhash
|
23
24
|
pu.set_oids dhash[:oid]
|
25
|
+
if dhash[:tdb]
|
26
|
+
dhash[:tdb].each {|item|
|
27
|
+
if item =~ /\s+\*\s+/
|
28
|
+
pre = Regexp.last_match.pre_match
|
29
|
+
post = Regexp.last_match.post_match
|
30
|
+
(pu.ophash ||= {})[pre] = proc {|val| val * post.to_f}
|
31
|
+
end
|
32
|
+
}
|
33
|
+
end
|
24
34
|
|
25
35
|
self::UNITS[name] = pu
|
26
36
|
end
|
@@ -31,6 +41,8 @@ module GRI
|
|
31
41
|
def initialize name, cat
|
32
42
|
@name = name
|
33
43
|
@cat = cat
|
44
|
+
@options = {}
|
45
|
+
@ophash = nil
|
34
46
|
@d_p = false
|
35
47
|
end
|
36
48
|
|
@@ -43,7 +55,6 @@ module GRI
|
|
43
55
|
|
44
56
|
def feed wh, enoid, tag, val
|
45
57
|
if (feed_proc = dhash[:feed])
|
46
|
-
puts " feed_proc #{[enid, tag, val].inspect}" if @d_p
|
47
58
|
feed_proc.call wh, enoid, tag, val
|
48
59
|
else
|
49
60
|
if enoid.getbyte(-2) < 128
|
@@ -66,11 +77,10 @@ module GRI
|
|
66
77
|
if (sym_oid = SNMP::ROIDS[oid_ind])
|
67
78
|
(conv_val_proc = dhash[:conv_val]) and
|
68
79
|
(val = conv_val_proc.call(sym_oid, val))
|
69
|
-
(
|
70
|
-
|
71
|
-
wh[ind]['_d'] = true
|
72
|
-
puts " feed #{[sym_oid, ind, tag, val].inspect}"
|
80
|
+
if ophash and (pr = ophash[sym_oid])
|
81
|
+
val = pr.call(val)
|
73
82
|
end
|
83
|
+
(wh[ind] ||= {})[sym_oid] = val
|
74
84
|
end
|
75
85
|
end
|
76
86
|
end
|
@@ -85,4 +95,29 @@ module GRI
|
|
85
95
|
"#<PU:#{@name}>"
|
86
96
|
end
|
87
97
|
end
|
98
|
+
|
99
|
+
class HRSWRunPerfPollingUnit < PollingUnit
|
100
|
+
def fix_workhash workhash
|
101
|
+
re = (pat = options['hrSWRunPerf']) ? Regexp.new(pat) : nil
|
102
|
+
wh2 = {}
|
103
|
+
if (wh = workhash[:hrSWRunPerf])
|
104
|
+
del_keys = []
|
105
|
+
for k, v in wh
|
106
|
+
sw = "#{v['hrSWRunPath']} #{v['hrSWRunParameters']}"
|
107
|
+
if re =~ sw
|
108
|
+
matched = $&
|
109
|
+
idx = matched.gsub(/[\s\/]/, '_').gsub(/[^\w]/, '') #/
|
110
|
+
h = (wh2[idx] ||= {})
|
111
|
+
h['hrSWRunPerfMatched'] = matched
|
112
|
+
h['hrSWRunPerfMem'] ||= 0
|
113
|
+
h['hrSWRunPerfMem'] += v['hrSWRunPerfMem'].to_i * 1024
|
114
|
+
h['hrSWRunPerfCPU'] ||= 0
|
115
|
+
h['hrSWRunPerfCPU'] += v['hrSWRunPerfCPU'].to_i
|
116
|
+
end
|
117
|
+
end
|
118
|
+
workhash[:hrSWRunPerf] = wh2
|
119
|
+
end
|
120
|
+
super
|
121
|
+
end
|
122
|
+
end
|
88
123
|
end
|
data/lib/gri/scheduler.rb
CHANGED
data/lib/gri/spark.rb
CHANGED
@@ -80,7 +80,6 @@ module GRI
|
|
80
80
|
op = OptionParser.new
|
81
81
|
op.on('--debug') {$debug = true; STDOUT.sync = true;
|
82
82
|
opts['log-level'] = 'debug'}
|
83
|
-
op.on('--Doption=STR') {|arg| (opts['Doption'] ||= []).push arg}
|
84
83
|
op.on('-O OPT_STR') {|arg| (opts['O'] ||= []).push arg}
|
85
84
|
op.on('-c', '--config-path=PATH') {|arg| opts[:config_path] = arg}
|
86
85
|
op.on('--log-level=LEVEL') {|arg| opts['log-level'] = arg}
|
data/lib/gri/updater.rb
CHANGED
@@ -147,7 +147,6 @@ module GRI
|
|
147
147
|
end
|
148
148
|
data = @record_keys.map {|key| record[key]}
|
149
149
|
s = "#{time.to_i}:#{mk_update_str data}"
|
150
|
-
puts " update #{@key} #{s}" if record['_d']
|
151
150
|
@rrd.buffered_update s
|
152
151
|
|
153
152
|
if (prop = @specs[:prop]) and (descr_k = prop[:description]) and
|
data/lib/gri/vendor.rb
CHANGED
data/lib/gri/version.rb
CHANGED
data/test/fake_snmp.txt
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
.1.3.6.1.2.1.1.1.0 = STRING: Linux HOSTNAME.example.com 2.6.18
|
2
|
+
.1.3.6.1.2.1.1.2.0 = OID: .1.3.6.1.4.1.8072.3.2.10
|
3
|
+
.1.3.6.1.2.1.1.5.0 = STRING: HOSTNAME.example.com
|
4
|
+
.1.3.6.1.2.1.2.1.0 = INTEGER: 3
|
5
|
+
.1.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
|
6
|
+
.1.3.6.1.2.1.2.2.1.1.2 = INTEGER: 2
|
7
|
+
.1.3.6.1.2.1.2.2.1.1.3 = INTEGER: 3
|
8
|
+
.1.3.6.1.2.1.2.2.1.2.1 = STRING: lo
|
9
|
+
.1.3.6.1.2.1.2.2.1.2.2 = STRING: eth0
|
10
|
+
.1.3.6.1.2.1.2.2.1.2.3 = STRING: eth1
|
11
|
+
.1.3.6.1.2.1.2.2.1.4.1 = INTEGER: 16436
|
12
|
+
.1.3.6.1.2.1.2.2.1.4.2 = INTEGER: 1500
|
13
|
+
.1.3.6.1.2.1.2.2.1.4.3 = INTEGER: 1500
|
14
|
+
.1.3.6.1.2.1.2.2.1.5.1 = Gauge32: 10000000
|
15
|
+
.1.3.6.1.2.1.2.2.1.5.2 = Gauge32: 1000000000
|
16
|
+
.1.3.6.1.2.1.2.2.1.5.3 = Gauge32: 10000000
|
17
|
+
.1.3.6.1.2.1.2.2.1.7.1 = INTEGER: up(1)
|
18
|
+
.1.3.6.1.2.1.2.2.1.7.2 = INTEGER: up(1)
|
19
|
+
.1.3.6.1.2.1.2.2.1.7.3 = INTEGER: down(2)
|
20
|
+
.1.3.6.1.2.1.2.2.1.8.1 = INTEGER: up(1)
|
21
|
+
.1.3.6.1.2.1.2.2.1.8.2 = INTEGER: up(1)
|
22
|
+
.1.3.6.1.2.1.2.2.1.8.3 = INTEGER: down(2)
|
23
|
+
.1.3.6.1.2.1.2.2.1.10.1 = Counter32: 415914156
|
24
|
+
.1.3.6.1.2.1.2.2.1.10.2 = Counter32: 493985280
|
25
|
+
.1.3.6.1.2.1.2.2.1.10.3 = Counter32: 0
|
26
|
+
.1.3.6.1.2.1.2.2.1.11.1 = Counter32: 6057806
|
27
|
+
.1.3.6.1.2.1.2.2.1.11.2 = Counter32: 39093162
|
28
|
+
.1.3.6.1.2.1.2.2.1.11.3 = Counter32: 0
|
29
|
+
.1.3.6.1.2.1.2.2.1.12.1 = Counter32: 0
|
30
|
+
.1.3.6.1.2.1.2.2.1.12.2 = Counter32: 97254
|
31
|
+
.1.3.6.1.2.1.2.2.1.12.3 = Counter32: 0
|
32
|
+
.1.3.6.1.2.1.2.2.1.13.1 = Counter32: 0
|
33
|
+
.1.3.6.1.2.1.2.2.1.13.2 = Counter32: 0
|
34
|
+
.1.3.6.1.2.1.2.2.1.13.3 = Counter32: 0
|
35
|
+
.1.3.6.1.2.1.2.2.1.14.1 = Counter32: 0
|
36
|
+
.1.3.6.1.2.1.2.2.1.14.2 = Counter32: 0
|
37
|
+
.1.3.6.1.2.1.2.2.1.14.3 = Counter32: 0
|
38
|
+
.1.3.6.1.2.1.2.2.1.16.1 = Counter32: 315914156
|
39
|
+
.1.3.6.1.2.1.2.2.1.16.2 = Counter32: 2789307653
|
40
|
+
.1.3.6.1.2.1.2.2.1.16.3 = Counter32: 0
|
41
|
+
.1.3.6.1.2.1.2.2.1.17.1 = Counter32: 6057806
|
42
|
+
.1.3.6.1.2.1.2.2.1.17.2 = Counter32: 22196084
|
43
|
+
.1.3.6.1.2.1.2.2.1.17.3 = Counter32: 0
|
44
|
+
.1.3.6.1.2.1.2.2.1.18.1 = Counter32: 0
|
45
|
+
.1.3.6.1.2.1.2.2.1.18.2 = Counter32: 0
|
46
|
+
.1.3.6.1.2.1.2.2.1.18.3 = Counter32: 0
|
47
|
+
.1.3.6.1.2.1.2.2.1.19.1 = Counter32: 0
|
48
|
+
.1.3.6.1.2.1.2.2.1.19.2 = Counter32: 0
|
49
|
+
.1.3.6.1.2.1.2.2.1.19.3 = Counter32: 0
|
50
|
+
.1.3.6.1.2.1.2.2.1.20.1 = Counter32: 0
|
51
|
+
.1.3.6.1.2.1.2.2.1.20.2 = Counter32: 0
|
52
|
+
.1.3.6.1.2.1.2.2.1.20.3 = Counter32: 0
|
data/test/test_builtindefs.rb
CHANGED
@@ -11,7 +11,7 @@ class TestBuiltinDEFS < Test::Unit::TestCase
|
|
11
11
|
def setup
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def test_get_specs
|
15
15
|
specs = DEFS.get_specs 'num'
|
16
16
|
ae '_index', specs[:prop][:name]
|
17
17
|
ae 4, specs[:rra].size
|
@@ -19,6 +19,15 @@ class TestBuiltinDEFS < Test::Unit::TestCase
|
|
19
19
|
ae 'ifInOctets,inoctet,DERIVE,MAX,AREA,#90f090,in,8', specs[:ds].first
|
20
20
|
specs = DEFS.get_specs :l
|
21
21
|
end
|
22
|
+
|
23
|
+
def test_get_specs_foo
|
24
|
+
specs = DEFS.get_specs :foo
|
25
|
+
assert_nil specs
|
26
|
+
DEFS.instance_eval {@specs = nil}
|
27
|
+
DEFS['foo'] = {:tdb=>['foo', 'xx * 10', 'yy', 'zz']}
|
28
|
+
specs = DEFS.get_specs :foo
|
29
|
+
ae ['foo', 'xx', 'yy', 'zz'], specs[:tdb]
|
30
|
+
end
|
22
31
|
end
|
23
32
|
|
24
33
|
end
|
data/test/test_collector.rb
CHANGED
@@ -27,7 +27,7 @@ class TestCollector < Test::Unit::TestCase
|
|
27
27
|
"\x7F\xC9i\xA10\"\x06\b+\x06\x01\x02\x01\x01\x06\x00" +
|
28
28
|
"\x04\x16xxxxx xxxx, xxxxx xxx."
|
29
29
|
|
30
|
-
def
|
30
|
+
def test_snmp_collector
|
31
31
|
c = Collector.create('snmp', 'testhost', {}) {|records|}
|
32
32
|
snmp = MockSNMP.new 'testhost'
|
33
33
|
c.instance_eval {
|
@@ -53,6 +53,20 @@ class TestCollector < Test::Unit::TestCase
|
|
53
53
|
c.walk(enoid) {|enoid, tag, val|}
|
54
54
|
ae :GETNEXT_REQ, snmp.state
|
55
55
|
end
|
56
|
+
|
57
|
+
def test_snmp_collector_fake_snmp
|
58
|
+
opts = {'fake-snmp'=>File.join($test_dir, 'fake_snmp.txt')}
|
59
|
+
records = nil
|
60
|
+
c = Collector.create('snmp', 'testhost', opts) {|rs| records = rs}
|
61
|
+
c.attach MockLoop.new
|
62
|
+
|
63
|
+
sys = records.detect {|r| r['_key'] == 'SYS'}
|
64
|
+
ae 'HOSTNAME.example.com', sys['sysName']
|
65
|
+
|
66
|
+
eth0 = records.detect {|r| r['ifDescr'] == 'eth0'}
|
67
|
+
ae '_eth0', eth0['_key']
|
68
|
+
ae 1000000000, eth0['ifSpeed']
|
69
|
+
end
|
56
70
|
end
|
57
71
|
|
58
72
|
end
|
data/test/test_polling_unit.rb
CHANGED
@@ -54,5 +54,24 @@ module GRI
|
|
54
54
|
pu.fix_workhash workhash
|
55
55
|
ae '192.168.0.1/255.255.255.0', wh[2]['ipaddr']
|
56
56
|
end
|
57
|
+
|
58
|
+
def test_polling_unit_ophash
|
59
|
+
DEFS['foo'] = {:tdb=>['foo', 'fooX * 10', 'fooY', 'fooZ']}
|
60
|
+
PollingUnit::UNITS.clear
|
61
|
+
units = PollingUnit.all_units
|
62
|
+
pu = units['foo']
|
63
|
+
ae 50, pu.ophash['fooX'].call(5).to_i
|
64
|
+
assert_nil pu.ophash['fooY']
|
65
|
+
|
66
|
+
wh = {}
|
67
|
+
SNMP.update 'fooEntry'=>'1.3.6.1.4.1.99999.1',
|
68
|
+
'fooX'=>'1.3.6.1.4.1.99999.1.1'
|
69
|
+
SNMP::ROIDS.clear
|
70
|
+
SNMP.new 'host'
|
71
|
+
enoid = BER.enc_v_oid(SNMP::OIDS['fooX'] + '.1')
|
72
|
+
pu.feed wh, enoid, 2, 3
|
73
|
+
r = wh[1]
|
74
|
+
ae 30, r['fooX'].to_i
|
75
|
+
end
|
57
76
|
end
|
58
77
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.0.
|
4
|
+
version: 10.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maebashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: msgpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rack
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -37,7 +51,9 @@ executables:
|
|
37
51
|
extensions: []
|
38
52
|
extra_rdoc_files: []
|
39
53
|
files:
|
54
|
+
- ".drone.yml"
|
40
55
|
- ".gitignore"
|
56
|
+
- Gemfile
|
41
57
|
- MIT-LICENSE.txt
|
42
58
|
- README.md
|
43
59
|
- Rakefile
|
@@ -61,6 +77,7 @@ files:
|
|
61
77
|
- lib/gri/collector.rb
|
62
78
|
- lib/gri/config.rb
|
63
79
|
- lib/gri/ds_list.rb
|
80
|
+
- lib/gri/fake_snmp.rb
|
64
81
|
- lib/gri/format_helper.rb
|
65
82
|
- lib/gri/gparams.rb
|
66
83
|
- lib/gri/graph.rb
|
@@ -103,6 +120,7 @@ files:
|
|
103
120
|
- lib/gri/writer.rb
|
104
121
|
- mcollector
|
105
122
|
- misc/Dockerfile
|
123
|
+
- test/fake_snmp.txt
|
106
124
|
- test/mock.rb
|
107
125
|
- test/root/gra/.sysdb/sysdb.txt
|
108
126
|
- test/root/gra/testhost/.records.txt
|
@@ -162,11 +180,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
180
|
version: '0'
|
163
181
|
requirements: []
|
164
182
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.2.
|
183
|
+
rubygems_version: 2.2.2
|
166
184
|
signing_key:
|
167
185
|
specification_version: 4
|
168
186
|
summary: GRI
|
169
187
|
test_files:
|
188
|
+
- test/fake_snmp.txt
|
170
189
|
- test/mock.rb
|
171
190
|
- test/root/gra/.sysdb/sysdb.txt
|
172
191
|
- test/root/gra/testhost/.records.txt
|