ffwd-statsd 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ffwd/plugin/statsd/connection.rb +47 -15
- data/lib/ffwd/plugin/statsd/parser.rb +37 -12
- data/lib/ffwd/plugin/statsd/version.rb +1 -1
- data/lib/ffwd/plugin/statsd.rb +14 -2
- metadata +18 -10
- checksums.yaml +0 -15
@@ -19,25 +19,57 @@ require 'ffwd/connection'
|
|
19
19
|
require_relative 'parser'
|
20
20
|
|
21
21
|
module FFWD::Plugin::Statsd
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
module Connection
|
23
|
+
module ConnectionBase
|
24
|
+
def receive_statsd_frame(data)
|
25
|
+
metric = Parser.parse(data)
|
26
|
+
return if metric.nil?
|
27
|
+
@core.input.metric metric
|
28
|
+
@bind.increment :received_metrics
|
29
|
+
rescue ParserError => e
|
30
|
+
log.error "Invalid frame '#{data}': #{e}"
|
31
|
+
@bind.increment :failed_metrics
|
32
|
+
rescue => e
|
33
|
+
log.error "Error when parsing metric '#{data}'", e
|
34
|
+
@bind.increment :failed_metrics
|
35
|
+
end
|
27
36
|
end
|
28
37
|
|
29
|
-
|
30
|
-
|
31
|
-
|
38
|
+
class UDP < FFWD::Connection
|
39
|
+
include ConnectionBase
|
40
|
+
include FFWD::Logging
|
41
|
+
|
42
|
+
def initialize bind, core
|
43
|
+
@bind = bind
|
44
|
+
@core = core
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.plugin_type
|
48
|
+
"statsd_udp_in"
|
49
|
+
end
|
50
|
+
|
51
|
+
def receive_data data
|
52
|
+
receive_statsd_frame data
|
53
|
+
end
|
32
54
|
end
|
33
55
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
56
|
+
class TCP < FFWD::Connection
|
57
|
+
include ConnectionBase
|
58
|
+
include FFWD::Logging
|
59
|
+
include EM::Protocols::LineText2
|
60
|
+
|
61
|
+
def initialize bind, core
|
62
|
+
@bind = bind
|
63
|
+
@core = core
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.plugin_type
|
67
|
+
"statsd_tcp_in"
|
68
|
+
end
|
69
|
+
|
70
|
+
def receive_line(data)
|
71
|
+
receive_statsd_frame data
|
72
|
+
end
|
41
73
|
end
|
42
74
|
end
|
43
75
|
end
|
@@ -14,9 +14,12 @@
|
|
14
14
|
# the License.
|
15
15
|
|
16
16
|
module FFWD::Plugin::Statsd
|
17
|
+
class ParserError < Exception; end
|
18
|
+
|
17
19
|
module Parser
|
18
20
|
COUNT = "count"
|
19
21
|
HISTOGRAM = "histogram"
|
22
|
+
RATE = "rate"
|
20
23
|
|
21
24
|
def self.gauge name, value
|
22
25
|
{:proc => nil, :key => name, :value => value}
|
@@ -26,21 +29,39 @@ module FFWD::Plugin::Statsd
|
|
26
29
|
{:proc => COUNT, :key => name, :value => value}
|
27
30
|
end
|
28
31
|
|
32
|
+
def self.meter name, value
|
33
|
+
{:proc => RATE, :key => name, :value => value}
|
34
|
+
end
|
35
|
+
|
29
36
|
def self.timing name, value
|
30
37
|
{:proc => HISTOGRAM, :key => name, :value => value}
|
31
38
|
end
|
32
39
|
|
33
|
-
def self.parse
|
34
|
-
name, value =
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
def self.parse m
|
41
|
+
name, value = m.split ':', 2
|
42
|
+
|
43
|
+
if value.nil?
|
44
|
+
raise ParserError.new("Missing value")
|
45
|
+
end
|
46
|
+
|
47
|
+
value, type_block = value.split '|', 2
|
48
|
+
|
49
|
+
if type_block.nil?
|
50
|
+
raise ParserError.new("Missing type")
|
51
|
+
end
|
39
52
|
|
40
|
-
|
41
|
-
|
53
|
+
type, sample_rate = type_block.split '|@', 2
|
54
|
+
|
55
|
+
if type.nil? or type.empty?
|
56
|
+
raise ParserError.new("Missing type")
|
57
|
+
end
|
58
|
+
|
59
|
+
if value.nil? or value.empty?
|
60
|
+
raise ParserError.new("Missing value")
|
61
|
+
end
|
62
|
+
|
63
|
+
value = value.to_f
|
42
64
|
|
43
|
-
value = value.to_f unless value.nil?
|
44
65
|
sample_rate = sample_rate.to_f unless sample_rate.nil?
|
45
66
|
|
46
67
|
value /= sample_rate unless sample_rate.nil?
|
@@ -53,12 +74,16 @@ module FFWD::Plugin::Statsd
|
|
53
74
|
return count(name, value)
|
54
75
|
end
|
55
76
|
|
56
|
-
if type == "
|
77
|
+
if type == "m"
|
78
|
+
return meter(name, value)
|
79
|
+
end
|
80
|
+
|
81
|
+
if type == "ms" or type == "h"
|
57
82
|
return timing(name, value)
|
58
83
|
end
|
59
84
|
|
60
|
-
|
61
|
-
|
85
|
+
raise ParserError.new(
|
86
|
+
"Received message of unsupported type '#{type}'")
|
62
87
|
end
|
63
88
|
end
|
64
89
|
end
|
data/lib/ffwd/plugin/statsd.rb
CHANGED
@@ -28,16 +28,28 @@ module FFWD::Plugin::Statsd
|
|
28
28
|
DEFAULT_HOST = "localhost"
|
29
29
|
DEFAULT_PORT = 8125
|
30
30
|
|
31
|
+
INPUTS = {:tcp => Connection::TCP, :udp => Connection::UDP}
|
32
|
+
|
31
33
|
def self.setup_input opts, core
|
32
34
|
opts[:host] ||= DEFAULT_HOST
|
33
35
|
opts[:port] ||= DEFAULT_PORT
|
34
36
|
protocol = FFWD.parse_protocol(opts[:protocol] || "udp")
|
35
|
-
|
37
|
+
|
38
|
+
unless connection = INPUTS[protocol.family]
|
39
|
+
raise "No connection for protocol family: #{protocol.family}"
|
40
|
+
end
|
41
|
+
|
42
|
+
protocol.bind opts, core, log, connection
|
36
43
|
end
|
37
44
|
|
38
45
|
def self.setup_tunnel opts, core, tunnel
|
39
46
|
opts[:port] ||= DEFAULT_PORT
|
40
47
|
protocol = FFWD.parse_protocol(opts[:protocol] || "tcp")
|
41
|
-
|
48
|
+
|
49
|
+
unless connection = INPUTS[protocol.family]
|
50
|
+
raise "No connection for protocol family: #{protocol.family}"
|
51
|
+
end
|
52
|
+
|
53
|
+
protocol.tunnel opts, core, tunnel, log, connection
|
42
54
|
end
|
43
55
|
end
|
metadata
CHANGED
@@ -1,32 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffwd-statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- John-John Tedro
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: ffwd
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - '='
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
21
|
+
version: 0.1.7
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - '='
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 0.1.7
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rspec
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -41,6 +46,7 @@ dependencies:
|
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rspec-mocks
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -59,32 +66,33 @@ executables: []
|
|
59
66
|
extensions: []
|
60
67
|
extra_rdoc_files: []
|
61
68
|
files:
|
69
|
+
- lib/ffwd/plugin/statsd.rb
|
62
70
|
- lib/ffwd/plugin/statsd/version.rb
|
63
71
|
- lib/ffwd/plugin/statsd/parser.rb
|
64
72
|
- lib/ffwd/plugin/statsd/connection.rb
|
65
|
-
- lib/ffwd/plugin/statsd.rb
|
66
73
|
homepage: https://github.com/spotify/ffwd
|
67
74
|
licenses:
|
68
75
|
- Apache 2.0
|
69
|
-
metadata: {}
|
70
76
|
post_install_message:
|
71
77
|
rdoc_options: []
|
72
78
|
require_paths:
|
73
79
|
- lib
|
74
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
75
82
|
requirements:
|
76
83
|
- - ! '>='
|
77
84
|
- !ruby/object:Gem::Version
|
78
85
|
version: '0'
|
79
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
80
88
|
requirements:
|
81
89
|
- - ! '>='
|
82
90
|
- !ruby/object:Gem::Version
|
83
91
|
version: '0'
|
84
92
|
requirements: []
|
85
93
|
rubyforge_project:
|
86
|
-
rubygems_version:
|
94
|
+
rubygems_version: 1.8.23
|
87
95
|
signing_key:
|
88
|
-
specification_version:
|
96
|
+
specification_version: 3
|
89
97
|
summary: StatsD support for FFWD.
|
90
98
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
MTQ4OGUwYzIwMDE0ZWYwNDA3NzkxYmQwNWI4NDEyYTM2NTQ2MzUzMA==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ODcwY2UwZjU5Y2Q5MTJmMWYzNDk2Yjc2MDBiMDYzM2U4OGNhY2E3NA==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ZWUyMzc5MDRlZTE0YWE5YWRmYmFjNWVlY2MzZjkxNDdmZWRmY2MyMGFkYjc5
|
10
|
-
MDUzMjA5MDU0MDhmMmI5MWNlMTBjNDE4NzRjYTU1YjZhZTViMDBlY2QxMWI0
|
11
|
-
NDk3MTdhYjJjOWIwZTM0NmMzMjkwZmNiYmY2OWYxZmUwNTBjOWU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZTJlZGExNDA0MjAyOGFlZWY1NTVjMGViYzBiYmQ3YTAwNjVkNDU3NTM2NTY5
|
14
|
-
YjJlZGJlOTQwZTgzYzk5YjM1OGNmMjFkYWRmZjFmOWViMDNlZDliZjdhYTli
|
15
|
-
Nzc0MDVmMDZiODlmMzdiYTc0YzAyYWIxMjBhZWM2Y2Y4MTI0OTg=
|