logstash-output-datadog_metrics 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTORS +1 -0
- data/NOTICE.TXT +5 -0
- data/README.md +5 -5
- data/lib/logstash/outputs/datadog_metrics.rb +15 -19
- data/logstash-output-datadog_metrics.gemspec +2 -1
- data/spec/outputs/datadog_metrics_spec.rb +85 -0
- metadata +26 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2fff9b69ded858abede9d1a806c1d452468070f
|
4
|
+
data.tar.gz: 6c8f8901fd704553ff0d71ba9edde9e33aaa23e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a36d244ccff5ec85ce4961b874d96e2572f13443f922365e9852bc73246c67b6ce48db1f22db14ce2fa1e7190c77a74eee25de2385a373159ba6b13cf3e4449
|
7
|
+
data.tar.gz: 760bf4fa251879d738f1fb39020f36eb4024cfcbb6ef9de7f53f291ed446c944997a76bc297c4923d14134504a5f4e1cb6fa63439fb4a413ba60ffda8234dca6
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTORS
CHANGED
@@ -10,6 +10,7 @@ Contributors:
|
|
10
10
|
* Kurt Hurtado (kurtado)
|
11
11
|
* Pier-Hugues Pellerin (ph)
|
12
12
|
* Richard Pijnenburg (electrical)
|
13
|
+
* Guy Boertje (guyboertje)
|
13
14
|
|
14
15
|
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
15
16
|
Logstash, and you aren't on the list above and want to be, please let us know
|
data/NOTICE.TXT
ADDED
data/README.md
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# Logstash Plugin
|
2
2
|
|
3
|
-
This is a plugin for [Logstash](https://github.com/
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
4
|
|
5
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
6
|
|
7
7
|
## Documentation
|
8
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.
|
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.elastic.co/guide/en/logstash/current/).
|
10
10
|
|
11
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/
|
12
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
13
13
|
|
14
14
|
## Need Help?
|
15
15
|
|
16
|
-
Need help? Try #logstash on freenode IRC or the logstash
|
16
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
17
17
|
|
18
18
|
## Developing
|
19
19
|
|
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
|
|
83
83
|
|
84
84
|
It is more important to the community that you are able to contribute.
|
85
85
|
|
86
|
-
For more information about contributing, see the [CONTRIBUTING](https://github.com/
|
86
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "logstash/outputs/base"
|
3
3
|
require "logstash/namespace"
|
4
|
+
require "logstash/json"
|
4
5
|
require "stud/buffer"
|
5
6
|
|
6
7
|
|
@@ -9,8 +10,7 @@ require "stud/buffer"
|
|
9
10
|
|
10
11
|
# Default `queue_size` and `timeframe` are low in order to provide near realtime alerting.
|
11
12
|
# If you do not use Datadog for alerting, consider raising these thresholds.
|
12
|
-
|
13
|
-
class LogStash::Outputs::DatadogMetrics < LogStash::Outputs::Base
|
13
|
+
module LogStash module Outputs class DatadogMetrics < LogStash::Outputs::Base
|
14
14
|
|
15
15
|
include Stud::Buffer
|
16
16
|
|
@@ -46,8 +46,8 @@ class LogStash::Outputs::DatadogMetrics < LogStash::Outputs::Base
|
|
46
46
|
config :timeframe, :validate => :number, :default => 10
|
47
47
|
|
48
48
|
public
|
49
|
+
|
49
50
|
def register
|
50
|
-
require 'time'
|
51
51
|
require "net/https"
|
52
52
|
require "uri"
|
53
53
|
|
@@ -64,7 +64,7 @@ class LogStash::Outputs::DatadogMetrics < LogStash::Outputs::Base
|
|
64
64
|
)
|
65
65
|
end # def register
|
66
66
|
|
67
|
-
public
|
67
|
+
# public
|
68
68
|
def receive(event)
|
69
69
|
return unless output?(event)
|
70
70
|
return unless @metric_name && @metric_value && @metric_type
|
@@ -88,24 +88,15 @@ class LogStash::Outputs::DatadogMetrics < LogStash::Outputs::Base
|
|
88
88
|
buffer_receive(dd_metrics)
|
89
89
|
end # def receive
|
90
90
|
|
91
|
-
public
|
91
|
+
# public
|
92
92
|
def flush(events, final=false)
|
93
93
|
dd_series = Hash.new
|
94
|
-
dd_series['series'] =
|
95
|
-
|
96
|
-
events.each do |event|
|
97
|
-
begin
|
98
|
-
dd_series['series'] << event
|
99
|
-
rescue
|
100
|
-
@logger.warn("Error adding event to series!", :exception => e)
|
101
|
-
next
|
102
|
-
end
|
103
|
-
end
|
94
|
+
dd_series['series'] = Array(events).flatten
|
104
95
|
|
105
96
|
request = Net::HTTP::Post.new("#{@uri.path}?api_key=#{@api_key}")
|
106
97
|
|
107
98
|
begin
|
108
|
-
request.body = dd_series
|
99
|
+
request.body = series_to_json(dd_series)
|
109
100
|
request.add_field("Content-Type", 'application/json')
|
110
101
|
response = @client.request(request)
|
111
102
|
@logger.info("DD convo", :request => request.inspect, :response => response.inspect)
|
@@ -116,8 +107,13 @@ class LogStash::Outputs::DatadogMetrics < LogStash::Outputs::Base
|
|
116
107
|
end # def flush
|
117
108
|
|
118
109
|
private
|
110
|
+
|
111
|
+
def series_to_json(series)
|
112
|
+
LogStash::Json.dump(series)
|
113
|
+
end
|
114
|
+
|
119
115
|
def to_epoch(t)
|
120
|
-
|
121
|
-
end
|
116
|
+
Integer(t.is_a?(String) ? Time.parse(t) : t)
|
117
|
+
end
|
122
118
|
|
123
|
-
end # class LogStash::Outputs::DatadogMetrics
|
119
|
+
end end end # class LogStash::Outputs::DatadogMetrics
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-output-datadog_metrics'
|
4
|
-
s.version = '0.1.
|
4
|
+
s.version = '0.1.5'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "This output lets you send metrics to DataDogHQ based on Logstash events."
|
7
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"
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
# Gem dependencies
|
23
23
|
s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
|
24
|
+
s.add_runtime_dependency "logstash-codec-plain", '>= 1.0.0'
|
24
25
|
|
25
26
|
s.add_development_dependency 'logstash-devutils'
|
26
27
|
end
|
@@ -1 +1,86 @@
|
|
1
1
|
require "logstash/devutils/rspec/spec_helper"
|
2
|
+
require "logstash/outputs/datadog_metrics"
|
3
|
+
|
4
|
+
describe LogStash::Outputs::DatadogMetrics do
|
5
|
+
let(:http_instance) { double('net_http_instance') }
|
6
|
+
let(:request) { double('net_http_request') }
|
7
|
+
let(:response) { double('net_http_response') }
|
8
|
+
|
9
|
+
let(:json_obj) { double('json_obj') }
|
10
|
+
let(:logger) { double('logger') }
|
11
|
+
let(:ddtags) { ['foo', 'bar'] }
|
12
|
+
let(:event_hash) do
|
13
|
+
{
|
14
|
+
'message' => 'Hello world!',
|
15
|
+
'source' => 'datadog-metrics',
|
16
|
+
'type' => 'generator',
|
17
|
+
'host' => 'localhost',
|
18
|
+
'@timestamp' => LogStash::Timestamp.now
|
19
|
+
}
|
20
|
+
end
|
21
|
+
let(:event) { LogStash::Event.new(event_hash) }
|
22
|
+
let(:params) do
|
23
|
+
{
|
24
|
+
'api_key' => '123456789',
|
25
|
+
'dd_tags' => ddtags,
|
26
|
+
'metric_type' => 'gauge'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
allow(Net::HTTP).to receive(:new).and_return(http_instance)
|
32
|
+
allow(Net::HTTP::Post).to receive(:new).and_return(request)
|
33
|
+
end
|
34
|
+
|
35
|
+
subject { described_class.new(params) }
|
36
|
+
|
37
|
+
context 'construction' do
|
38
|
+
it 'register method calls collaborator methods' do
|
39
|
+
expect(http_instance).to receive(:use_ssl=)
|
40
|
+
expect(http_instance).to receive(:verify_mode=)
|
41
|
+
subject.register
|
42
|
+
buffer = subject.instance_variable_get(:@buffer_config)
|
43
|
+
expect(buffer[:max_items]).to be 10
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'runtime' do
|
48
|
+
before do
|
49
|
+
allow(http_instance).to receive(:use_ssl=)
|
50
|
+
allow(http_instance).to receive(:verify_mode=)
|
51
|
+
subject.register
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'receiving an event' do
|
55
|
+
it 'receives' do
|
56
|
+
subject.receive(event)
|
57
|
+
buffer = subject.instance_variable_get(:@buffer_state)
|
58
|
+
expect(buffer[:pending_items].inspect).to match(/"tags"=>\["foo", "bar"\]/)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'flushing multiple events' do
|
63
|
+
before do
|
64
|
+
series_hash = {'series' => Array(event)}
|
65
|
+
subject.instance_variable_set(:@logger, logger)
|
66
|
+
expect(LogStash::Json).to receive(:dump).with(series_hash).and_return('---')
|
67
|
+
expect(request).to receive(:body=)
|
68
|
+
expect(request).to receive(:add_field)
|
69
|
+
expect(logger).to receive(:info).at_least(:once)
|
70
|
+
expect(logger).not_to receive(:warn)
|
71
|
+
expect(http_instance).to receive(:request).with(request).and_return(response)
|
72
|
+
|
73
|
+
expect(response).to receive(:code).and_return('202')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'flushes final=false [final is unused]' do
|
77
|
+
expect{subject.flush([event], false)}.not_to raise_error
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'flushes final=true [final is unused]' do
|
81
|
+
expect{subject.flush([event], true)}.not_to raise_error
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-datadog_metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
|
14
|
+
name: logstash-core
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - '>='
|
17
18
|
- !ruby/object:Gem::Version
|
@@ -19,10 +20,7 @@ dependencies:
|
|
19
20
|
- - <
|
20
21
|
- !ruby/object:Gem::Version
|
21
22
|
version: 2.0.0
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
type: :runtime
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
25
|
- - '>='
|
28
26
|
- !ruby/object:Gem::Version
|
@@ -30,20 +28,36 @@ dependencies:
|
|
30
28
|
- - <
|
31
29
|
- !ruby/object:Gem::Version
|
32
30
|
version: 2.0.0
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-codec-plain
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.0.0
|
34
40
|
requirement: !ruby/object:Gem::Requirement
|
35
41
|
requirements:
|
36
42
|
- - '>='
|
37
43
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
39
|
-
name: logstash-devutils
|
44
|
+
version: 1.0.0
|
40
45
|
prerelease: false
|
41
|
-
type: :
|
46
|
+
type: :runtime
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: logstash-devutils
|
42
49
|
version_requirements: !ruby/object:Gem::Requirement
|
43
50
|
requirements:
|
44
51
|
- - '>='
|
45
52
|
- !ruby/object:Gem::Version
|
46
53
|
version: '0'
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
prerelease: false
|
60
|
+
type: :development
|
47
61
|
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
|
48
62
|
email: info@elastic.co
|
49
63
|
executables: []
|
@@ -51,9 +65,11 @@ extensions: []
|
|
51
65
|
extra_rdoc_files: []
|
52
66
|
files:
|
53
67
|
- .gitignore
|
68
|
+
- CHANGELOG.md
|
54
69
|
- CONTRIBUTORS
|
55
70
|
- Gemfile
|
56
71
|
- LICENSE
|
72
|
+
- NOTICE.TXT
|
57
73
|
- README.md
|
58
74
|
- Rakefile
|
59
75
|
- lib/logstash/outputs/datadog_metrics.rb
|