1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
***************************************
imdocker: Docker Input Module
***************************************
=========================== ===========================================================================
**Module Name:** **imdocker**
**Author:** Nelson Yen
**Available since:** 8.41.0
=========================== ===========================================================================
Purpose
=======
The imdocker input plug-in provides the ability to receive container logs from Docker (engine)
via the Docker Rest API.
Other features include:
- filter containers through the plugin options
- handle long log lines (greater than 16kb) and obtain
- container metadata, such as container id, name, image id, labels, etc.
**Note**: Multiple docker instances are not supported at the time of this writing.
Configuration Parameters
========================
The configuration parameters for this module are designed for tailoring
the behavior of imdocker.
.. note::
Parameter names are case-insensitive.
.. note::
This module supports module parameters, only.
Module Parameters
-----------------
DockerApiUnixSockAddr
^^^^^^^^^^^^^^^^^^^^^
.. csv-table::
:header: "type", "default", "mandatory", "|FmtObsoleteName| directive"
:widths: auto
:class: parameter-table
"string", "/var/run/docker.sock", "no", "none"
Specifies the Docker unix socket address to use.
ApiVersionStr
^^^^^^^^^^^^^^^^^^^^
.. csv-table::
:header: "type", "default", "mandatory", "|FmtObsoleteName| directive"
:widths: auto
:class: parameter-table
"string", "v1.27", "no", "none"
Specifies the version of Docker API to use. Must be in the format specified by the
Docker api, e.g. similar to the default above (v1.27, v1.28, etc).
PollingInterval
^^^^^^^^^^^^^^^^^^^^
.. csv-table::
:header: "type", "default", "mandatory", "|FmtObsoleteName| directive"
:widths: auto
:class: parameter-table
"integer", "60", "no", "none"
Specifies the polling interval in seconds, imdocker will poll for new containers by
calling the 'List containers' API from the Docker engine.
ListContainersOptions
^^^^^^^^^^^^^^^^^^^^^
.. csv-table::
:header: "type", "default", "mandatory", "|FmtObsoleteName| directive"
:widths: auto
:class: parameter-table
"string", "", "no", "none"
Specifies the http query component of the a 'List Containers' HTTP API request.
See Docker API for more information about available options.
**Note**: It is not necessary to prepend the string with '?'.
GetContainerLogOptions
^^^^^^^^^^^^^^^^^^^^^^
.. csv-table::
:header: "type", "default", "mandatory", "|FmtObsoleteName| directive"
:widths: auto
:class: parameter-table
"string", "timestamp=0&follow=1&stdout=1&stderr=1&tail=1", "no", "none"
Specifies the http query component of the a 'Get container logs' HTTP API request.
See Docker API for more information about available options.
**Note**: It is not necessary to prepend the string with '?'.
RetrieveNewLogsFromStart
^^^^^^^^^^^^^^^^^^^^^^^^
.. csv-table::
:header: "type", "default", "mandatory", "|FmtObsoleteName| directive"
:widths: auto
:class: parameter-table
"binary", "1", "no", "none"
This option specifies the whether imdocker will process newly found container logs from the beginning.
The exception is for containers found on start-up. The container logs for containers
that were active at imdocker start-up are controlled via 'GetContainerLogOptions', the
'tail' in particular.
DefaultFacility
^^^^^^^^^^^^^^^
.. csv-table::
:header: "type", "default", "mandatory", "|FmtObsoleteName| directive"
:widths: auto
:class: parameter-table
"integer or string (preferred)", "user", "no", "``$InputFileFacility``"
The syslog facility to be assigned to log messages received. Specified as numbers.
.. seealso::
https://en.wikipedia.org/wiki/Syslog
DefaultSeverity
^^^^^^^^^^^^^^^
.. csv-table::
:header: "type", "default", "mandatory", "|FmtObsoleteName| directive"
:widths: auto
:class: parameter-table
"integer or string (preferred)", "notice", "no", "``$InputFileSeverity``"
The syslog severity to be assigned to log messages received. Specified as numbers (e.g. 6
for ``info``). Textual form is suggested. Default is ``notice``.
.. seealso::
https://en.wikipedia.org/wiki/Syslog
escapeLF
^^^^^^^^
.. csv-table::
:header: "type", "default", "mandatory", "|FmtObsoleteName| directive"
:widths: auto
:class: parameter-table
"binary", "on", "no", "none"
This is only meaningful if multi-line messages are to be processed.
LF characters embedded into syslog messages cause a lot of trouble,
as most tools and even the legacy syslog TCP protocol do not expect
these. If set to "on", this option avoid this trouble by properly
escaping LF characters to the 4-byte sequence "#012". This is
consistent with other rsyslog control character escaping. By default,
escaping is turned on. If you turn it off, make sure you test very
carefully with all associated tools. Please note that if you intend
to use plain TCP syslog with embedded LF characters, you need to
enable octet-counted framing.
For more details, see Rainer's blog posting on imfile LF escaping.
Metadata
========
The imdocker module supports message metadata. It supports the following
data items:
- **Id** - the container id associated with the message.
- **Names** - the first container associated with the message.
- **ImageID** - the image id of the container associated with the message.
- **Labels** - all the labels of the container associated with the message in json format.
**Note**: At the time of this writing, metadata is always enabled.
Statistic Counter
=================
This plugin maintains `statistics <http://www.rsyslog.com/rsyslog-statistic-counter/>`. The statistic is named "imdocker".
The following properties are maintained for each listener:
- **submitted** - total number of messages submitted to main queue after reading from journal for processing
since startup. All records may not be submitted due to rate-limiting.
- **ratelimit.discarded** - number of messages discarded due to rate-limiting within configured
rate-limiting interval.
- **curl.errors** - total number of curl errors.
Caveats/Known Bugs
==================
- At the moment, this plugin only supports a single instance of docker on a host.
Configuration Examples
======================
Load module, with only defaults
--------------------------------
This activates the module with all the default options:
.. code-block:: none
module(load="imdocker")
Load module, with container filtering
-------------------------------------
This activates the module with container filtering on a label:
.. code-block:: none
module(load="imdocker"
DockerApiUnixSockAddr="/var/run/docker.sock"
ApiVersionStr="v1.27"
PollingInterval="60"
ListContainersOptions="filters={\"label\":[\"log_opt_enabled\"]}"
GetContainerLogOptions="timestamps=0&follow=1&stdout=1&stderr=0&tail=1"
)
Example template to get container metadata
------------------------------------------
An example of how to create a template with container metadata
.. code-block:: none
template (name="ImdockerFormat" type="string"
string="program:%programname% tag:%syslogtag% id:%$!metadata!Id% name:%$!metadata!Names% imageid:%$!metadata!ImageID% labels:%$!metadata!Labels% msg: %msg%\n"
)
|