fluent-plugin-dogstatsd 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6ce5e12ea022b781f31f745f2a31ff3764860ab2
4
+ data.tar.gz: 83e3d99b0b172ac3a4e678e88299b2aaeb31257c
5
+ SHA512:
6
+ metadata.gz: 779b3b7fbc3b189d88478edd560ee7dd65c02c8e3d29c02597f68dd11f3cee1ccb0139cd60a4317b2751566f5e23eedfe5959bb3ddd780ae7de8430db3edaf0d
7
+ data.tar.gz: 2f19c1bb877c1e22b581b39477221a4f0ff035e0b36fbccbd4cad556b6fb131053afd2177836e8358cbc464e84e6a8f3d3272fa3b4c4bf653cf5a0c1ae6bdc6b
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-dogstatsd.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryota Arai
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # fluent-plugin-dogstatsd
2
+
3
+ Fluend plugin for Dogstatsd, that is statsd server for Datadog.
4
+
5
+ ## Installation
6
+
7
+ $ gem install fluent-plugin-dogstatsd
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ $ echo '{"type": "increment", "key": "apache.requests", "tags": {"url": "/"}}' | fluent-cat dogstatsd.hello
13
+ $ echo '{"type": "histogram", "key": "apache.response_time", "value": 10.5, "tags": {"url": "/hello"}}' | fluent-cat dogstatsd.hello
14
+ $ echo '{"type": "event", "title": "Deploy", "text": "New revision"}' | fluent-cat dogstatsd.hello
15
+ ```
16
+
17
+ Supported types are `increment`, `decrement`, `count`, `gauge`, `histogram`, `timing`, `set` and `event`.
18
+
19
+ ## Configuration
20
+
21
+ ```
22
+ <match dogstatsd.*>
23
+ type dogstatsd
24
+
25
+ # Dogstatsd host
26
+ host localhost
27
+
28
+ # Dogstatsd port
29
+ port 8125
30
+
31
+ # Use tag of fluentd record as key sent to Dogstatsd
32
+ use_tag_as_key false
33
+ </match>
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/ryotarai/fluent-plugin-dogstatsd/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'test'
7
+ test.test_files = FileList['test/plugin/*.rb']
8
+ end
9
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent/plugin/dogstatsd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fluent-plugin-dogstatsd"
8
+ spec.version = Fluent::Plugin::Dogstatsd::VERSION
9
+ spec.authors = ["Ryota Arai"]
10
+ spec.email = ["ryota.arai@gmail.com"]
11
+ spec.summary = %q{Fluent plugin for Dogstatsd, that is statsd server for Datadog.}
12
+ spec.homepage = "https://github.com/ryotarai/fluent-plugin-dogstatsd"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "fluentd"
21
+ spec.add_dependency "dogstatsd-ruby"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,9 @@
1
+ require "fluent/plugin/dogstatsd/version"
2
+
3
+ module Fluent
4
+ module Plugin
5
+ module Dogstatsd
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'statsd'
2
+
3
+ # https://github.com/DataDog/dogstatsd-ruby/pull/10
4
+ class Statsd
5
+ def flush_buffer()
6
+ send_to_socket(@buffer.join("\n"))
7
+ @buffer = Array.new
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Fluent
2
+ module Plugin
3
+ module Dogstatsd
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,77 @@
1
+ module Fluent
2
+ class DogstatsdOutput < BufferedOutput
3
+ Plugin.register_output('dogstatsd', self)
4
+
5
+ config_param :host, :string, :default => nil
6
+ config_param :port, :integer, :default => nil
7
+ config_param :use_tag_as_key, :bool, :default => false
8
+
9
+ unless method_defined?(:log)
10
+ define_method(:log) { $log }
11
+ end
12
+
13
+ attr_accessor :statsd
14
+
15
+ def initialize
16
+ super
17
+
18
+ require 'statsd' # dogstatsd-ruby
19
+ require 'fluent/plugin/dogstatsd/statsd_patch'
20
+ end
21
+
22
+ def start
23
+ super
24
+
25
+ host = @host || Statsd::DEFAULT_HOST
26
+ port = @port || Statsd::DEFAULT_PORT
27
+
28
+ @statsd ||= Statsd.new(host, port)
29
+ end
30
+
31
+ def format(tag, time, record)
32
+ [tag, time, record].to_msgpack
33
+ end
34
+
35
+ def write(chunk)
36
+ @statsd.batch do |s|
37
+ chunk.msgpack_each do |tag, time, record|
38
+ key = if @use_tag_as_key
39
+ tag
40
+ else
41
+ record['key']
42
+ end
43
+
44
+ value = record['value']
45
+
46
+ options = {}
47
+
48
+ if record['tags']
49
+ options[:tags] = record['tags'].map do |k, v|
50
+ "#{k}:#{v}"
51
+ end
52
+ end
53
+
54
+ case record['type']
55
+ when 'increment'
56
+ s.increment(key, options)
57
+ when 'decrement'
58
+ s.decrement(key, options)
59
+ when 'count'
60
+ s.count(key, value, options)
61
+ when 'gauge'
62
+ s.gauge(key, value, options)
63
+ when 'histogram'
64
+ s.histogram(key, value, options)
65
+ when 'timing'
66
+ s.timing(key, value, options)
67
+ when 'set'
68
+ s.set(key, value, options)
69
+ when 'event'
70
+ s.event(record['title'], record['text'], options)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,108 @@
1
+ require 'test_helper'
2
+
3
+ class DummyStatsd
4
+ attr_reader :messages
5
+
6
+ def initialize
7
+ @messages = []
8
+ end
9
+
10
+ def batch
11
+ yield(self)
12
+ end
13
+
14
+ %i!increment decrement count gauge histogram timing set event!.each do |name|
15
+ define_method(name) do |*args|
16
+ @messages << [name, args].flatten
17
+ end
18
+ end
19
+ end
20
+
21
+ class DogstatsdOutputTest < Test::Unit::TestCase
22
+ def setup
23
+ Fluent::Test.setup
24
+ require 'fluent/plugin/out_dogstatsd'
25
+ end
26
+
27
+ def teardown
28
+ end
29
+
30
+ def test_configure
31
+ d = create_driver(<<-EOC)
32
+ type dogstatsd
33
+ host HOST
34
+ port 12345
35
+ EOC
36
+
37
+ assert_equal('HOST', d.instance.host)
38
+ assert_equal(12345, d.instance.port)
39
+ end
40
+
41
+ def test_write
42
+ d = create_driver
43
+
44
+ d.instance.statsd = DummyStatsd.new
45
+
46
+ d.emit({'type' => 'increment', 'key' => 'hello.world1'}, Time.now.to_i)
47
+ d.emit({'type' => 'increment', 'key' => 'hello.world2'}, Time.now.to_i)
48
+ d.emit({'type' => 'decrement', 'key' => 'hello.world'}, Time.now.to_i)
49
+ d.emit({'type' => 'count', 'value' => 10, 'key' => 'hello.world'}, Time.now.to_i)
50
+ d.emit({'type' => 'gauge', 'value' => 10, 'key' => 'hello.world'}, Time.now.to_i)
51
+ d.emit({'type' => 'histogram', 'value' => 10, 'key' => 'hello.world'}, Time.now.to_i)
52
+ d.emit({'type' => 'timing', 'value' => 10, 'key' => 'hello.world'}, Time.now.to_i)
53
+ d.emit({'type' => 'set', 'value' => 10, 'key' => 'hello.world'}, Time.now.to_i)
54
+ d.emit({'type' => 'event', 'title' => 'Deploy', 'text' => 'Revision', 'key' => 'hello.world'}, Time.now.to_i)
55
+ d.run
56
+
57
+ assert_equal(d.instance.statsd.messages, [
58
+ [:increment, 'hello.world1', {}],
59
+ [:increment, 'hello.world2', {}],
60
+ [:decrement, 'hello.world', {}],
61
+ [:count, 'hello.world', 10, {}],
62
+ [:gauge, 'hello.world', 10, {}],
63
+ [:histogram, 'hello.world', 10, {}],
64
+ [:timing, 'hello.world', 10, {}],
65
+ [:set, 'hello.world', 10, {}],
66
+ [:event, 'Deploy', 'Revision', {}],
67
+ ])
68
+ end
69
+
70
+ def test_use_tag_as_key
71
+ d = create_driver(<<-EOC)
72
+ #{default_config}
73
+ use_tag_as_key true
74
+ EOC
75
+
76
+ d.instance.statsd = DummyStatsd.new
77
+
78
+ d.emit({'type' => 'increment'}, Time.now.to_i)
79
+ d.run
80
+
81
+ assert_equal(d.instance.statsd.messages, [
82
+ [:increment, 'dogstatsd.tag', {}],
83
+ ])
84
+ end
85
+
86
+ def test_tags
87
+ d = create_driver
88
+ d.instance.statsd = DummyStatsd.new
89
+ d.emit({'type' => 'increment', 'key' => 'hello.world', 'tags' => {'key' => 'value'}}, Time.now.to_i)
90
+ d.run
91
+
92
+ assert_equal(d.instance.statsd.messages, [
93
+ [:increment, 'hello.world', {tags: ["key:value"]}],
94
+ ])
95
+ end
96
+
97
+ private
98
+ def default_config
99
+ <<-EOC
100
+ type dogstatsd
101
+ EOC
102
+ end
103
+
104
+ def create_driver(conf = default_config)
105
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::DogstatsdOutput, 'dogstatsd.tag').configure(conf)
106
+ end
107
+ end
108
+
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ require 'fluent/test'
3
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-dogstatsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryota Arai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: dogstatsd-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - ryota.arai@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - fluent-plugin-dogstatsd.gemspec
82
+ - lib/fluent/plugin/dogstatsd.rb
83
+ - lib/fluent/plugin/dogstatsd/statsd_patch.rb
84
+ - lib/fluent/plugin/dogstatsd/version.rb
85
+ - lib/fluent/plugin/out_dogstatsd.rb
86
+ - test/plugin/test_out_dogstatsd.rb
87
+ - test/test_helper.rb
88
+ homepage: https://github.com/ryotarai/fluent-plugin-dogstatsd
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Fluent plugin for Dogstatsd, that is statsd server for Datadog.
112
+ test_files:
113
+ - test/plugin/test_out_dogstatsd.rb
114
+ - test/test_helper.rb