Module: Mouth
- Defined in:
- lib/mouth.rb,
lib/mouth/graph.rb,
lib/mouth/record.rb,
lib/mouth/runner.rb,
lib/mouth/source.rb,
lib/mouth/sucker.rb,
lib/mouth/version.rb,
lib/mouth/recorder.rb,
lib/mouth/dashboard.rb,
lib/mouth/endoscope.rb,
lib/mouth/instrument.rb,
lib/mouth/sequence_query.rb
Defined Under Namespace
Modules: Recorder Classes: Dashboard, Endoscope, Graph, Record, Runner, SequenceQuery, Source, Sucker, SuckerConnection
Constant Summary collapse
- VERSION =
"0.8.2"
Class Attribute Summary collapse
-
.daemon_host ⇒ Object
Returns the value of attribute daemon_host.
-
.daemon_port ⇒ Object
Returns the value of attribute daemon_port.
-
.disabled ⇒ Object
Returns the value of attribute disabled.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.mongo ⇒ Object
Returns a mongo connection (NOT an em-mongo connection).
-
.mongo_db_name ⇒ Object
Info to connect to mongo.
-
.mongo_hostports ⇒ Object
Returns the value of attribute mongo_hostports.
Class Method Summary collapse
- .collection(collection_name) ⇒ Object
- .collection_for(namespace) ⇒ Object
- .current_timestamp ⇒ Object
-
.daemon_hostport=(hostport) ⇒ Object
Mouth.server = ‘localhost:1234’.
- .gauge(key, value) ⇒ Object
- .increment(key, delta = 1, sample_rate = nil) ⇒ Object
- .measure(key, milli = nil) ⇒ Object
- .mongo_collection_name(namespace) ⇒ Object
-
.parse_key(key) ⇒ Object
Parses a key into two parts: namespace, and metric.
- .sanitize_metric(key) ⇒ Object
- .sanitize_namespace(key) ⇒ Object
- .timestamp_for(time) ⇒ Object
Class Attribute Details
.daemon_host ⇒ Object
Returns the value of attribute daemon_host.
7 8 9 |
# File 'lib/mouth/instrument.rb', line 7 def daemon_host @daemon_host end |
.daemon_port ⇒ Object
Returns the value of attribute daemon_port.
7 8 9 |
# File 'lib/mouth/instrument.rb', line 7 def daemon_port @daemon_port end |
.disabled ⇒ Object
Returns the value of attribute disabled.
7 8 9 |
# File 'lib/mouth/instrument.rb', line 7 def disabled @disabled end |
.logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/mouth.rb', line 6 def logger @logger end |
.mongo ⇒ Object
Returns a mongo connection (NOT an em-mongo connection)
9 10 11 |
# File 'lib/mouth.rb', line 9 def mongo @mongo end |
.mongo_db_name ⇒ Object
Info to connect to mongo
12 13 14 |
# File 'lib/mouth.rb', line 12 def mongo_db_name @mongo_db_name end |
.mongo_hostports ⇒ Object
Returns the value of attribute mongo_hostports.
13 14 15 |
# File 'lib/mouth.rb', line 13 def mongo_hostports @mongo_hostports end |
Class Method Details
.collection(collection_name) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/mouth.rb', line 39 def collection(collection_name) @collections ||= {} @collections[collection_name] ||= begin c = mongo.collection(collection_name) c.ensure_index([["t", 1]], {:background => true, :unique => true}) c end end |
.collection_for(namespace) ⇒ Object
52 53 54 |
# File 'lib/mouth.rb', line 52 def collection_for(namespace) collection(mongo_collection_name(namespace)) end |
.current_timestamp ⇒ Object
85 86 87 |
# File 'lib/mouth.rb', line 85 def (Time.now) end |
.daemon_hostport=(hostport) ⇒ Object
Mouth.server = ‘localhost:1234’
10 11 12 13 |
# File 'lib/mouth/instrument.rb', line 10 def daemon_hostport=(hostport) self.daemon_host, port = hostport.split(':') self.daemon_port = port.to_i end |
.gauge(key, value) ⇒ Object
36 37 38 |
# File 'lib/mouth/instrument.rb', line 36 def gauge(key, value) write(key, value, :g) end |
.increment(key, delta = 1, sample_rate = nil) ⇒ Object
32 33 34 |
# File 'lib/mouth/instrument.rb', line 32 def increment(key, delta = 1, sample_rate = nil) write(key, delta, :c, sample_rate) end |
.measure(key, milli = nil) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/mouth/instrument.rb', line 23 def measure(key, milli = nil) result = nil ms = milli || (Benchmark.realtime { result = yield } * 1000).to_i write(key, ms, :ms) result end |
.mongo_collection_name(namespace) ⇒ Object
48 49 50 |
# File 'lib/mouth.rb', line 48 def mongo_collection_name(namespace) "mouth_#{namespace}" end |
.parse_key(key) ⇒ Object
Parses a key into two parts: namespace, and metric. Also sanitizes each field Returns an array of values: [namespace, metric] eg, parse_key(“Ticket.process_new_ticket”) # => [“Ticket”, “process_new_ticket”] parse_key(“Forum List.other! stuff.ok”) # => [“Forum_List”, “other_stuff-ok”] parse_key(“no_namespace”) # => [“default”, “no_namespace”]
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mouth.rb', line 70 def parse_key(key) parts = key.split(".") namespace = nil metric = nil if parts.length > 1 namespace = parts.shift metric = parts.join("-") else namespace = "default" metric = parts.shift end [sanitize_namespace(namespace), sanitize_metric(metric)] end |
.sanitize_metric(key) ⇒ Object
60 61 62 |
# File 'lib/mouth.rb', line 60 def sanitize_metric(key) key.gsub(/\s+/, '_').gsub(/[^a-zA-Z0-9\-_\/]/, '') end |
.sanitize_namespace(key) ⇒ Object
56 57 58 |
# File 'lib/mouth.rb', line 56 def sanitize_namespace(key) key.gsub(/\s+/, '_').gsub(/\//, '-').gsub(/[^a-zA-Z_\-0-9]/, '') end |
.timestamp_for(time) ⇒ Object
89 90 91 |
# File 'lib/mouth.rb', line 89 def (time) time.to_i / 60 end |