fluent-plugin-statsd-output 1.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: bf28263842e81f1b71c3741005e7f8f30d4f7d03
4
+ data.tar.gz: 343f9697a96eedf12d4fb237ea032ba8c7f60c8b
5
+ SHA512:
6
+ metadata.gz: 1d7fd5b1508d0e791a0d738d7a12c0e61daf601ed388dec10ceb5cd40caa03afd8ccb197cbd66c27fdf33c4a2141627e6a3cb6b0c438404734e90fef14ff72e7
7
+ data.tar.gz: 15f543b72a246f1a6a129af83ba4f407086750d0ff9e15be2d079bc6c7637e16f36298bb097ca433eb70cbcf0ee5e26dbd6625ff093f042a5fc4d7339ffa5c86
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.swp
2
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/AUTHORS ADDED
@@ -0,0 +1,2 @@
1
+ Chris Song <fakechris _at_ gmail.com>
2
+ Jon Xie <Jon.xie _at_ liulishuo.com>
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem "statsd-ruby"
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-statsd (1.1.0)
5
+ fluentd (>= 0.10.8)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ coderay (1.1.1)
11
+ cool.io (1.4.4)
12
+ diff-lcs (1.2.5)
13
+ fluentd (0.14.1)
14
+ cool.io (>= 1.4.3, < 2.0.0)
15
+ http_parser.rb (>= 0.5.1, < 0.7.0)
16
+ json (>= 1.4.3)
17
+ msgpack (>= 0.7.0)
18
+ serverengine (>= 1.6.4)
19
+ sigdump (~> 0.2.2)
20
+ strptime (>= 0.1.7)
21
+ tzinfo (>= 1.0.0)
22
+ tzinfo-data (>= 1.0.0)
23
+ yajl-ruby (~> 1.0)
24
+ http_parser.rb (0.6.0)
25
+ json (2.0.1)
26
+ method_source (0.8.2)
27
+ msgpack (1.0.0)
28
+ power_assert (0.3.0)
29
+ pry (0.10.4)
30
+ coderay (~> 1.1.0)
31
+ method_source (~> 0.8.1)
32
+ slop (~> 3.4)
33
+ rspec (3.5.0)
34
+ rspec-core (~> 3.5.0)
35
+ rspec-expectations (~> 3.5.0)
36
+ rspec-mocks (~> 3.5.0)
37
+ rspec-core (3.5.1)
38
+ rspec-support (~> 3.5.0)
39
+ rspec-expectations (3.5.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.5.0)
42
+ rspec-mocks (3.5.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.5.0)
45
+ rspec-support (3.5.0)
46
+ serverengine (1.6.4)
47
+ sigdump (~> 0.2.2)
48
+ sigdump (0.2.4)
49
+ slop (3.6.0)
50
+ statsd-ruby (1.3.0)
51
+ strptime (0.1.8)
52
+ test-unit (3.1.8)
53
+ power_assert
54
+ thread_safe (0.3.5)
55
+ tzinfo (1.2.2)
56
+ thread_safe (~> 0.1)
57
+ tzinfo-data (1.2016.6)
58
+ tzinfo (>= 1.0.0)
59
+ yajl-ruby (1.2.1)
60
+
61
+ PLATFORMS
62
+ ruby
63
+
64
+ DEPENDENCIES
65
+ fluent-plugin-statsd!
66
+ pry
67
+ rspec (~> 3.0)
68
+ statsd-ruby
69
+ test-unit
70
+
71
+ BUNDLED WITH
72
+ 1.10.6
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Fluent event to statsd plugin.
2
+
3
+ # Installation
4
+
5
+ ```
6
+ $ fluent-gem install fluent-plugin-statsd
7
+ ```
8
+
9
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-statsd.png)](http://badge.fury.io/rb/fluent-plugin-statsd)
10
+
11
+ # Usage
12
+
13
+ ```
14
+ <match statsd>
15
+ type statsd
16
+ host localhost # optional
17
+ port 8125 # optional
18
+ namespace a.b.c # optional
19
+
20
+ <metric>
21
+ statsd_type timing
22
+ statsd_key my_app.nginx.response_time
23
+ statsd_key ${record['response_time']}
24
+ </metric>
25
+
26
+ <metric>
27
+ statsd_type incrument
28
+ statsd_key my_app.nginx.${response_code.to_i / 100}xx # 2xx 4xx 5xx
29
+ </metric>
30
+ </match>
31
+ ```
32
+
33
+ # Development
34
+
35
+ ```
36
+ $ rspec
37
+ ```
38
+
39
+ # Copyright
40
+
41
+ Copyright (c) 2014- Chris Song
42
+
43
+ # License
44
+
45
+ Apache License, Version 2.0
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.0
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-statsd-output"
6
+ gem.description = "fluentd output filter plugin to send metrics to Esty StatsD"
7
+ gem.homepage = "https://github.com/lingochamp/fluent-plugin-statsd"
8
+ gem.summary = gem.description
9
+ gem.version = File.read("VERSION").strip
10
+ gem.authors = ["Chris Song"]
11
+ gem.email = "fakechris@gmail.com"
12
+ gem.has_rdoc = false
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_dependency "fluentd", ">= 0.10.8"
19
+
20
+ gem.add_development_dependency "rspec", '~> 3.0'
21
+ gem.add_development_dependency "test-unit"
22
+ gem.add_development_dependency "statsd-ruby", ">=1.2.1"
23
+ gem.add_development_dependency "pry"
24
+ end
@@ -0,0 +1,94 @@
1
+ require 'statsd-ruby'
2
+ require 'ostruct'
3
+ require 'fluent/output'
4
+
5
+ module Fluent
6
+ class StatsdOutput < BufferedOutput
7
+ Fluent::Plugin.register_output('statsd', self)
8
+
9
+ config_param :flush_interval, :time, :default => 1
10
+ config_param :host, :string, :default => 'localhost'
11
+ config_param :port, :string, :default => '8125'
12
+ config_param :namespace, :string, :default => nil
13
+
14
+ config_section :metric do
15
+ config_param :statsd_type, :string
16
+ config_param :statsd_key, :string
17
+ config_param :statsd_val, :string, default: nil
18
+ end
19
+
20
+ attr_reader :statsd
21
+
22
+ def initialize
23
+ super
24
+ end
25
+
26
+ def configure(conf)
27
+ super
28
+ @statsd = Statsd.new(host, port)
29
+ @statsd.namespace = namespace if namespace
30
+ log.info(statsd)
31
+
32
+ @metrics = conf.elements.select {|elem| elem.name == 'metric' }
33
+ log.info(@metrics)
34
+ end
35
+
36
+ def start
37
+ super
38
+ end
39
+
40
+ def shutdown
41
+ super
42
+ end
43
+
44
+ def format(tag, time, record)
45
+ [tag, record].to_msgpack
46
+ end
47
+
48
+ def write(chunk)
49
+ chunk.msgpack_each do |tag, record|
50
+ parser = RubyStringParser.new(record: record, tag: tag)
51
+
52
+ @metrics.each do |metric|
53
+ arg_names = %w{statsd_type statsd_key statsd_val}
54
+ send_to_statsd(*metric.values_at(*arg_names).map {|str| parser.parse(str) })
55
+ end
56
+ end
57
+ end
58
+
59
+
60
+ private
61
+
62
+ def send_to_statsd(type, key, val)
63
+ log.debug([type, key, val])
64
+
65
+ case type
66
+ when 'timing'
67
+ @statsd.timing key, val.to_f
68
+ when 'gauge'
69
+ @statsd.gauge key, val.to_f
70
+ when 'count'
71
+ @statsd.count key, val.to_f
72
+ when 'set'
73
+ @statsd.set key, val
74
+ when 'increment'
75
+ @statsd.increment key
76
+ when 'decrement'
77
+ @statsd.decrement key
78
+ else
79
+ raise "Invalid statsd type '#{type}'"
80
+ end
81
+ end
82
+
83
+ class RubyStringParser
84
+ def initialize(vars = {})
85
+ @obj = Struct.new(*vars.keys).new(*vars.values)
86
+ end
87
+
88
+ def parse(string)
89
+ return unless string
90
+ string.gsub(/\$\{.+\}/) {|str| @obj.instance_eval str[2..-2] }
91
+ end
92
+ end
93
+ end
94
+ end
data/spec/examples.txt ADDED
@@ -0,0 +1,3 @@
1
+ example_id | status | run_time |
2
+ ------------------------------------- | ------ | --------------- |
3
+ ./spec/plugin/out_statsd_spec.rb[1:1] | passed | 0.53516 seconds |
@@ -0,0 +1,62 @@
1
+ require 'fluent/plugin/out_statsd'
2
+ require 'fluent/test'
3
+
4
+ RSpec.describe Fluent::StatsdOutput do
5
+ let(:config) do
6
+ %{
7
+ type statsd
8
+ namespace a.b.c
9
+
10
+ <metric>
11
+ statsd_type timing
12
+ statsd_key res_time
13
+ statsd_val ${record['response_time']}
14
+ </metric>
15
+
16
+ <metric>
17
+ statsd_type increment
18
+ statsd_key res_code_${record['status'].to_i / 100}xx
19
+ </metric>
20
+ }
21
+ end
22
+ let(:driver) { create_driver(config) }
23
+ let(:statsd) { double('statsd', increment: true, timing: true, 'namespace=' => true) }
24
+ let(:time) { Time.now.utc }
25
+
26
+ before :all do
27
+ Fluent::Test.setup
28
+ end
29
+
30
+ def create_driver(conf)
31
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::StatsdOutput) {
32
+ }.configure(conf)
33
+ end
34
+
35
+ def emit_events(events)
36
+ events.each {|e| driver.emit(e, time) }
37
+ end
38
+
39
+
40
+ it 'should call statsd with events data' do
41
+ allow(Statsd).to receive(:new).and_return(statsd)
42
+
43
+ expect(statsd).to receive(:namespace=).with('a.b.c')
44
+
45
+ expect(statsd).to receive(:increment).with('res_code_2xx').twice.times
46
+ expect(statsd).to receive(:increment).with('res_code_4xx').once.times
47
+ expect(statsd).to receive(:increment).with('res_code_5xx').once.times
48
+ expect(statsd).to receive(:timing).with('res_time', 102).ordered
49
+ expect(statsd).to receive(:timing).with('res_time', 105).ordered
50
+ expect(statsd).to receive(:timing).with('res_time', 112).ordered
51
+ expect(statsd).to receive(:timing).with('res_time', 125).ordered
52
+
53
+ emit_events([
54
+ {'response_time' => 102, 'status' => '200'},
55
+ {'response_time' => 105, 'status' => '200'},
56
+ {'response_time' => 112, 'status' => '400'},
57
+ {'response_time' => 125, 'status' => '500'}
58
+ ])
59
+
60
+ driver.run
61
+ end
62
+ end
@@ -0,0 +1,99 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
+ # have no way to turn it off -- the option exists only for backwards
45
+ # compatibility in RSpec 3). It causes shared context metadata to be
46
+ # inherited by the metadata hash of host groups and examples, rather than
47
+ # triggering implicit auto-inclusion in groups with matching metadata.
48
+ config.shared_context_metadata_behavior = :apply_to_host_groups
49
+
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = 'doc'
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-statsd-output
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Song
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-12 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.10.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
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
+ - !ruby/object:Gem::Dependency
56
+ name: statsd-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: fluentd output filter plugin to send metrics to Esty StatsD
84
+ email: fakechris@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - AUTHORS
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - README.md
95
+ - VERSION
96
+ - fluent-plugin-statsd.gemspec
97
+ - lib/fluent/plugin/out_statsd.rb
98
+ - spec/examples.txt
99
+ - spec/plugin/out_statsd_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/lingochamp/fluent-plugin-statsd
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.5.1
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: fluentd output filter plugin to send metrics to Esty StatsD
124
+ test_files:
125
+ - spec/examples.txt
126
+ - spec/plugin/out_statsd_spec.rb
127
+ - spec/spec_helper.rb