Top Level Namespace

Defined Under Namespace

Classes: Solanum

Instance Method Summary collapse

Instance Method Details

#duration_str(duration) ⇒ Object

Return a human-friendly duration string for the given duration in seconds.



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/solanum/util.rb', line 2

def duration_str(duration)
  days = (duration/86400).to_i
  hours = ((duration % 86400)/3600).to_i
  minutes = ((duration % 3600)/60).to_i
  seconds = (duration % 60).to_i
  hms = "%02d:%02d:%02d" % [hours, minutes, seconds]

  if 0 < days
    "#{days} days, #{hms}"
  else
    hms
  end
end

#state_over(thresholds, metric, min_state = 'ok') ⇒ Object

Calculate the state of a metric by comparing it to the given thresholds. The metric is compared to each threshold in turn, largest to smallest. The first threshold the metric is larger than is returned, or the ‘min_sate’ is returned.



21
22
23
24
25
26
27
# File 'lib/solanum/util.rb', line 21

def state_over(thresholds, metric, min_state='ok')
  thresholds.sort_by {|e| -e[1] }.each do |threshold_entry|
    key, threshold = *threshold_entry
    return key if threshold <= metric
  end
  return min_state
end

#state_under(thresholds, metric, max_state = 'ok') ⇒ Object

Calculate the state of a metric by comparing it to the given thresholds. The metric is compared to each threshold in turn, smallest to largest. The first threshold the metric is smaller than is returned, or the ‘max_state’ is returned.



34
35
36
37
38
39
40
# File 'lib/solanum/util.rb', line 34

def state_under(thresholds, metric, max_state='ok')
  thresholds.sort_by {|e| e[1] }.each do |threshold_entry|
    key, threshold = *threshold_entry
    return key if threshold > metric
  end
  return max_state
end