Class: Peek::Views::Moped

Inherits:
View
  • Object
show all
Defined in:
lib/peek/views/moped.rb

Constant Summary collapse

OP_CODES =
{
  '1'    => ['*', 'Reply to a client request. responseTo is set'],
  '1000' => ['*', 'Generic msg command followed by a string'],
  '2001' => ['U', 'Update document'],
  '2002' => ['I', 'Insert new document'],
  '2003' => ['*', 'Formerly used for OP_GET_BY_OID'],
  '2004' => ['R', 'Query a collection'],
  '2005' => ['RR','Get more data from a query'],
  '2006' => ['D', 'Delete documents'],
  '2007' => ['*', 'Tell database client is done with a cursor']
}

Instance Method Summary collapse

Instance Method Details

#callsObject



66
67
68
# File 'lib/peek/views/moped.rb', line 66

def calls
  ::Moped::Node.command_count.value
end

#durationObject



44
45
46
# File 'lib/peek/views/moped.rb', line 44

def duration
  ::Moped::Node.command_time.value
end

#formatted_durationObject



57
58
59
60
61
62
63
64
# File 'lib/peek/views/moped.rb', line 57

def formatted_duration
  ms = duration * 1000
  if ms >= 1000
    "%.2fms" % ms
  else
    "%.0fms" % ms
  end
end

#op_code_info(op_code) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/peek/views/moped.rb', line 48

def op_code_info op_code
  key = op_code.to_s
  if OP_CODES.has_key? key
    OP_CODES[key]
  else
    [key, 'Undescribed op_code of mongodb wired protocol']
  end
end

#operationsObject



70
71
72
# File 'lib/peek/views/moped.rb', line 70

def operations
  ::Moped::Node.command_operations.value
end

#resultsObject



74
75
76
# File 'lib/peek/views/moped.rb', line 74

def results
  { :duration => formatted_duration, :calls => calls, :operations => operations.inspect }
end