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
|
# File 'lib/ruby_script_exporter/executor.rb', line 22
def run
total_count = 0
successful_count = 0
cached_count = 0
error_count = 0
timeout_count = 0
measurements = []
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
probes.each do |probe|
total_count += 1
begin
probe_measurements, execution_time = probe.run
rescue Probe::ScriptError => e
STDERR.puts "Error while executing #{probe.inspect}: #{e.inspect}"
error_count += 1
next
rescue Probe::ScriptTimeout
STDERR.puts "Timeout while executing #{probe.inspect}"
timeout_count += 1
next
end
measurements.concat(probe_measurements)
successful_count += 1
if execution_time == :cached
execution_time = 0
cached_count += 1
end
if @report_execution_time
measurements << Measurement.new(:probe_execution_time, execution_time,
probe: probe,
)
end
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
total_execution_time = end_time - start_time
if @report_execution_time
measurements << Measurement.new(:total_execution_time, total_execution_time)
end
if @report_counts
measurements << Measurement.new(:total_probe_count, total_count)
measurements << Measurement.new(:successful_probe_count, successful_count)
measurements << Measurement.new(:cached_probe_count, cached_count)
measurements << Measurement.new(:error_probe_count, error_count)
measurements << Measurement.new(:timeout_probe_count, timeout_count)
end
measurements
end
|