fluent-plugin-datadog 0.9.2.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +41 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +69 -0
- data/Rakefile +1 -0
- data/fluent-plugin-datadog.gemspec +22 -0
- data/lib/fluent/plugin/out_datadog.rb +151 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b93c02f502b84f29f21972b23951089eac51b38a
|
4
|
+
data.tar.gz: 7dd0ef40fb8ac4d90ff724a3b91c081a4fb443dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6e9aa3bca5010c1b2bbc347450174359d79710754a2175c45cc3c17094ab6651ffe256f310e0c63ef60824d4ae75e2cfde2f4369f26d87dfb1d9a61590b1024
|
7
|
+
data.tar.gz: 4921013a7da5cd1ab3400d920fe8b51dee1b8b58f1063c0ba7a060add48d67b9603583de8585908a38543e71b13fa56dfd96a093396bf3f4c0bb8b89e56f8132
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
37
|
+
|
38
|
+
# Misc
|
39
|
+
foo/
|
40
|
+
*.iml
|
41
|
+
.idea/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Datadog
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Fluentd output plugin for Datadog
|
2
|
+
|
3
|
+
It mainly contains a proper JSON formatter and a socket handler that
|
4
|
+
streams logs directly to Datadog - so no need to use a log shipper
|
5
|
+
if you don't wan't to.
|
6
|
+
|
7
|
+
## Pre-requirements
|
8
|
+
|
9
|
+
To add the plugin to your fluentd agent, use the following command:
|
10
|
+
|
11
|
+
gem install fluent-plugin-datadog
|
12
|
+
|
13
|
+
If you installed the td-agent instead
|
14
|
+
|
15
|
+
/usr/sbin/td-agent-gem install fluent-plugin-datadog
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
### Configure the output plugin
|
19
|
+
|
20
|
+
To match events and send them to Datadog, simply add the following code to your configuration file.
|
21
|
+
|
22
|
+
TCP example
|
23
|
+
```xml
|
24
|
+
# Match events tagged with "datadog.**" and
|
25
|
+
# send them to Datadog
|
26
|
+
<match datadog.**>
|
27
|
+
|
28
|
+
@type datadog
|
29
|
+
@id awesome_agent
|
30
|
+
api_key <your_api_key>
|
31
|
+
|
32
|
+
# Optional
|
33
|
+
include_tag_key true
|
34
|
+
tag_key 'tag'
|
35
|
+
|
36
|
+
</match>
|
37
|
+
```
|
38
|
+
|
39
|
+
After a restart of FluentD, any child events tagged with `datadog` are shipped to your platform.
|
40
|
+
|
41
|
+
### Validation
|
42
|
+
Let's make a simple test.
|
43
|
+
|
44
|
+
```bash
|
45
|
+
curl -X POST -d 'json={"message":"hello Datadog from fluentd"}' http://localhost:8888/datadog.test
|
46
|
+
```
|
47
|
+
|
48
|
+
Produces the following event:
|
49
|
+
|
50
|
+
```javascript
|
51
|
+
{
|
52
|
+
"message": "hello Datadog from fluentd"
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
### fluent-plugin-datadog properties
|
57
|
+
Let's go deeper on the plugin configuration.
|
58
|
+
|
59
|
+
As fluent-plugin-datadog is an output_buffer, you can set all output_buffer properties like it's describe in the [fluentd documentation](http://docs.fluentd.org/articles/output-plugin-overview#buffered-output-parameters "documentation").
|
60
|
+
|
61
|
+
|
62
|
+
| Property | Description | Default value |
|
63
|
+
|-------------|--------------------------------------------------------------------------|----------------|
|
64
|
+
| **api_key** | This parameter is required in order to authenticate your fluent agent. | nil |
|
65
|
+
| **use_json**| Event format, if true, the event is sent in json format. Othwerwise, in plain text. | true |
|
66
|
+
| **include_tag_key**| Automatically include tags in the record. | false |
|
67
|
+
| **tag_key**| Name of the tag attribute, if they are included. | "tag" |
|
68
|
+
| **use_ssl** | If true, the agent initializes a secure connection to Datadog. In clear TCP otherwise. | true |
|
69
|
+
|**max_retries**| The number of retries before the output plugin stops. Set to -1 for unlimited retries | -1 |
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fluent-plugin-datadog"
|
7
|
+
spec.version = "0.9.2.beta"
|
8
|
+
spec.authors = ["Datadog support team"]
|
9
|
+
spec.email = ["support@datadoghq.com"]
|
10
|
+
spec.summary = "Datadog output plugin for Fluent event collector"
|
11
|
+
spec.homepage = "http://datadoghq.com"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = [".gitignore", "Gemfile", "LICENSE", "README.md", "Rakefile", "fluent-plugin-datadog.gemspec", "lib/fluent/plugin/out_datadog.rb"]
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "yajl-ruby", "~> 1.2"
|
22
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'openssl'
|
3
|
+
require 'yajl'
|
4
|
+
|
5
|
+
class Fluent::DatadogOutput < Fluent::BufferedOutput
|
6
|
+
class ConnectionFailure < StandardError; end
|
7
|
+
|
8
|
+
# Register the plugin
|
9
|
+
Fluent::Plugin.register_output('datadog', self)
|
10
|
+
# Output settings
|
11
|
+
config_param :use_json, :bool, :default => true
|
12
|
+
config_param :include_tag_key,:bool, :default => false
|
13
|
+
config_param :tag_key, :string, :default => 'tag'
|
14
|
+
|
15
|
+
# Connection settings
|
16
|
+
config_param :host, :string, :default => 'intake.logs.datadoghq.com'
|
17
|
+
config_param :use_ssl, :bool, :default => false
|
18
|
+
config_param :port, :integer, :default => 10514
|
19
|
+
config_param :ssl_port, :integer, :default => 10516
|
20
|
+
config_param :max_retries, :integer, :default => -1
|
21
|
+
config_param :tcp_ping_rate, :integer, :default => 10
|
22
|
+
|
23
|
+
# API Settings
|
24
|
+
config_param :api_key, :string
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
# Define `log` method for v0.10.42 or earlier
|
31
|
+
unless method_defined?(:log)
|
32
|
+
define_method("log") { $log }
|
33
|
+
end
|
34
|
+
|
35
|
+
def configure(conf)
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
def client
|
40
|
+
@_socket ||= if @use_ssl
|
41
|
+
context = OpenSSL::SSL::SSLContext.new
|
42
|
+
socket = TCPSocket.new @host, @ssl_port
|
43
|
+
ssl_client = OpenSSL::SSL::SSLSocket.new socket, context
|
44
|
+
ssl_client.connect
|
45
|
+
else
|
46
|
+
socket = TCPSocket.new @host, @port
|
47
|
+
end
|
48
|
+
|
49
|
+
return @_socket
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
#not used for now...
|
54
|
+
def init_socket(socket)
|
55
|
+
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
|
56
|
+
|
57
|
+
begin
|
58
|
+
socket.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPINTVL, 3)
|
59
|
+
socket.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPCNT, 3)
|
60
|
+
socket.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPIDLE, 10)
|
61
|
+
rescue
|
62
|
+
log.info "DatadogOutput: Fallback on socket options during initialization"
|
63
|
+
end
|
64
|
+
|
65
|
+
return socket
|
66
|
+
end
|
67
|
+
|
68
|
+
def start
|
69
|
+
super
|
70
|
+
@my_mutex = Mutex.new
|
71
|
+
@running = true
|
72
|
+
|
73
|
+
if @tcp_ping_rate > 0
|
74
|
+
@timer = Thread.new do
|
75
|
+
while @running do
|
76
|
+
messages = Array.new
|
77
|
+
messages.push("fp\n")
|
78
|
+
send_to_datadog(messages)
|
79
|
+
sleep(15)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def shutdown
|
87
|
+
super
|
88
|
+
@running = false
|
89
|
+
if @_socket
|
90
|
+
@_socket.close()
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# This method is called when an event reaches Fluentd.
|
95
|
+
def format(tag, time, record)
|
96
|
+
return [tag, record].to_msgpack
|
97
|
+
end
|
98
|
+
|
99
|
+
# NOTE! This method is called by internal thread, not Fluentd's main thread.
|
100
|
+
# 'chunk' is a buffer chunk that includes multiple formatted events.
|
101
|
+
def write(chunk)
|
102
|
+
messages = Array.new
|
103
|
+
chunk.msgpack_each do |tag, record|
|
104
|
+
next unless record.is_a? Hash
|
105
|
+
next unless record.has_key? "message"
|
106
|
+
|
107
|
+
if @include_tag_key
|
108
|
+
record[@tag_key] = tag
|
109
|
+
end
|
110
|
+
if @use_json
|
111
|
+
messages.push "#{api_key} " + Yajl.dump(record) + "\n"
|
112
|
+
else
|
113
|
+
messages.push "#{api_key} " + record["message"].rstrip() + "\n"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
send_to_datadog(messages)
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
def send_to_datadog(data)
|
121
|
+
@my_mutex.synchronize do
|
122
|
+
retries = 0
|
123
|
+
begin
|
124
|
+
log.trace "Send nb_event=#{data.size} events to Datadog"
|
125
|
+
|
126
|
+
# Check the connectivity and write messages
|
127
|
+
log.info "New attempt to Datadog attempt=#{retries}" if retries > 0
|
128
|
+
|
129
|
+
retries = retries + 1
|
130
|
+
data.each do |event|
|
131
|
+
client.write(event)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Handle some failures
|
135
|
+
rescue Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::EPIPE => e
|
136
|
+
|
137
|
+
if retries < @max_retries || max_retries == -1
|
138
|
+
@_socket = nil
|
139
|
+
a_couple_of_seconds = retries ** 2
|
140
|
+
a_couple_of_seconds = 30 unless a_couple_of_seconds < 30
|
141
|
+
retries += 1
|
142
|
+
log.warn "Could not push logs to Datadog, attempt=#{retries} max_attempts=#{max_retries} wait=#{a_couple_of_seconds}s error=#{e.message}"
|
143
|
+
sleep a_couple_of_seconds
|
144
|
+
retry
|
145
|
+
end
|
146
|
+
raise ConnectionFailure, "Could not push logs to Datadog after #{retries} retries, #{e.message}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-datadog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Datadog support team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: yajl-ruby
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- support@datadoghq.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- fluent-plugin-datadog.gemspec
|
68
|
+
- lib/fluent/plugin/out_datadog.rb
|
69
|
+
homepage: http://datadoghq.com
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.3.1
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.6.13
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Datadog output plugin for Fluent event collector
|
93
|
+
test_files: []
|