Class: Top

Inherits:
Object
  • Object
show all
Defined in:
lib/ls4/command/top.rb

Instance Method Summary collapse

Constructor Details

#initialize(cs_addr) ⇒ Top

Returns a new instance of Top.



180
181
182
183
184
185
186
# File 'lib/ls4/command/top.rb', line 180

def initialize(cs_addr)
	@cs_addr = cs_addr
	@nodes = {}  # { nid => TargetNode }
	@nodes_sorted = []  # [TargetNode]
	update_nodes
	@simple = false
end

Instance Method Details

#refreshObject



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/ls4/command/top.rb', line 213

def refresh
	Curses.clear
	if @simple
		if Curses.stdscr.maxx >= 82
			format = FORMAT_LARGE_SIMPLE
		else
			format = FORMAT_SMALL_SIMPLE
		end
	else
		if Curses.stdscr.maxx >= 147
			format = FORMAT_LARGE
		else
			format = FORMAT_SMALL
		end
	end

	Curses.setpos(0, 0)
	title_line = format % TITLES
	nlines = title_line.count("\n")+1
	Curses.addstr(title_line)

	@nodes_sorted.each {|node|
		node.refresh_async
	}
	@nodes_sorted.each_with_index {|node, i|
		Curses.setpos((1+i)*nlines, 0)
		params = node.refresh_async_get
		line = format % params
		Curses.addstr(line)
	}

	Curses.refresh
end

#runObject



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/ls4/command/top.rb', line 247

def run
	i = 0
	while true
		before = Time.now

		refresh

		i += 1
		if i > 5
			i = 0
			update_nodes
		end

		elapse = Time.now - before
		if elapse < 0.5
			sleep 0.5 - elapse
		end
	end
rescue
	$stderr.puts $!.inspect
end

#toggle_simpleObject



188
189
190
191
192
193
194
# File 'lib/ls4/command/top.rb', line 188

def toggle_simple
	if @simple
		@simple = false
	else
		@simple = true
	end
end

#update_nodesObject



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ls4/command/top.rb', line 196

def update_nodes
	s = $net.get_session(*@cs_addr)
	s.timeout = 20

	fault_nids = s.call(:stat, 'fault')
	s.call(:stat, 'nodes').each {|nid,address,name,rsids,location|
		address = MessagePack::RPC::Address.load(address)
		fault = fault_nids.include?(nid)
		if node = @nodes[nid]
			node.update_info(address, name, rsids, location, fault)
		else
			@nodes[nid] = TargetNode.new(nid, address, name, rsids, location, fault)
		end
	}
	@nodes_sorted = @nodes.values.sort_by {|node| node.nid }
end