Class: PSI::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/psi/event.rb

Overview

A pressure event delivered by Monitor.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trigger:, reading:, at: Time.now) ⇒ Event

Returns a new instance of Event.



8
9
10
11
12
13
14
15
# File 'lib/psi/event.rb', line 8

def initialize(trigger:, reading:, at: Time.now)
  @resource = trigger.resource
  @kind = trigger.kind
  @stall = trigger.stall
  @window = trigger.window
  @reading = reading
  @at = at
end

Instance Attribute Details

#atObject (readonly)

Returns the value of attribute at.



6
7
8
# File 'lib/psi/event.rb', line 6

def at
  @at
end

#kindObject (readonly)

Returns the value of attribute kind.



6
7
8
# File 'lib/psi/event.rb', line 6

def kind
  @kind
end

#readingObject (readonly)

Returns the value of attribute reading.



6
7
8
# File 'lib/psi/event.rb', line 6

def reading
  @reading
end

#resourceObject (readonly)

Returns the value of attribute resource.



6
7
8
# File 'lib/psi/event.rb', line 6

def resource
  @resource
end

#stallObject (readonly)

Returns the value of attribute stall.



6
7
8
# File 'lib/psi/event.rb', line 6

def stall
  @stall
end

#windowObject (readonly)

Returns the value of attribute window.



6
7
8
# File 'lib/psi/event.rb', line 6

def window
  @window
end

Instance Method Details

#to_sString

Formats the pressure and threshold for logs.

Returns:

  • (String)


19
20
21
22
23
# File 'lib/psi/event.rb', line 19

def to_s
  average = reading.public_send(kind)&.avg10
  value = average ? " avg10=#{average}%" : ""
  "#{resource} #{kind}#{value} (threshold #{duration(stall)}/#{duration(window)})"
end