Class: ExoLogging::ProviderFailure

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/exologging/provider_failure.rb

Constant Summary collapse

@@app_name =
'Untitled'

Class Method Summary collapse

Class Method Details

.mk!(provider) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/exologging/provider_failure.rb', line 19

def self.mk!(provider)
  x = ProviderFailure.new
  x.name     = @@app_name
  x.provider = provider

  x.save!
  x
end

.mtbf(provider, from = 0, mtbf_type = 'decaying') ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/exologging/provider_failure.rb', line 55

def self.mtbf(provider, from=0, mtbf_type='decaying')
  from_time = ExoBasic::Timer.from_epoch(from).to_datetime
  failed_ts = ProviderFailure.where(name: @@app_name,
                                    provider: provider,
                                    :created_at.gte => from_time)
                             .map { |i| ExoBasic::Timer.to_epoch(i.created_at) }
                             .to_a
                             .sort

  ProviderFailure.mtbf_helper(failed_ts, mtbf_type)
end

.mtbf_helper(failed_ts, mtbf_type) ⇒ Object



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
# File 'lib/exologging/provider_failure.rb', line 28

def self.mtbf_helper(failed_ts, mtbf_type)
  failed_count = failed_ts.length

  last = -1
  mtbf = 0.0
  if failed_count > 0
    last = failed_ts[-1]
    tbf  = failed_ts[1..-1].zip(failed_ts).map { |pair| pair[0] - pair[1] }
    mtbf = nil
    case mtbf_type
    when 'mean'
      mtbf = ExoBasic::MeanAvg.new
    when 'short_term'
      mtbf = ExoBasic::ShortTermAvg.new
    else
      mtbf = ExoBasic::DecayingAvg.new
    end
    mtbf.offer_many(tbf)
  end

  {
    :count => failed_count,
    :last => last,
    :mtbf => mtbf.as_json
  }
end

.set_app_name(appname) ⇒ Object



15
16
17
# File 'lib/exologging/provider_failure.rb', line 15

def self.set_app_name(appname)
  @@app_name = appname
end