ffwd-statsd 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d31b39fbd8c44b4fcfda668ddeae8d54c55f54af
4
+ data.tar.gz: 9267ac8d0db93a0f100ee343668794f118bf4f99
5
+ SHA512:
6
+ metadata.gz: 280cc329aab4689fd1e678a4e7947c590f00bc228e41501f930400b6242287f5aee182a3fefca92b6aaacfe6e2a48ba98a0828527aa8899826a9f41f142e5217
7
+ data.tar.gz: f6590d1cfc9a80ebb23ed418f02e93f3314eb63f7cfef77a76955e35e1bde238b53c9f827efeafe816fde96cd2e1241204049ae7895bc67f670991b36a152bb5
@@ -0,0 +1,43 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'ffwd/plugin'
17
+ require 'ffwd/protocol'
18
+ require 'ffwd/logging'
19
+
20
+ require_relative 'statsd/connection'
21
+
22
+ module FFWD::Plugin::Statsd
23
+ include FFWD::Plugin
24
+ include FFWD::Logging
25
+
26
+ register_plugin "statsd"
27
+
28
+ DEFAULT_HOST = "localhost"
29
+ DEFAULT_PORT = 8125
30
+
31
+ def self.setup_input opts, core
32
+ opts[:host] ||= DEFAULT_HOST
33
+ opts[:port] ||= DEFAULT_PORT
34
+ protocol = FFWD.parse_protocol(opts[:protocol] || "udp")
35
+ protocol.bind opts, core, log, Connection
36
+ end
37
+
38
+ def self.setup_tunnel opts, core, tunnel
39
+ opts[:port] ||= DEFAULT_PORT
40
+ protocol = FFWD.parse_protocol(opts[:protocol] || "tcp")
41
+ protocol.tunnel opts, core, tunnel, log, Connection
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'ffwd/logging'
17
+ require 'ffwd/connection'
18
+
19
+ require_relative 'parser'
20
+
21
+ module FFWD::Plugin::Statsd
22
+ class Connection < FFWD::Connection
23
+ include FFWD::Logging
24
+
25
+ def self.plugin_type
26
+ "statsd_in"
27
+ end
28
+
29
+ def initialize bind, core
30
+ @bind = bind
31
+ @core = core
32
+ end
33
+
34
+ def receive_data(data)
35
+ metric = Parser.parse(data)
36
+ return if metric.nil?
37
+ @core.input.metric metric
38
+ @bind.increment :received_metrics
39
+ rescue => e
40
+ log.error "Failed to receive data", e
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,64 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ module FFWD::Plugin::Statsd
17
+ module Parser
18
+ COUNT = "count"
19
+ HISTOGRAM = "histogram"
20
+
21
+ def self.gauge name, value
22
+ {:proc => nil, :key => name, :value => value}
23
+ end
24
+
25
+ def self.count name, value
26
+ {:proc => COUNT, :key => name, :value => value}
27
+ end
28
+
29
+ def self.timing name, value
30
+ {:proc => HISTOGRAM, :key => name, :value => value}
31
+ end
32
+
33
+ def self.parse line
34
+ name, value = line.split ':', 2
35
+ raise "invalid frame" if value.nil?
36
+ value, type = value.split '|', 2
37
+ raise "invalid frame" if type.nil?
38
+ type, sample_rate = type.split '|@', 2
39
+
40
+ return nil if type.nil? or type.empty?
41
+ return nil if value.nil? or value.empty?
42
+
43
+ value = value.to_f unless value.nil?
44
+ sample_rate = sample_rate.to_f unless sample_rate.nil?
45
+
46
+ value /= sample_rate unless sample_rate.nil?
47
+
48
+ if type == "g"
49
+ return gauge(name, value)
50
+ end
51
+
52
+ if type == "c"
53
+ return count(name, value)
54
+ end
55
+
56
+ if type == "ms"
57
+ return timing(name, value)
58
+ end
59
+
60
+ log.warning "Not supported type: #{type}"
61
+ return nil
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,22 @@
1
+ # $LICENSE
2
+ # Copyright 2013-2014 Spotify AB. All rights reserved.
3
+ #
4
+ # The contents of this file are licensed under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ module FFWD
17
+ module Plugin
18
+ module Statsd
19
+ VERSION = "0.1.0"
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ffwd-statsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John-John Tedro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffwd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-mocks
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - udoprog@spotify.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/ffwd/plugin/statsd.rb
63
+ - lib/ffwd/plugin/statsd/parser.rb
64
+ - lib/ffwd/plugin/statsd/connection.rb
65
+ - lib/ffwd/plugin/statsd/version.rb
66
+ homepage: https://github.com/spotify/ffwd
67
+ licenses:
68
+ - Apache 2.0
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.3
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: StatsD support for FFWD.
90
+ test_files: []