Class: Aspera::Ascp::LogAnalyzer::LogFile

Inherits:
Object
  • Object
show all
Includes:
Lines
Defined in:
lib/aspera/ascp/log_analyzer/log_file.rb

Overview

Analysis of one ascp log file: sessions, snapshot periods and statistics

Constant Summary collapse

FINDINGS =

Statistic => finding, when not zero

{
  stuck_nack:           'Retransmission requests (NACKs) were stuck in %d transfers: check the logs.',
  filename_too_long:    '%d files failed because their Windows path is longer than 260 characters.',
  gap:                  'ascp was blocked (IO wait) %d times.',
  gap_ssh:              'ascp was blocked (IO wait) %d times, with an SSH timeout.',
  buffer_died:          'The system ran out of buffer memory, and ascp exited, %d times.',
  timeout_died:         'A data or SSH timeout made ascp exit %d times.',
  decryption_died:      'A file decryption error made ascp exit %d times.',
  table_died:           'ascp exited at the end of %d sessions, without logging the statistics table.',
  died:                 'ascp exited, was blocked (IO wait), or stopped logging, %d times: check the logs.',
  win_clock:            'The clock of the system moves backwards: update the firmware of the motherboard.',
  vm:                   'This system may run on a VM, or have another clock problem, which affected %d transfers.',
  disable_reverse:      'Reverse path congestion inference skew affected %d transfers: check the logs, and disable it if appropriate.',
  vm_peer:              'Peers may run on a VM, or have another clock problem, which affected %d transfers.',
  ossl_modules_missing: 'The OpenSSL modules folder of ascp was not found in %d sessions (configuration, e.g. installation of the HTTP gateway): no effect unless an OpenSSL provider (e.g. FIPS) is needed.',
  change_event_failed:  'A change of the schedule of the virtual link capacity could not be registered in %d sessions: the schedule is not applied.'
}.freeze
PERIOD_TOTALS =

Totals of a snapshot period

%i[rate rate_in rate_out calc calc_in calc_out target target_in target_out loss_in loss_out].freeze
RETRY_KEYS =

A retry has the same values for these

%i[peer op source dest].freeze

Constants included from Lines

Aspera::Ascp::LogAnalyzer::Lines::ASCP_LINE, Aspera::Ascp::LogAnalyzer::Lines::HALF_YEAR, Aspera::Ascp::LogAnalyzer::Lines::MONTHS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Lines

#ascp?

Constructor Details

#initialize(path, period: 60, zero_bytes: false, mtu: nil, thresholds: {}, timezone: nil) ⇒ LogFile

Returns a new instance of LogFile.

Parameters:

  • path (String, StandardInput) —

    Log file, or standard input

  • period (Integer) (defaults to: 60) —

    Snapshot period in seconds

  • zero_bytes (Boolean) (defaults to: false) —

    Include sessions without transferred bytes

  • mtu (Integer, nil) (defaults to: nil) —

    MTU to use when not found in logs

  • thresholds (Hash) (defaults to: {}) —

    Diagnostic thresholds

  • timezone (String, nil) (defaults to: nil) —

    Time zone of the log lines: UTC or +HH:MM. Time zone of the analyst if nil.



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
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 53

def initialize(path, period: 60, zero_bytes: false, mtu: nil, thresholds: {}, timezone: nil)
  @source = path
  # Name in results: `-` for the standard input
  @path = path.to_s
  @timezone = timezone
  @period = period
  @zero_bytes = zero_bytes
  @mtu = mtu
  thresholds = thresholds.transform_keys(&:to_sym)
  unknown = thresholds.keys - DEFAULT_THRESHOLDS.keys
  Aspera.assert(unknown.empty?, type: ArgumentError) { "Unknown threshold: #{unknown.join(', ')}" }
  @thresholds = DEFAULT_THRESHOLDS.merge(thresholds)
  # PID => current Session of process
  @current = {}
  # All sessions, in order of creation
  @sessions = []
  # PID => user and version from configuration lines
  @config = Hash.new { |h, k| h[k] = {} }
  @stats = Hash.new(0)
  @stats[:errors] = Hash.new(0)
  @stats[:error_categories] = Hash.new(0)
  # Start time => {start:, stop:, slots: {Session => Hash}, totals: Hash}
  @periods = {}
  # Start time of the latest period with samples
  @bucket = nil
  # [license number, IP] => {product:, account:, os:}
  @licenses = {}
end

Instance Attribute Details

#first_time ⇒ Object (readonly)

Returns the value of attribute first_time.



45
46
47
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 45

def first_time
  @first_time
end

#last_time ⇒ Object (readonly)

Returns the value of attribute last_time.



45
46
47
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 45

def last_time
  @last_time
end

#licenses ⇒ Object (readonly)

Returns the value of attribute licenses.



45
46
47
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 45

def licenses
  @licenses
end

#path ⇒ Object (readonly)

Returns the value of attribute path.



45
46
47
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 45

def path
  @path
end

#stats ⇒ Object (readonly)

Returns the value of attribute stats.



45
46
47
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 45

def stats
  @stats
end

#thresholds ⇒ Object (readonly)

Returns the value of attribute thresholds.



45
46
47
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 45

def thresholds
  @thresholds
end

Class Method Details

.findings(stats) ⇒ Array<String>

Returns findings from statistics.

Parameters:

  • stats (Hash) —

    statistics of one or several log files

Returns:

  • (Array<String>) —

    findings from statistics



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 106

def findings(stats)
  result = FINDINGS.filter_map do |key, message|
    if stats[key].positive?
      message.include?('%d') ? format(message, stats[key]) : message
    end
  end
  result.insert(1, 'The stuck retransmission requests may have been caused by high packet loss.') if stats[:stuck_nack_loss] > 0.4
  if stats[:smart_reset].positive?
    result.push("ascp reset the base RTT #{stats[:smart_reset]} times.#{' Consider changing the rtt_autocorrect parameters.' if stats[:smart_reset] > 100}")
  end
  result
end

Instance Method Details

#analyze ⇒ self

Read and analyze the log file

Returns:

  • (self)


84
85
86
87
88
89
90
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 84

def analyze
  LogAnalyzer.read_lines(@source, Encoding::BINARY) { |line| parse_line(normalize(line)) }
  @sessions.each(&:evaluate_atm)
  @periods.sort.each { |time, period| end_of_period(time, period) }
  compute_statistics
  self
end

#diagnostics ⇒ Array<Hash>

Returns one row per diagnostic of sessions: id, severity, message, recommendation (if any).

Returns:

  • (Array<Hash>) —

    one row per diagnostic of sessions: id, severity, message, recommendation (if any)



145
146
147
148
149
150
151
152
153
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 145

def diagnostics
  windows_log = @path.match?(/\w:/)
  sessions.flat_map do |s|
    s.report(windows_log: windows_log)
    s.diagnostics.map do |diagnostic|
      {'file' => @path, 'pid' => s.pid, 'session' => s[:uuid]}.compact.merge(diagnostic, 'recommendation' => RECOMMENDATIONS[diagnostic['id'].to_sym]).compact
    end
  end
end

#multi_sessions ⇒ Array<Hash>

Returns one row per multi-session transfer: sessions with the same transfer identifier.

Returns:

  • (Array<Hash>) —

    one row per multi-session transfer: sessions with the same transfer identifier



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 121

def multi_sessions
  parallel = transfer_sessions.select { |s| s.num(:cluster_nodes) > 1 && s[:xfer_id] }
  parallel.group_by { |s| s[:xfer_id] }.map do |xfer_id, group|
    group = group.sort_by { |s| s.num(:cluster_node) }
    start = group.filter_map { |s| s[:start] }.min
    stop = group.filter_map { |s| s[:stop] || s[:last] }.max
    bytes = group.sum { |s| s.num(:tx_bytes) }
    {
      'file'              => @path,
      'transfer_id'       => xfer_id,
      'nodes'             => group.first[:cluster_nodes],
      'pids'              => group.map(&:pid),
      'peer'              => group.first[:peer],
      'direction'         => group.first.direction,
      'status'            => group.all? { |s| s[:status] == 'success' } ? 'success' : 'failed',
      'start'             => iso(start),
      'stop'              => iso(stop),
      'transmitted_bytes' => bytes,
      'average_rate'      => (bytes * 8 / (stop - start) if start && stop && stop > start)
    }.compact
  end
end

#old_versions ⇒ Array<String>

Returns ascp versions found in log, older than supported.

Returns:

  • (Array<String>) —

    ascp versions found in log, older than supported



156
157
158
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 156

def old_versions
  transfer_sessions.filter_map { |s| s[:ver] if Session.version_older?(s[:ver], MIN_VERSION) }.uniq
end

#session_reports ⇒ Array<Hash>

Returns one row per session.

Returns:

  • (Array<Hash>) —

    one row per session



98
99
100
101
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 98

def session_reports
  windows_log = @path.match?(/\w:/)
  sessions.map { |s| {'file' => @path}.merge(s.report(windows_log: windows_log)) }
end

#sessions ⇒ Array<Session>

Returns transfer sessions to report, sorted by date.

Returns:

  • (Array<Session>) —

    transfer sessions to report, sorted by date



93
94
95
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 93

def sessions
  transfer_sessions.select { |s| counted?(s) }.sort_by { |s| [s.num(:date), s[:user].to_s] }
end

#snapshot_sessions ⇒ Array<Hash>

Returns one row per session in each snapshot period.

Returns:

  • (Array<Hash>) —

    one row per session in each snapshot period



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 175

def snapshot_sessions
  reported_periods.flat_map do |time, period|
    period[:slots].sort_by { |session, _| session.pid.to_i }.filter_map do |session, slot|
      next if !@zero_bytes && slot[:net_rate].to_i.zero?
      progress = (100.0 * slot[:tx_bytes].to_i / session[:tx_bytes]).round(2) if session.flag?(:statistics) && session.num(:tx_bytes).nonzero?
      {
        'file'       => @path,
        'time'       => iso(time),
        'pid'        => session.pid,
        'session'    => session[:uuid],
        'rate'       => slot[:net_rate].to_i,
        'calculated' => slot[:avg_calc],
        'target'     => slot[:target_rate],
        'loss'       => slot[:loss_rate]&.round(2),
        'progress'   => progress,
        'direction'  => slot[:receiver] ? 'receive' : 'send',
        'constraint' => slot[:calc_1]&.join(',')
      }.compact
    end
  end
end

#snapshots ⇒ Array<Hash>

Returns one row per snapshot period.

Returns:

  • (Array<Hash>) —

    one row per snapshot period



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/aspera/ascp/log_analyzer/log_file.rb', line 161

def snapshots
  reported_periods.map do |time, period|
    t = period[:totals]
    row = {'file' => @path, 'time' => iso(time), 'sessions' => active_sessions(period[:slots])}
    if @period > 600 && period[:stop].to_i > period[:start].to_i
      duration = period[:stop] - period[:start]
      row.merge!('rate' => t[:data] / duration, 'rate_in' => t[:data_in] / duration, 'rate_out' => t[:data_out] / duration)
    else
      row.merge!(PERIOD_TOTALS.to_h { |k| [k.to_s, t[k]] })
    end
  end
end