Class: Profiler::MCP::Resources::RecentRequests

Inherits:
Object
  • Object
show all
Defined in:
lib/profiler/mcp/resources/recent_requests.rb

Class Method Summary collapse

Class Method Details

.callObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/profiler/mcp/resources/recent_requests.rb', line 7

def self.call
  profiles = Profiler.storage.list(limit: 50)

  data = profiles.map do |profile|
    {
      token: profile.token,
      path: profile.path,
      method: profile.method,
      status: profile.status,
      duration: profile.duration&.round(2),
      memory: profile.memory ? (profile.memory / 1024.0 / 1024.0).round(2) : nil,
      timestamp: profile.started_at&.iso8601,
      query_count: profile.collector_data("database")&.dig("total_queries") || 0,
      matched_route: profile.collector_data("routes")&.dig("matched", "pattern"),
      controller_action: profile.collector_data("request")&.dig("controller_action")
    }
  end

  {
    uri: "profiler://recent",
    mimeType: "application/json",
    text: JSON.pretty_generate({
      total: data.size,
      profiles: data
    })
  }
end