-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaepwatch.rb
executable file
·83 lines (65 loc) · 1.54 KB
/
aepwatch.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/ruby
require_relative 'utility'
class Aepwatch
def initialize
set_install("/opt/intel/ipmwatch")
set_output_dir(File.join(Dir.pwd, Time.now.strftime("aepwatch-%F.%T")))
end
def set_install(install)
@install = install
@start_bin = File.join(@install, "bin64", "ipmwatch")
@stop_bin = File.join(@install, "bin64", "ipmwatch-stop")
end
def set_output_dir(output_dir)
@output_dir = output_dir
end
def output_file(file)
File.join(@output_dir, file)
end
def start()
cmds = [
{
:cmd => @start_bin + " 1",
:out => output_file("aep-watch.csv"),
:err => output_file("aep-watch.err"),
:wait => false,
:pid => nil,
},
]
system("mkdir", "-p", @output_dir)
cmds.each do |cmd| new_proc(cmd) end
end
def stop()
cmd = {
:cmd => @stop_bin,
:out => output_file("aep-watch-stop.out"),
:err => output_file("aep-watch-stop.err"),
:wait => true,
:pid => nil,
}
# meet sometime stop failure, so called 3 times here, just a
# workaround
new_proc(cmd)
sleep(10)
new_proc(cmd)
sleep(10)
new_proc(cmd)
end
end
if __FILE__ == $0
if ARGV.size < 2
puts "Usage:"
puts "Arg 0: install path of aepwatch"
puts "Arg 1: output dir"
puts "Example:"
puts "#{$0} /opt/intel/ipmwatch /tmp/aep-watch"
return -1
end
aepwatch = Aepwatch.new
aepwatch.set_install(ARGV[0])
aepwatch.set_output_dir(ARGV[1])
aepwatch.start
sleep ARGV[2].to_i
aepwatch.stop
return 0
end