Class: RubyLLM::Ups::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/ups/monitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, component_id:, client:, async_reporter: nil) ⇒ Monitor

Returns a new instance of Monitor.



8
9
10
11
12
13
14
15
16
# File 'lib/ruby_llm/ups/monitor.rb', line 8

def initialize(target, component_id:, client:, async_reporter: nil)
  @chat = extract_chat(target)
  @component_id = component_id
  @client = client
  @async_reporter = async_reporter
  @request_start = nil
  install_callbacks
  install_incident_methods(target)
end

Instance Attribute Details

#client ⇒ Object (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/ruby_llm/ups/monitor.rb', line 6

def client
  @client
end

#component_id ⇒ Object (readonly)

Returns the value of attribute component_id.



6
7
8
# File 'lib/ruby_llm/ups/monitor.rb', line 6

def component_id
  @component_id
end

Instance Method Details

#build_metadata ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby_llm/ups/monitor.rb', line 32

def 
   = {
    model: @chat.model.id,
    provider: @chat.model.provider.to_s,
    tool_count: @chat.tools.size
  }

  if @request_start
    elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - @request_start
    [:last_response_time_ms] = (elapsed * 1000).round
  end

  
end

#mark_start ⇒ Object



18
19
20
# File 'lib/ruby_llm/ups/monitor.rb', line 18

def mark_start
  @request_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

#report(_message) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/ruby_llm/ups/monitor.rb', line 22

def report(_message)
  if @async_reporter
    @async_reporter.enqueue(@component_id, status: :operational, agent_metadata: )
  else
    @client.update_component(@component_id, status: :operational, agent_metadata: )
  end
rescue => e
  handle_error(e)
end