recognizer 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,7 @@ module Recognizer
21
21
  amqp.start
22
22
 
23
23
  exchange = amqp.exchange(exchange_name, :type => exchange_type.to_sym, :durable => durable)
24
- queue = amqp.queue("recognizer")
24
+ queue = amqp.queue("recognizer")
25
25
  queue.bind(exchange, :key => routing_key)
26
26
 
27
27
  Thread.abort_on_exception = true
@@ -31,6 +31,7 @@ module Recognizer
31
31
  queue.subscribe do |message|
32
32
  payload = message[:payload]
33
33
  msg_routing_key = message[:routing_key] || message[:delivery_details][:routing_key]
34
+
34
35
  lines = payload.split("\n")
35
36
  lines.each do |line|
36
37
  line = line.strip
@@ -31,7 +31,7 @@ module Recognizer
31
31
  begin
32
32
  librato.submit
33
33
  rescue => error
34
- logger.error("Encountered an error when flushing metrics to Librato: " + error.to_s)
34
+ logger.error("Encountered an error when flushing metrics to Librato :: #{error}")
35
35
  end
36
36
  end
37
37
  logger.info("Successfully flushed metrics to Librato")
@@ -57,19 +57,30 @@ module Recognizer
57
57
  loop do
58
58
  graphite_formated = carbon_queue.pop
59
59
  begin
60
- path, value, timestamp = graphite_formated.split(" ").inject([]) do |result, part|
61
- result << (result.empty? ? part.split(".") : Float(part).pretty)
62
- result
60
+ parts = graphite_formated.split("\s")
61
+
62
+ unless parts.first =~ /^[A-Za-z0-9\._-]*$/
63
+ raise "metric name must only consist of alpha-numeric characters, periods, underscores, and dashes"
64
+ end
65
+ unless parts.first.size <= 63
66
+ raise "metric name must be 63 or fewer characters"
63
67
  end
64
- source = get_source.call(path)
68
+
69
+ path = parts.shift.split(".")
70
+ value = Float(parts.shift).pretty
71
+ timestamp = Float(parts.shift).pretty
72
+ source = get_source.call(path)
73
+
65
74
  path.delete(source)
75
+
66
76
  metric = {path.join(".") => {:value => value, :measure_time => timestamp, :source => source}}
77
+
67
78
  mutex.synchronize do
68
- logger.info("Adding metric to queue: #{metric.inspect}")
79
+ logger.info("Adding metric to queue :: #{metric.inspect}")
69
80
  librato.add(metric)
70
81
  end
71
- rescue ArgumentError
72
- logger.info("Invalid metric: #{graphite_formated}")
82
+ rescue => error
83
+ logger.info("Invalid metric :: #{graphite_formated} :: #{error}")
73
84
  end
74
85
  end
75
86
  end
@@ -15,7 +15,7 @@ module Recognizer
15
15
  threads = options[:tcp][:threads] || 20
16
16
  port = options[:tcp][:port] || 2003
17
17
 
18
- tcp_server = TCPServer.new("0.0.0.0", port)
18
+ tcp_server = TCPServer.new("0.0.0.0", port)
19
19
  tcp_connections = Queue.new
20
20
 
21
21
  Thread.abort_on_exception = true
@@ -35,6 +35,7 @@ module Recognizer
35
35
  end
36
36
  end
37
37
  rescue Timeout::Error
38
+ logger.warn("TCP -- A connection has timed out")
38
39
  connection.close
39
40
  end
40
41
  end
@@ -1,3 +1,3 @@
1
1
  module Recognizer
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recognizer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Porter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-21 00:00:00 -07:00
18
+ date: 2012-03-22 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency