logstash-output-dogstatsd 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cb8720939c32309a703107f259983b53df4207c
4
+ data.tar.gz: 754cac540de40f10618bbadbfa4f0494bc014721
5
+ SHA512:
6
+ metadata.gz: 892f9d95c67a7ecfb8e4ce7529559efa1d622be0f87d3beb3f931a9ec10408c7eedbe419b587b99485027ace7600d371e0dbd43909b3d06a3c55028891551fdc
7
+ data.tar.gz: d2f85fb11a8d0dc3d0639d72e3a89fe3b89c9b66d533c02f8a3a53949612e3165ebf8f30a03dcefdf130680becb22ec25944ba6811d0d438b9ceca225e58dcfa
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
4
+ vendor
data/.overcommit.yml ADDED
@@ -0,0 +1,13 @@
1
+ PreCommit:
2
+ HardTabs:
3
+ enabled: true
4
+
5
+ RuboCop:
6
+ enabled: true
7
+ command: ['bundle', 'exec', 'rubocop']
8
+
9
+ TrailingWhitespace:
10
+ enabled: true
11
+
12
+ # Overcommit will use the repo's Gemfile when loading the Bundler context
13
+ gemfile: Gemfile
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-1.7.20
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 0.9.0
2
+ - First version of logstash-output-dogstatsd, forked from v1.1.0 of
3
+ logstash-output-statsd.
data/CONTRIBUTORS ADDED
@@ -0,0 +1,23 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * David Warden (dfwarden)
6
+ * Graham Bleach (bleach)
7
+ * John E. Vincent (lusis)
8
+ * Jordan Sissel (jordansissel)
9
+ * João Duarte (jsvd)
10
+ * Kurt Hurtado (kurtado)
11
+ * Michael Leinartas (mleinart)
12
+ * Parker DeBardelaben (parkerd)
13
+ * Pere Urbón (purbon)
14
+ * Pete Fritchman (fetep)
15
+ * Pier-Hugues Pellerin (ph)
16
+ * Richard Pijnenburg (electrical)
17
+ * alistar79
18
+ * piavlo
19
+
20
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
21
+ Logstash, and you aren't on the list above and want to be, please let us know
22
+ and we'll make sure you're here. Contributions from folks like you are what make
23
+ open source awesome.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
4
+
5
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
+
7
+ ## Documentation
8
+
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ @files=[]
2
+
3
+ task :default do
4
+ system("rake -T")
5
+ end
6
+
7
+ require "logstash/devutils/rake"
@@ -0,0 +1,119 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+
5
+ # This is a hack to load the dogstatsd-ruby gem's statsd.rb file into a
6
+ # namespace so as to not clobber the top-level Statsd provided by the
7
+ # much-more-popular Statsd gem. The problem is that both gems have a file named
8
+ # 'statsd.rb' that you are supposed to load. Why did Datadog not name their file
9
+ # differently? Who knows!
10
+ # (see: https://github.com/DataDog/dogstatsd-ruby/pull/3)
11
+ module Datadog
12
+ module_eval(File.read(Gem.find_files('**/statsd.rb').grep(/dogstatsd/).first))
13
+ end
14
+
15
+ # dogstatsd is a fork of the statsd protocol which aggregates statistics, such
16
+ # as counters and timers, and ships them over UDP to the dogstatsd-server
17
+ # running as part of the Datadog Agent. Dogstatsd adds support for metric tags,
18
+ # which are used to slice metrics along various dimensions.
19
+ #
20
+ # You can learn about statsd here:
21
+ #
22
+ # * http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/[Etsy blog post announcing statsd]
23
+ # * https://github.com/etsy/statsd[statsd on github]
24
+ #
25
+ # A simple example usage of this is to count HTTP hits by response code; to learn
26
+ # more about that, check out the ../tutorials/metrics-from-logs[log metrics tutorial]
27
+ #
28
+ # Example:
29
+ # [source,ruby]
30
+ # output {
31
+ # dogstatsd {
32
+ # metric_tags => {
33
+ # "host" => "%{host}"
34
+ # }
35
+ # count => {
36
+ # "http.bytes" => "%{bytes}"
37
+ # }
38
+ # }
39
+ # }
40
+ class LogStash::Outputs::Dogstatsd < LogStash::Outputs::Base
41
+ ## Regex stolen from statsd code
42
+ RESERVED_CHARACTERS_REGEX = /[\:\|\@]/
43
+ config_name "dogstatsd"
44
+
45
+ # The address of the dogstatsd server.
46
+ config :host, :validate => :string, :default => "localhost"
47
+
48
+ # The port to connect to on your dogstatsd server.
49
+ config :port, :validate => :number, :default => 8125
50
+
51
+ # An increment metric. Metric names as array.
52
+ config :increment, :validate => :array, :default => []
53
+
54
+ # A decrement metric. Metric names as array.
55
+ config :decrement, :validate => :array, :default => []
56
+
57
+ # A histogram metric, which a statsd timing but conceptually maps to any
58
+ # numeric value, not just durations. `metric_name => value` as hash
59
+ config :histogram, :validate => :hash, :default => {}
60
+
61
+ # A count metric. `metric_name => count` as hash
62
+ config :count, :validate => :hash, :default => {}
63
+
64
+ # A set metric. `metric_name => "string"` to append as hash
65
+ config :set, :validate => :hash, :default => {}
66
+
67
+ # A gauge metric. `metric_name => gauge` as hash.
68
+ config :gauge, :validate => :hash, :default => {}
69
+
70
+ # The sample rate for the metric.
71
+ config :sample_rate, :validate => :number, :default => 1
72
+
73
+ # The tags to apply to each metric.
74
+ config :metric_tags, :validate => :hash, :default => {}
75
+
76
+ public
77
+ def register
78
+ @client = Datadog::Statsd.new(@host, @port)
79
+ end # def register
80
+
81
+ public
82
+ def receive(event)
83
+ return unless output?(event)
84
+ @logger.debug? and @logger.debug("Event: #{event}")
85
+
86
+ tags = process_tags(event, @metric_tags)
87
+ metric_opts = { :sample_rate => @sample_rate, :tags => tags }
88
+
89
+ @increment.each do |metric|
90
+ @client.increment(event.sprintf(metric), metric_opts)
91
+ end
92
+
93
+ @decrement.each do |metric|
94
+ @client.decrement(event.sprintf(metric), metric_opts)
95
+ end
96
+
97
+ @count.each do |metric, val|
98
+ @client.count(event.sprintf(metric), event.sprintf(val), metric_opts)
99
+ end
100
+
101
+ @histogram.each do |metric, val|
102
+ @client.histogram(event.sprintf(metric), event.sprintf(val), metric_opts)
103
+ end
104
+
105
+ @set.each do |metric, val|
106
+ @client.set(event.sprintf(metric), event.sprintf(val), metric_opts)
107
+ end
108
+
109
+ @gauge.each do |metric, val|
110
+ @client.gauge(event.sprintf(metric), event.sprintf(val), metric_opts)
111
+ end
112
+ end # def receive
113
+
114
+ private
115
+ # Returns an array of tags like ["tag1:value1", "tag2:value2"]
116
+ def process_tags(event, tags)
117
+ tags.map { |k, v| event.sprintf(k) + ':' + event.sprintf(v) }
118
+ end
119
+ end # class LogStash::Outputs::Statsd
@@ -0,0 +1,33 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-output-dogstatsd'
4
+ s.version = '1.2.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "Send metrics to StatsD"
7
+ s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
8
+ s.authors = ["Tom Dooner"]
9
+ s.email = 'info@elastic.co'
10
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
15
+
16
+ # Tests
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+
19
+ # Special flag to let us know this is actually a logstash plugin
20
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
24
+ s.add_runtime_dependency 'logstash-input-generator'
25
+
26
+ # This version is pinned exactly to ensure that upgrades don't break the
27
+ # gnarly `module_eval` hack in lib/logstash/outputs/dogstatsd.rb.
28
+ s.add_runtime_dependency 'dogstatsd-ruby', '= 1.5'
29
+
30
+ s.add_development_dependency 'logstash-devutils'
31
+ s.add_development_dependency 'overcommit'
32
+ end
33
+
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ require 'logstash/outputs/dogstatsd'
3
+ require_relative '../spec_helper'
4
+
5
+ describe LogStash::Outputs::Dogstatsd do
6
+ let(:output) { described_class.new(config) }
7
+
8
+ let(:config) do
9
+ {
10
+ 'host' => '127.0.0.1',
11
+ 'port' => 8125
12
+ }.merge(metric_config)
13
+ end
14
+ let(:metric_config) { {} }
15
+
16
+ describe 'registration and teardown' do
17
+ it 'registers without errors' do
18
+ output = LogStash::Plugin.lookup('output', 'dogstatsd').new
19
+ expect { output.register }.to_not raise_error
20
+ end
21
+ end
22
+
23
+ describe '#send' do
24
+ before { output.register }
25
+ subject { output.receive(LogStash::Event.new(event)) }
26
+
27
+ let(:event) { { 'something_count' => 10 } }
28
+
29
+ context 'increment metrics' do
30
+ let(:metric_config) { { 'increment' => [metric_to_track] } }
31
+ let(:metric_to_track) { 'metric.name.here' }
32
+
33
+ context 'with a plain ol metric name' do
34
+ it 'tracks' do
35
+ expect_any_instance_of(Datadog::Statsd).to receive(:send_to_socket)
36
+ .with("#{metric_to_track}:1|c")
37
+ subject
38
+ end
39
+ end
40
+
41
+ context 'with tags' do
42
+ let(:metric_config) { super().merge('metric_tags' => { 'foo' => '%{value}' }) }
43
+ let(:event) { { 'value' => 'helloworld' } }
44
+
45
+ it 'sprintf tags' do
46
+ expect_any_instance_of(Datadog::Statsd).to receive(:send_to_socket)
47
+ .with("#{metric_to_track}:1|c|#foo:helloworld")
48
+ subject
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'histogram metrics' do
54
+ let(:metric_to_track) { 'metric.name.here' }
55
+ let(:metric_config) { { 'histogram' => { '%{metric_name}' => '%{track_value}' } } }
56
+ let(:event) { super().merge('metric_name' => metric_to_track, 'track_value' => 123) }
57
+
58
+ context 'with tags in the metric name and value' do
59
+ it 'tracks' do
60
+ expect_any_instance_of(Datadog::Statsd).to receive(:send_to_socket)
61
+ .with("#{metric_to_track}:123|h")
62
+ subject
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,8 @@
1
+ require 'logstash/devutils/rspec/spec_helper'
2
+ require 'logstash/outputs/dogstatsd'
3
+
4
+ RSpec.configure do |c|
5
+ c.before do
6
+ allow_any_instance_of(Datadog::Statsd).to receive(:send_to_socket)
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-dogstatsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Dooner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ - - <
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-input-generator
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: dogstatsd-ruby
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: '1.5'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '='
57
+ - !ruby/object:Gem::Version
58
+ version: '1.5'
59
+ prerelease: false
60
+ type: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-devutils
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ prerelease: false
74
+ type: :development
75
+ - !ruby/object:Gem::Dependency
76
+ name: overcommit
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ prerelease: false
88
+ type: :development
89
+ description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
90
+ email: info@elastic.co
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - .gitignore
96
+ - .overcommit.yml
97
+ - .ruby-version
98
+ - CHANGELOG.md
99
+ - CONTRIBUTORS
100
+ - Gemfile
101
+ - LICENSE
102
+ - NOTICE.TXT
103
+ - README.md
104
+ - Rakefile
105
+ - lib/logstash/outputs/dogstatsd.rb
106
+ - logstash-output-dogstatsd.gemspec
107
+ - spec/outputs/dogstatsd_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
110
+ licenses:
111
+ - Apache License (2.0)
112
+ metadata:
113
+ logstash_plugin: 'true'
114
+ logstash_group: output
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.6
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Send metrics to StatsD
135
+ test_files:
136
+ - spec/outputs/dogstatsd_spec.rb
137
+ - spec/spec_helper.rb