Class: RecoveryAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_recovery/recovery_analyzer.rb

Instance Method Summary collapse

Instance Method Details

#get_bytes(prefix) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 59

def get_bytes(prefix)
  string_value = get_value(prefix)
  return nil if string_value.nil?
  string_num,units = string_value.split(/\s+/)
  float_value = string_num.to_f
  bytes = case units
    when 'KB'
      float_value * 1024
    when 'MB'
      float_value * 1024 * 1024
    when 'GB'
      float_value * 1024 * 1024 * 1024
    when 'TB'
      float_value * 1024 * 1024 * 1024 * 1024
    else
      string_num
  end
  bytes.to_i
end

#get_elapsed_sec(prefix) ⇒ Object


97
98
99
100
101
102
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 97

def get_elapsed_sec(prefix)
  string_value = get_value(prefix)
  return nil if string_value.nil?
  t = Time.parse(string_value)
  t.hour*3600 + t.min*60 + t.sec
end

#get_object_id(prefix) ⇒ Object


47
48
49
50
51
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 47

def get_object_id(prefix)
  line = next_line(prefix)
  match = /([a-z]{2}\d{3}[a-z]{2}\d{4})/.match(line)
  match ? match.to_s : nil
end

#get_secs(prefix) ⇒ Object


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 79

def get_secs(prefix)
  string_value = get_value(prefix)
  return nil if string_value.nil?
  string_num,units = string_value.split(/\s+/)
  float_value = string_num.to_f
  secs = case units
    when 'sec'
      float_value
    when 'min'
      float_value * 60
    when 'hour'
      float_value * 60 * 60
    else
      string_num
  end
  secs
end

#get_value(prefix) ⇒ Object


53
54
55
56
57
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 53

def get_value(prefix)
  line = next_line(prefix)
  return nil if line.nil?
  line.sub(prefix,'').strip
end

#next_line(prefix = nil) ⇒ Object


26
27
28
29
30
31
32
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 26

def next_line(prefix=nil)
  line = nil
  begin
    line = @lines[@linenum += 1]
  end until line.nil? or prefix.nil? or line.start_with?(prefix)
  line
end

#next_objectObject


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 34

def next_object
  obj = DigitalObject.new
  obj.object_id = get_object_id('Restoring')
  return nil if obj.object_id.nil?
  obj.files_restored = get_value('Total number of objects restored:')
  obj.files_failed = get_value('Total number of objects failed:')
  obj.bytes = get_bytes('Total number of bytes transferred:')
  obj.transfer_sec = get_secs('Data transfer time:')
  obj.elapsed_sec = get_elapsed_sec('Elapsed processing time:')
  puts obj.inspect
  obj
end

#parse_tsm_restore_log(logfile) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 14

def parse_tsm_restore_log(logfile)
  pathname = Pathname(logfile)
  @lines = pathname.readlines
  @linenum = -1
  event_data = Array.new
  begin
    obj = next_object
    event_data << obj unless obj.nil?
  end until obj.nil?
  event_data
end

#puts_string(string) ⇒ Object


104
105
106
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 104

def puts_string(string)
  puts string
end

#serialize_data(event_data) ⇒ Object


8
9
10
11
# File 'lib/sdr_recovery/recovery_analyzer.rb', line 8

def serialize_data(event_data)
  puts event_data[1].members.join('|')
  puts event_data.map{|row| row.values.join('|')}
end