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



104
105
106
# File 'lib/peek/views/moped.rb', line 104

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

#cmd_collection_name(cmd) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/peek/views/moped.rb', line 57

def cmd_collection_name cmd
  if not cmd.respond_to? :database
    name = "#{cmd.class.name} "
  elsif %w(admin config local).include? cmd.database
    name = %Q(<span class="peek-moped-system-db">#{cmd.database}</span>.)
  else
    name = ''
  end

  if cmd.respond_to? :collection
    if cmd.collection == '$cmd'
      if not cmd.respond_to? :selector
        name << '$cmd'
      elsif cmd.selector.has_key? :getlasterror
        name << 'getLastError()'
      elsif cmd.selector.has_key? :count
        name << "#{cmd.selector[:count]}.count()"
      elsif cmd.selector.has_key? :aggregate
        name << "#{cmd.selector[:aggregate]}.aggregate(#{cmd.selector[:pipeline].map{|p| p.keys}.flatten.join(', ')})"
      elsif cmd.selector.has_key? :mapreduce
        name << "#{cmd.selector[:mapreduce]}.mapReduce(#{cmd.selector[:out].to_s})"
      elsif cmd.selector.has_key? :findAndModify
        name << "#{cmd.selector[:findAndModify]}.findAndModify()"
      elsif cmd.selector.has_key? :geoNear
        name << "#{cmd.selector[:geoNear]}.geoNear()"
      elsif cmd.selector.has_key? :ismaster
        name << 'isMaster()'
      else
        name << '$cmd'
      end
    else
      name << cmd.collection
    end
  end

  name
end

#durationObject



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

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

#formatted_durationObject



95
96
97
98
99
100
101
102
# File 'lib/peek/views/moped.rb', line 95

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



108
109
110
# File 'lib/peek/views/moped.rb', line 108

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

#resultsObject



112
113
114
# File 'lib/peek/views/moped.rb', line 112

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