Skip to content

Commit

Permalink
Merge pull request #1 from jalaziz/logstash-2.0
Browse files Browse the repository at this point in the history
Upgrade to Logstash 2.0 API
  • Loading branch information
tdooner authored Jul 18, 2016
2 parents 35bfe89 + b16b3dc commit fa9ffb9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.0.0
- Updates from logstash-output-statsd v2.0.5.
- Upgraded logstash-core dependency to 2.0.
- Upgraded dogstatsd-ruby dependency to 1.6.

# 0.9.0
- First version of logstash-output-dogstatsd, forked from v1.1.0 of
logstash-output-statsd.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Logstash Plugin

This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
This is a plugin for [Logstash](https://github.com/elastic/logstash).

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.

## Documentation

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/).
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.elastic.co/guide/en/logstash/current/).

- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide

## Need Help?

Expand Down Expand Up @@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and

It is more important to the community that you are able to contribute.

For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
43 changes: 27 additions & 16 deletions lib/logstash/outputs/dogstatsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,57 @@ module Datadog
#
# You can learn about statsd here:
#
# * http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/[Etsy blog post announcing statsd]
# * https://codeascraft.com/2011/02/15/measure-anything-measure-everything/[Etsy blog post announcing statsd]
# * https://github.com/etsy/statsd[statsd on github]
#
# A simple example usage of this is to count HTTP hits by response code; to learn
# more about that, check out the ../tutorials/metrics-from-logs[log metrics tutorial]
# Typical examples of how this can be used with Logstash include counting HTTP hits
# by response code, summing the total number of bytes of traffic served, and tracking
# the 50th and 95th percentile of the processing time of requests.
#
# Example:
# [source,ruby]
# output {
# dogstatsd {
# metric_tags => ["host:%{host}","role:foo"]
# count => {
# "http.bytes" => "%{bytes}"
# dogstatsd {
# metric_tags => ["host:%{host}","role:foo"]
# count => {
# "http.bytes" => "%{bytes}"
# }
# }
# }
# }
class LogStash::Outputs::Dogstatsd < LogStash::Outputs::Base
## Regex stolen from statsd code
RESERVED_CHARACTERS_REGEX = /[\:\|\@]/
config_name "dogstatsd"

# The address of the dogstatsd server.
# The hostname or IP address of the dogstatsd server.
config :host, :validate => :string, :default => "localhost"

# The port to connect to on your dogstatsd server.
config :port, :validate => :number, :default => 8125

# An increment metric. Metric names as array.
# An increment metric. Metric names as array. `%{fieldname}` substitutions are
# allowed in the metric names.
config :increment, :validate => :array, :default => []

# A decrement metric. Metric names as array.
# A decrement metric. Metric names as array. `%{fieldname}` substitutions are
# allowed in the metric names.
config :decrement, :validate => :array, :default => []

# A histogram metric, which a statsd timing but conceptually maps to any
# numeric value, not just durations. `metric_name => value` as hash
# numeric value, not just durations. `metric_name => value` as hash. `%{fieldname}`
# substitutions are allowed in the metric names.
config :histogram, :validate => :hash, :default => {}

# A count metric. `metric_name => count` as hash
# A count metric. `metric_name => count` as hash. `%{fieldname}` substitutions are
# allowed in the metric names.
config :count, :validate => :hash, :default => {}

# A set metric. `metric_name => "string"` to append as hash
# A set metric. `metric_name => "string"` to append as hash. `%{fieldname}`
# substitutions are allowed in the metric names.
config :set, :validate => :hash, :default => {}

# A gauge metric. `metric_name => gauge` as hash.
# A gauge metric. `metric_name => gauge` as hash. `%{fieldname}` substitutions are
# allowed in the metric names.
config :gauge, :validate => :hash, :default => {}

# The sample rate for the metric.
Expand All @@ -78,7 +85,6 @@ def register

public
def receive(event)
return unless output?(event)
@logger.debug? and @logger.debug("Event: #{event}")

metric_opts = {
Expand Down Expand Up @@ -110,4 +116,9 @@ def receive(event)
@client.gauge(event.sprintf(metric), event.sprintf(val), metric_opts)
end
end # def receive

public
def close
@client.close
end # def close
end # class LogStash::Outputs::Statsd
9 changes: 4 additions & 5 deletions logstash-output-dogstatsd.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-output-dogstatsd'
s.version = '1.3.0'
s.version = '2.0.0'
s.licenses = ['Apache License (2.0)']
s.summary = "Send metrics to StatsD"
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"
Expand All @@ -11,7 +11,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

# Files
s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
s.files = Dir['lib/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']

# Tests
s.test_files = s.files.grep(%r{^(test|spec|features)/})
Expand All @@ -20,14 +20,13 @@ Gem::Specification.new do |s|
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }

# Gem dependencies
s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
s.add_runtime_dependency 'logstash-input-generator'

# This version is pinned exactly to ensure that upgrades don't break the
# gnarly `module_eval` hack in lib/logstash/outputs/dogstatsd.rb.
s.add_runtime_dependency 'dogstatsd-ruby', '= 1.5'
s.add_runtime_dependency 'dogstatsd-ruby', '= 1.6'

s.add_development_dependency 'logstash-devutils'
s.add_development_dependency 'overcommit'
end

2 changes: 1 addition & 1 deletion spec/outputs/dogstatsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end
let(:metric_config) { {} }

describe 'registration and teardown' do
describe 'registration and close' do
it 'registers without errors' do
output = LogStash::Plugin.lookup('output', 'dogstatsd').new
expect { output.register }.to_not raise_error
Expand Down

0 comments on commit fa9ffb9

Please sign in to comment.