fluent-plugin-datadog-np 0.10.6.1
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 +7 -0
- data/.gitignore +44 -0
- data/Gemfile +9 -0
- data/LICENSE +201 -0
- data/README.md +104 -0
- data/Rakefile +6 -0
- data/fluent-plugin-datadog-np.gemspec +27 -0
- data/lib/fluent/plugin/out_datadog.rb +234 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec2f0897dd5cbb3ed086b2b692f3006142ada6c3
|
4
|
+
data.tar.gz: e90015e42862cead8f579f12864bb577255b950e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73427f5d993c69e0642137dbcbf6ed7aede2fa23d9f975642552adfa77978ef6c43b744c3713247cd465dd72e39adbb5c94df4c202d9fe553a6a60f412b4fa58
|
7
|
+
data.tar.gz: adfb2df05078ce2631fef5dd0e06a91b91e292e41dd3f8ae3ae428f75d71da723fd6e34ad8fdff62035175bbfd72d8622005f47bfa3fa93af98c33acda85c4c0
|
data/.gitignore
ADDED
@@ -0,0 +1,44 @@
|
|
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/
|
42
|
+
|
43
|
+
fluent/
|
44
|
+
Gemfile.lock
|
data/Gemfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Unless explicitly stated otherwise all files in this repository are licensed
|
2
|
+
# under the Apache License Version 2.0.
|
3
|
+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
|
4
|
+
# Copyright 2018 Datadog, Inc.
|
5
|
+
|
6
|
+
source 'https://rubygems.org'
|
7
|
+
|
8
|
+
# Specify your gem's dependencies in fluent-plugin-datadog.gemspec
|
9
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright 2018 Datadog, Inc.
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
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
|
+
|
24
|
+
```xml
|
25
|
+
# Match events tagged with "datadog.**" and
|
26
|
+
# send them to Datadog
|
27
|
+
<match datadog.**>
|
28
|
+
|
29
|
+
@type datadog
|
30
|
+
@id awesome_agent
|
31
|
+
api_key <your_api_key>
|
32
|
+
|
33
|
+
# Optional
|
34
|
+
include_tag_key true
|
35
|
+
tag_key 'tag'
|
36
|
+
|
37
|
+
# Optional parameters
|
38
|
+
dd_source '<INTEGRATION_NAME>'
|
39
|
+
dd_tags '<KEY1:VALU1>,<KEY2:VALUE2>'
|
40
|
+
dd_sourcecategory '<MY_SOURCE_CATEGORY>'
|
41
|
+
|
42
|
+
</match>
|
43
|
+
```
|
44
|
+
|
45
|
+
After a restart of FluentD, any child events tagged with `datadog` are shipped to your platform.
|
46
|
+
|
47
|
+
### Validation
|
48
|
+
Let's make a simple test.
|
49
|
+
|
50
|
+
```bash
|
51
|
+
curl -X POST -d 'json={"message":"hello Datadog from fluentd"}' http://localhost:8888/datadog.test
|
52
|
+
```
|
53
|
+
|
54
|
+
Produces the following event:
|
55
|
+
|
56
|
+
```javascript
|
57
|
+
{
|
58
|
+
"message": "hello Datadog from fluentd"
|
59
|
+
}
|
60
|
+
```
|
61
|
+
|
62
|
+
### fluent-plugin-datadog properties
|
63
|
+
Let's go deeper on the plugin configuration.
|
64
|
+
|
65
|
+
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").
|
66
|
+
|
67
|
+
| Property | Description | Default value |
|
68
|
+
|-------------|--------------------------------------------------------------------------|----------------|
|
69
|
+
| **api_key** | This parameter is required in order to authenticate your fluent agent. | nil |
|
70
|
+
| **use_json** | Event format, if true, the event is sent in json format. Othwerwise, in plain text. | true |
|
71
|
+
| **include_tag_key** | Automatically include tags in the record. | false |
|
72
|
+
| **tag_key** | Name of the tag attribute, if they are included. | "tag" |
|
73
|
+
| **timestamp_key** | Name of the attribute which will contain timestamp of the log event. If nil, timestamp attribute is not added. | "@timestamp" |
|
74
|
+
| **use_ssl** | If true, the agent initializes a secure connection to Datadog. In clear TCP otherwise. | true |
|
75
|
+
| **ssl_port** | Port used to send logs over a SSL encripted connection to Datadog (use 443 for the EU region) | 10516 |
|
76
|
+
| **max_retries** | The number of retries before the output plugin stops. Set to -1 for unlimited retries | -1 |
|
77
|
+
| **dd_source** | This tells Datadog what integration it is | nil |
|
78
|
+
| **dd_sourcecategory** | Multiple value attribute. Can be used to refine the source attribtue | nil |
|
79
|
+
| **dd_tags** | Custom tags with the following format "key1:value1, key2:value2" | nil |
|
80
|
+
| **port** | Proxy port when logs are not directly forwarded to Datadog and ssl is not used | 10514 |
|
81
|
+
| **host** | Proxy endpoint when logs are not directly forwarded to Datadog | intake.logs.datadoghq.com |
|
82
|
+
|
83
|
+
### Docker and Kubernetes tags
|
84
|
+
|
85
|
+
Tags in Datadog are critical to be able to jump from one part of the product to the other. Having the right metadata associated to your logs is therefore important to jump from the container view or any container metrics to the most related logs.
|
86
|
+
|
87
|
+
If your logs contain any of the following attributes, it will automatically be added as Datadog tags (with the same name as on your metrics) on your logs:
|
88
|
+
|
89
|
+
* kubernetes.container_image
|
90
|
+
* kubernetes.container_name
|
91
|
+
* kubernetes.namespace_name
|
92
|
+
* kubernetes.pod_name
|
93
|
+
* docker.container_id
|
94
|
+
|
95
|
+
If the Datadog Agent collect them automatically, FluentD requires a plugin for this. We recommend using [fluent-plugin-kubernetes_metadata_filter](https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter) to collect Docker and Kubernetes metadata.
|
96
|
+
|
97
|
+
Configuration example:
|
98
|
+
|
99
|
+
```
|
100
|
+
# Collect metadata for logs tagged with "kubernetes.**"
|
101
|
+
<filter kubernetes.*>
|
102
|
+
type kubernetes_metadata
|
103
|
+
</filter>
|
104
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# Unless explicitly stated otherwise all files in this repository are licensed
|
2
|
+
# under the Apache License Version 2.0.
|
3
|
+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
|
4
|
+
# Copyright 2018 Datadog, Inc.
|
5
|
+
|
6
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Unless explicitly stated otherwise all files in this repository are licensed
|
2
|
+
# under the Apache License Version 2.0.
|
3
|
+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
|
4
|
+
# Copyright 2018 Datadog, Inc.
|
5
|
+
|
6
|
+
# coding: utf-8
|
7
|
+
lib = File.expand_path('../lib', __FILE__)
|
8
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
9
|
+
|
10
|
+
Gem::Specification.new do |spec|
|
11
|
+
spec.name = "fluent-plugin-datadog-np"
|
12
|
+
spec.version = "0.10.6.1"
|
13
|
+
spec.authors = ["Nicolas parfait"]
|
14
|
+
spec.email = [""]
|
15
|
+
spec.summary = "Datadog output plugin for Fluent event collector"
|
16
|
+
spec.homepage = "http://datadoghq.com"
|
17
|
+
spec.license = "Apache License 2.0"
|
18
|
+
|
19
|
+
spec.files = [".gitignore", "Gemfile", "LICENSE", "README.md", "Rakefile", "fluent-plugin-datadog-np.gemspec", "lib/fluent/plugin/out_datadog.rb"]
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "yajl-ruby", "~> 1.2"
|
27
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
# Unless explicitly stated otherwise all files in this repository are licensed
|
2
|
+
# under the Apache License Version 2.0.
|
3
|
+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
|
4
|
+
# Copyright 2018 Datadog, Inc.
|
5
|
+
|
6
|
+
require 'socket'
|
7
|
+
require 'openssl'
|
8
|
+
require 'yajl'
|
9
|
+
|
10
|
+
class Fluent::DatadogOutput < Fluent::BufferedOutput
|
11
|
+
class ConnectionFailure < StandardError; end
|
12
|
+
|
13
|
+
# Register the plugin
|
14
|
+
Fluent::Plugin.register_output('datadog', self)
|
15
|
+
# Output settings
|
16
|
+
config_param :use_json, :bool, :default => true
|
17
|
+
config_param :include_tag_key, :bool, :default => false
|
18
|
+
config_param :tag_key, :string, :default => 'tag'
|
19
|
+
config_param :timestamp_key, :string, :default => '@timestamp'
|
20
|
+
config_param :dd_sourcecategory, :string, :default => nil
|
21
|
+
config_param :dd_source, :string, :default => nil
|
22
|
+
config_param :dd_tags, :string, :default => nil
|
23
|
+
config_param :dd_attribute_tags, :string, :default => nil
|
24
|
+
|
25
|
+
# Connection settings
|
26
|
+
config_param :host, :string, :default => 'intake.logs.datadoghq.com'
|
27
|
+
config_param :use_ssl, :bool, :default => true
|
28
|
+
config_param :port, :integer, :default => 10514
|
29
|
+
config_param :ssl_port, :integer, :default => 10516
|
30
|
+
config_param :max_retries, :integer, :default => -1
|
31
|
+
config_param :tcp_ping_rate, :integer, :default => 10
|
32
|
+
|
33
|
+
# API Settings
|
34
|
+
config_param :api_key, :string
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
# Define `log` method for v0.10.42 or earlier
|
41
|
+
unless method_defined?(:log)
|
42
|
+
define_method("log") { $log }
|
43
|
+
end
|
44
|
+
|
45
|
+
def configure(conf)
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
def multi_workers_ready?
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def new_client
|
54
|
+
if @use_ssl
|
55
|
+
context = OpenSSL::SSL::SSLContext.new
|
56
|
+
socket = TCPSocket.new @host, @ssl_port
|
57
|
+
ssl_client = OpenSSL::SSL::SSLSocket.new socket, context
|
58
|
+
ssl_client.connect
|
59
|
+
return ssl_client
|
60
|
+
else
|
61
|
+
return TCPSocket.new @host, @port
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def start
|
66
|
+
super
|
67
|
+
@my_mutex = Mutex.new
|
68
|
+
@running = true
|
69
|
+
|
70
|
+
if @tcp_ping_rate > 0
|
71
|
+
@timer = Thread.new do
|
72
|
+
while @running do
|
73
|
+
messages = Array.new
|
74
|
+
messages.push("fp\n")
|
75
|
+
send_to_datadog(messages)
|
76
|
+
sleep(@tcp_ping_rate)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def shutdown
|
83
|
+
super
|
84
|
+
@running = false
|
85
|
+
if @client
|
86
|
+
@client.close
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# This method is called when an event reaches Fluentd.
|
91
|
+
def format(tag, time, record)
|
92
|
+
# When Fluent::EventTime is msgpack'ed it gets converted to int with seconds
|
93
|
+
# precision only. We explicitly convert it to floating point number, which
|
94
|
+
# is compatible with Time.at below.
|
95
|
+
return [tag, time.to_f, record].to_msgpack
|
96
|
+
end
|
97
|
+
|
98
|
+
# NOTE! This method is called by internal thread, not Fluentd's main thread.
|
99
|
+
# 'chunk' is a buffer chunk that includes multiple formatted events.
|
100
|
+
def write(chunk)
|
101
|
+
messages = Array.new
|
102
|
+
|
103
|
+
chunk.msgpack_each do |tag, time, record|
|
104
|
+
next unless record.is_a? Hash
|
105
|
+
next if record.empty?
|
106
|
+
|
107
|
+
if @dd_sourcecategory
|
108
|
+
record["ddsourcecategory"] = @dd_sourcecategory
|
109
|
+
end
|
110
|
+
if @dd_source
|
111
|
+
record["ddsource"] = @dd_source
|
112
|
+
end
|
113
|
+
if @dd_tags
|
114
|
+
record["ddtags"] = @dd_tags
|
115
|
+
end
|
116
|
+
|
117
|
+
if @include_tag_key
|
118
|
+
record[@tag_key] = tag
|
119
|
+
end
|
120
|
+
# If @timestamp_key already exists, we don't overwrite it.
|
121
|
+
if @timestamp_key and record[@timestamp_key].nil? and time
|
122
|
+
record[@timestamp_key] = Time.at(time).utc.iso8601(3)
|
123
|
+
end
|
124
|
+
|
125
|
+
attribute_tags = get_attribute_tags(record, @dd_attribute_tags)
|
126
|
+
if not attribute_tags.empty?
|
127
|
+
if record["ddtags"].nil? || record["ddtags"].empty?
|
128
|
+
record["ddtags"] = attribute_tags
|
129
|
+
else
|
130
|
+
record["ddtags"] = record["ddtags"] + "," + attribute_tags
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
container_tags = get_container_tags(record)
|
135
|
+
if not container_tags.empty?
|
136
|
+
if record["ddtags"].nil? || record["ddtags"].empty?
|
137
|
+
record["ddtags"] = container_tags
|
138
|
+
else
|
139
|
+
record["ddtags"] = record["ddtags"] + "," + container_tags
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
log.trace "datadog plugin: all tags=#{record["ddtags"]}"
|
144
|
+
|
145
|
+
if @use_json
|
146
|
+
messages.push "#{api_key} " + Yajl.dump(record) + "\n"
|
147
|
+
else
|
148
|
+
next unless record.has_key? "message"
|
149
|
+
messages.push "#{api_key} " + record["message"].strip + "\n"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
send_to_datadog(messages)
|
153
|
+
end
|
154
|
+
|
155
|
+
def send_to_datadog(events)
|
156
|
+
@my_mutex.synchronize do
|
157
|
+
events.each do |event|
|
158
|
+
log.trace "Datadog plugin: about to send event=#{event}"
|
159
|
+
retries = 0
|
160
|
+
begin
|
161
|
+
log.info "New attempt to Datadog attempt=#{retries}" if retries > 1
|
162
|
+
@client ||= new_client
|
163
|
+
@client.write(event)
|
164
|
+
rescue => e
|
165
|
+
@client.close rescue nil
|
166
|
+
@client = nil
|
167
|
+
|
168
|
+
if retries == 0
|
169
|
+
# immediately retry, in case it's just a server-side close
|
170
|
+
retries += 1
|
171
|
+
retry
|
172
|
+
end
|
173
|
+
|
174
|
+
if retries < @max_retries || @max_retries == -1
|
175
|
+
a_couple_of_seconds = retries ** 2
|
176
|
+
a_couple_of_seconds = 30 unless a_couple_of_seconds < 30
|
177
|
+
retries += 1
|
178
|
+
log.warn "Could not push event to Datadog, attempt=#{retries} max_attempts=#{max_retries} wait=#{a_couple_of_seconds}s error=#{e}"
|
179
|
+
sleep a_couple_of_seconds
|
180
|
+
retry
|
181
|
+
end
|
182
|
+
raise ConnectionFailure, "Could not push event to Datadog after #{retries} retries, #{e}"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
# Collect docker and kubernetes tags for your logs using `filter_kubernetes_metadata` plugin,
|
189
|
+
# for more information about the attribute names, check:
|
190
|
+
# https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter/blob/master/lib/fluent/plugin/filter_kubernetes_metadata.rb#L265
|
191
|
+
|
192
|
+
def get_container_tags(record)
|
193
|
+
return [
|
194
|
+
get_kubernetes_tags(record),
|
195
|
+
get_docker_tags(record)
|
196
|
+
].compact.join(",")
|
197
|
+
end
|
198
|
+
|
199
|
+
def get_kubernetes_tags(record)
|
200
|
+
if record.key?('kubernetes') and not record.fetch('kubernetes').nil?
|
201
|
+
kubernetes = record['kubernetes']
|
202
|
+
tags = Array.new
|
203
|
+
tags.push("image_name:" + kubernetes['container_image']) unless kubernetes['container_image'].nil?
|
204
|
+
tags.push("container_name:" + kubernetes['container_name']) unless kubernetes['container_name'].nil?
|
205
|
+
tags.push("kube_namespace:" + kubernetes['namespace_name']) unless kubernetes['namespace_name'].nil?
|
206
|
+
tags.push("pod_name:" + kubernetes['pod_name']) unless kubernetes['pod_name'].nil?
|
207
|
+
return tags.join(",")
|
208
|
+
end
|
209
|
+
return nil
|
210
|
+
end
|
211
|
+
|
212
|
+
def get_docker_tags(record)
|
213
|
+
if record.key?('docker') and not record.fetch('docker').nil?
|
214
|
+
docker = record['docker']
|
215
|
+
tags = Array.new
|
216
|
+
tags.push("container_id:" + docker['container_id']) unless docker['container_id'].nil?
|
217
|
+
return tags.join(",")
|
218
|
+
end
|
219
|
+
return nil
|
220
|
+
end
|
221
|
+
|
222
|
+
def get_attribute_tags(record, attribute_tags)
|
223
|
+
if not attribute_tags.nil? and not record.nil?
|
224
|
+
tags = Array.new
|
225
|
+
for attribute_tag in attribute_tags
|
226
|
+
log.trace "attribute tags - datadog plugin: attr=#{attribute_tag}, value=#{record[attribute_tag]}"
|
227
|
+
tags.push(attribute_tag + ":" + record[attribute_tag]) unless record[attribute_tag].nil?
|
228
|
+
end
|
229
|
+
return tags.join(",")
|
230
|
+
end
|
231
|
+
return nil
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-datadog-np
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.10.6.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas parfait
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-12 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
|
+
- ''
|
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-np.gemspec
|
68
|
+
- lib/fluent/plugin/out_datadog.rb
|
69
|
+
homepage: http://datadoghq.com
|
70
|
+
licenses:
|
71
|
+
- Apache License 2.0
|
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: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.5.2.3
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Datadog output plugin for Fluent event collector
|
93
|
+
test_files: []
|