logstash-filter-aggregate 0.1.5 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BUILD.md +81 -81
- data/CHANGELOG.md +14 -15
- data/CONTRIBUTORS +10 -10
- data/Gemfile +2 -2
- data/LICENSE +13 -13
- data/README.md +147 -147
- data/lib/logstash/filters/aggregate.rb +277 -277
- data/logstash-filter-aggregate.gemspec +24 -24
- data/spec/filters/aggregate_spec.rb +177 -185
- data/spec/filters/aggregate_spec_helper.rb +49 -49
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c0279cf7984071cc3f9a16b46c6880381ce1c8
|
4
|
+
data.tar.gz: 4388fcf687de2dbdc244567faf9b377d1078c639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c1fea00dea5fce67dc57e5f24d402d116f966c4412e714b9ac385a2189a0b3284b3674c5d941fd4120a969e90dd562f2859884e26444be5885e85cf6725c651
|
7
|
+
data.tar.gz: 1769add45737af42642d49cc762a93499df95e6c766c4e82ec03ed7978fa7535c81daf10b91ce96943286238b72e6faad3c65596075e4cfbc9bdab8eadb97d2e
|
data/BUILD.md
CHANGED
@@ -1,82 +1,82 @@
|
|
1
|
-
# Logstash Plugin
|
2
|
-
|
3
|
-
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
-
|
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
|
-
|
7
|
-
## Documentation
|
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.elasticsearch.org/guide/en/logstash/current/).
|
10
|
-
|
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/elastic/docs#asciidoc-guide
|
13
|
-
|
14
|
-
## Developing
|
15
|
-
|
16
|
-
### 1. Plugin Developement and Testing
|
17
|
-
|
18
|
-
#### Code
|
19
|
-
- To get started, you'll need JRuby with the Bundler gem installed.
|
20
|
-
|
21
|
-
- Create a new plugin or clone an existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
22
|
-
|
23
|
-
- Install dependencies
|
24
|
-
```sh
|
25
|
-
bundle install
|
26
|
-
```
|
27
|
-
|
28
|
-
#### Test
|
29
|
-
|
30
|
-
- Update your dependencies
|
31
|
-
|
32
|
-
```sh
|
33
|
-
bundle install
|
34
|
-
```
|
35
|
-
|
36
|
-
- Run tests
|
37
|
-
|
38
|
-
```sh
|
39
|
-
bundle exec rspec
|
40
|
-
```
|
41
|
-
|
42
|
-
### 2. Running your unpublished Plugin in Logstash
|
43
|
-
|
44
|
-
#### 2.1 Run in a local Logstash clone
|
45
|
-
|
46
|
-
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
47
|
-
```ruby
|
48
|
-
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
49
|
-
```
|
50
|
-
- Install plugin
|
51
|
-
```sh
|
52
|
-
bin/plugin install --no-verify
|
53
|
-
```
|
54
|
-
- Run Logstash with your plugin
|
55
|
-
```sh
|
56
|
-
bin/logstash -e 'filter {awesome {}}'
|
57
|
-
```
|
58
|
-
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
59
|
-
|
60
|
-
#### 2.2 Run in an installed Logstash
|
61
|
-
|
62
|
-
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
63
|
-
|
64
|
-
- Build your plugin gem
|
65
|
-
```sh
|
66
|
-
gem build logstash-filter-awesome.gemspec
|
67
|
-
```
|
68
|
-
- Install the plugin from the Logstash home
|
69
|
-
```sh
|
70
|
-
bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
|
71
|
-
```
|
72
|
-
- Start Logstash and proceed to test the plugin
|
73
|
-
|
74
|
-
## Contributing
|
75
|
-
|
76
|
-
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
77
|
-
|
78
|
-
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
79
|
-
|
80
|
-
It is more important to the community that you are able to contribute.
|
81
|
-
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
+
|
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
|
+
|
7
|
+
## Documentation
|
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.elasticsearch.org/guide/en/logstash/current/).
|
10
|
+
|
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/elastic/docs#asciidoc-guide
|
13
|
+
|
14
|
+
## Developing
|
15
|
+
|
16
|
+
### 1. Plugin Developement and Testing
|
17
|
+
|
18
|
+
#### Code
|
19
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
20
|
+
|
21
|
+
- Create a new plugin or clone an existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
22
|
+
|
23
|
+
- Install dependencies
|
24
|
+
```sh
|
25
|
+
bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
#### Test
|
29
|
+
|
30
|
+
- Update your dependencies
|
31
|
+
|
32
|
+
```sh
|
33
|
+
bundle install
|
34
|
+
```
|
35
|
+
|
36
|
+
- Run tests
|
37
|
+
|
38
|
+
```sh
|
39
|
+
bundle exec rspec
|
40
|
+
```
|
41
|
+
|
42
|
+
### 2. Running your unpublished Plugin in Logstash
|
43
|
+
|
44
|
+
#### 2.1 Run in a local Logstash clone
|
45
|
+
|
46
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
47
|
+
```ruby
|
48
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
49
|
+
```
|
50
|
+
- Install plugin
|
51
|
+
```sh
|
52
|
+
bin/plugin install --no-verify
|
53
|
+
```
|
54
|
+
- Run Logstash with your plugin
|
55
|
+
```sh
|
56
|
+
bin/logstash -e 'filter {awesome {}}'
|
57
|
+
```
|
58
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
59
|
+
|
60
|
+
#### 2.2 Run in an installed Logstash
|
61
|
+
|
62
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
63
|
+
|
64
|
+
- Build your plugin gem
|
65
|
+
```sh
|
66
|
+
gem build logstash-filter-awesome.gemspec
|
67
|
+
```
|
68
|
+
- Install the plugin from the Logstash home
|
69
|
+
```sh
|
70
|
+
bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
|
71
|
+
```
|
72
|
+
- Start Logstash and proceed to test the plugin
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
77
|
+
|
78
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
79
|
+
|
80
|
+
It is more important to the community that you are able to contribute.
|
81
|
+
|
82
82
|
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
|
2
|
-
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
-
|
15
|
-
- first version available on github
|
1
|
+
## 2.0.0
|
2
|
+
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
3
|
+
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
4
|
+
- Dependency on logstash-core update to 2.0
|
5
|
+
|
6
|
+
# v 0.1.3
|
7
|
+
- break compatibility with logstash 1.4
|
8
|
+
- remove "milestone" method call which is deprecated in logstash 1.5
|
9
|
+
- enhanced tests using 'expect' command
|
10
|
+
- add a second example in documentation
|
11
|
+
|
12
|
+
# v 0.1.2
|
13
|
+
- compatible with logstash 1.4
|
14
|
+
- first version available on github
|
data/CONTRIBUTORS
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
The following is a list of people who have contributed ideas, code, bug
|
2
|
-
reports, or in general have helped logstash along its way.
|
3
|
-
|
4
|
-
Contributors:
|
5
|
-
* Fabien Baligand (fbaligand)
|
6
|
-
|
7
|
-
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
8
|
-
Logstash, and you aren't on the list above and want to be, please let us know
|
9
|
-
and we'll make sure you're here. Contributions from folks like you are what make
|
10
|
-
open source awesome.
|
1
|
+
The following is a list of people who have contributed ideas, code, bug
|
2
|
+
reports, or in general have helped logstash along its way.
|
3
|
+
|
4
|
+
Contributors:
|
5
|
+
* Fabien Baligand (fbaligand)
|
6
|
+
|
7
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
8
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
9
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
10
|
+
open source awesome.
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
data/LICENSE
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
Copyright (c) 2012-2015 Elasticsearch <http://www.elasticsearch.org>
|
2
|
-
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
you may not use this file except in compliance with the License.
|
5
|
-
You may obtain a copy of the License at
|
6
|
-
|
7
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
10
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
See the License for the specific language governing permissions and
|
13
|
-
limitations under the License.
|
1
|
+
Copyright (c) 2012-2015 Elasticsearch <http://www.elasticsearch.org>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,147 +1,147 @@
|
|
1
|
-
# Logstash Filter Aggregate Documentation
|
2
|
-
|
3
|
-
The aim of this filter is to aggregate information available among several events (typically log lines) belonging to a same task, and finally push aggregated information into final task event.
|
4
|
-
|
5
|
-
## Example #1
|
6
|
-
|
7
|
-
* with these given logs :
|
8
|
-
```
|
9
|
-
INFO - 12345 - TASK_START - start
|
10
|
-
INFO - 12345 - SQL - sqlQuery1 - 12
|
11
|
-
INFO - 12345 - SQL - sqlQuery2 - 34
|
12
|
-
INFO - 12345 - TASK_END - end
|
13
|
-
```
|
14
|
-
|
15
|
-
* you can aggregate "sql duration" for the whole task with this configuration :
|
16
|
-
``` ruby
|
17
|
-
filter {
|
18
|
-
grok {
|
19
|
-
match => [ "message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
|
20
|
-
}
|
21
|
-
|
22
|
-
if [logger] == "TASK_START" {
|
23
|
-
aggregate {
|
24
|
-
task_id => "%{taskid}"
|
25
|
-
code => "map['sql_duration'] = 0"
|
26
|
-
map_action => "create"
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
if [logger] == "SQL" {
|
31
|
-
aggregate {
|
32
|
-
task_id => "%{taskid}"
|
33
|
-
code => "map['sql_duration'] += event['duration']"
|
34
|
-
map_action => "update"
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
if [logger] == "TASK_END" {
|
39
|
-
aggregate {
|
40
|
-
task_id => "%{taskid}"
|
41
|
-
code => "event['sql_duration'] = map['sql_duration']"
|
42
|
-
map_action => "update"
|
43
|
-
end_of_task => true
|
44
|
-
timeout => 120
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
48
|
-
```
|
49
|
-
|
50
|
-
* the final event then looks like :
|
51
|
-
``` ruby
|
52
|
-
{
|
53
|
-
"message" => "INFO - 12345 - TASK_END - end",
|
54
|
-
"sql_duration" => 46
|
55
|
-
}
|
56
|
-
```
|
57
|
-
|
58
|
-
the field `sql_duration` is added and contains the sum of all sql queries durations.
|
59
|
-
|
60
|
-
## Example #2
|
61
|
-
|
62
|
-
* If you have the same logs than example #1, but without a start log :
|
63
|
-
```
|
64
|
-
INFO - 12345 - SQL - sqlQuery1 - 12
|
65
|
-
INFO - 12345 - SQL - sqlQuery2 - 34
|
66
|
-
INFO - 12345 - TASK_END - end
|
67
|
-
```
|
68
|
-
|
69
|
-
* you can also aggregate "sql duration" with a slightly different configuration :
|
70
|
-
``` ruby
|
71
|
-
filter {
|
72
|
-
grok {
|
73
|
-
match => [ "message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
|
74
|
-
}
|
75
|
-
|
76
|
-
if [logger] == "SQL" {
|
77
|
-
aggregate {
|
78
|
-
task_id => "%{taskid}"
|
79
|
-
code => "map['sql_duration'] ||= 0 ; map['sql_duration'] += event['duration']"
|
80
|
-
}
|
81
|
-
}
|
82
|
-
|
83
|
-
if [logger] == "TASK_END" {
|
84
|
-
aggregate {
|
85
|
-
task_id => "%{taskid}"
|
86
|
-
code => "event['sql_duration'] = map['sql_duration']"
|
87
|
-
end_of_task => true
|
88
|
-
timeout => 120
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
```
|
93
|
-
|
94
|
-
* the final event is exactly the same than example #1
|
95
|
-
* the key point is the "||=" ruby operator.
|
96
|
-
it allows to initialize 'sql_duration' map entry to 0 only if this map entry is not already initialized
|
97
|
-
|
98
|
-
|
99
|
-
## How it works
|
100
|
-
- the filter needs a "task_id" to correlate events (log lines) of a same task
|
101
|
-
- at the task beggining, filter creates a map, attached to task_id
|
102
|
-
- for each event, you can execute code using 'event' and 'map' (for instance, copy an event field to map)
|
103
|
-
- in the final event, you can execute a last code (for instance, add map data to final event)
|
104
|
-
- after the final event, the map attached to task is deleted
|
105
|
-
- in one filter configuration, it is recommanded to define a timeout option to protect the filter against unterminated tasks. It tells the filter to delete expired maps
|
106
|
-
- if no timeout is defined, by default, all maps older than 1800 seconds are automatically deleted
|
107
|
-
- finally, if `code` execution raises an exception, the error is logged and event is tagged '_aggregateexception'
|
108
|
-
|
109
|
-
## Aggregate Plugin Options
|
110
|
-
- **task_id :**
|
111
|
-
The expression defining task ID to correlate logs.
|
112
|
-
This value must uniquely identify the task in the system.
|
113
|
-
This option is required.
|
114
|
-
Example value : `"%{application}%{my_task_id}"`
|
115
|
-
|
116
|
-
- **code:**
|
117
|
-
The code to execute to update map, using current event.
|
118
|
-
Or on the contrary, the code to execute to update event, using current map.
|
119
|
-
You will have a 'map' variable and an 'event' variable available (that is the event itself).
|
120
|
-
This option is required.
|
121
|
-
Example value : `"map['sql_duration'] += event['duration']"`
|
122
|
-
|
123
|
-
- **map_action:**
|
124
|
-
Tell the filter what to do with aggregate map (default : "create_or_update").
|
125
|
-
`create`: create the map, and execute the code only if map wasn't created before
|
126
|
-
`update`: doesn't create the map, and execute the code only if map was created before
|
127
|
-
`create_or_update`: create the map if it wasn't created before, execute the code in all cases
|
128
|
-
Default value: `create_or_update`
|
129
|
-
|
130
|
-
- **end_of_task:**
|
131
|
-
Tell the filter that task is ended, and therefore, to delete map after code execution.
|
132
|
-
Default value: `false`
|
133
|
-
|
134
|
-
- **timeout:**
|
135
|
-
The amount of seconds after a task "end event" can be considered lost.
|
136
|
-
The task "map" is then evicted.
|
137
|
-
The default value is 0, which means no timeout so no auto eviction.
|
138
|
-
|
139
|
-
|
140
|
-
## Need Help?
|
141
|
-
|
142
|
-
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
143
|
-
|
144
|
-
|
145
|
-
## Want to contribute?
|
146
|
-
|
147
|
-
Read [BUILD.md](BUILD.md).
|
1
|
+
# Logstash Filter Aggregate Documentation
|
2
|
+
|
3
|
+
The aim of this filter is to aggregate information available among several events (typically log lines) belonging to a same task, and finally push aggregated information into final task event.
|
4
|
+
|
5
|
+
## Example #1
|
6
|
+
|
7
|
+
* with these given logs :
|
8
|
+
```
|
9
|
+
INFO - 12345 - TASK_START - start
|
10
|
+
INFO - 12345 - SQL - sqlQuery1 - 12
|
11
|
+
INFO - 12345 - SQL - sqlQuery2 - 34
|
12
|
+
INFO - 12345 - TASK_END - end
|
13
|
+
```
|
14
|
+
|
15
|
+
* you can aggregate "sql duration" for the whole task with this configuration :
|
16
|
+
``` ruby
|
17
|
+
filter {
|
18
|
+
grok {
|
19
|
+
match => [ "message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
|
20
|
+
}
|
21
|
+
|
22
|
+
if [logger] == "TASK_START" {
|
23
|
+
aggregate {
|
24
|
+
task_id => "%{taskid}"
|
25
|
+
code => "map['sql_duration'] = 0"
|
26
|
+
map_action => "create"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
if [logger] == "SQL" {
|
31
|
+
aggregate {
|
32
|
+
task_id => "%{taskid}"
|
33
|
+
code => "map['sql_duration'] += event['duration']"
|
34
|
+
map_action => "update"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
if [logger] == "TASK_END" {
|
39
|
+
aggregate {
|
40
|
+
task_id => "%{taskid}"
|
41
|
+
code => "event['sql_duration'] = map['sql_duration']"
|
42
|
+
map_action => "update"
|
43
|
+
end_of_task => true
|
44
|
+
timeout => 120
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
```
|
49
|
+
|
50
|
+
* the final event then looks like :
|
51
|
+
``` ruby
|
52
|
+
{
|
53
|
+
"message" => "INFO - 12345 - TASK_END - end",
|
54
|
+
"sql_duration" => 46
|
55
|
+
}
|
56
|
+
```
|
57
|
+
|
58
|
+
the field `sql_duration` is added and contains the sum of all sql queries durations.
|
59
|
+
|
60
|
+
## Example #2
|
61
|
+
|
62
|
+
* If you have the same logs than example #1, but without a start log :
|
63
|
+
```
|
64
|
+
INFO - 12345 - SQL - sqlQuery1 - 12
|
65
|
+
INFO - 12345 - SQL - sqlQuery2 - 34
|
66
|
+
INFO - 12345 - TASK_END - end
|
67
|
+
```
|
68
|
+
|
69
|
+
* you can also aggregate "sql duration" with a slightly different configuration :
|
70
|
+
``` ruby
|
71
|
+
filter {
|
72
|
+
grok {
|
73
|
+
match => [ "message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
|
74
|
+
}
|
75
|
+
|
76
|
+
if [logger] == "SQL" {
|
77
|
+
aggregate {
|
78
|
+
task_id => "%{taskid}"
|
79
|
+
code => "map['sql_duration'] ||= 0 ; map['sql_duration'] += event['duration']"
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
if [logger] == "TASK_END" {
|
84
|
+
aggregate {
|
85
|
+
task_id => "%{taskid}"
|
86
|
+
code => "event['sql_duration'] = map['sql_duration']"
|
87
|
+
end_of_task => true
|
88
|
+
timeout => 120
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
```
|
93
|
+
|
94
|
+
* the final event is exactly the same than example #1
|
95
|
+
* the key point is the "||=" ruby operator.
|
96
|
+
it allows to initialize 'sql_duration' map entry to 0 only if this map entry is not already initialized
|
97
|
+
|
98
|
+
|
99
|
+
## How it works
|
100
|
+
- the filter needs a "task_id" to correlate events (log lines) of a same task
|
101
|
+
- at the task beggining, filter creates a map, attached to task_id
|
102
|
+
- for each event, you can execute code using 'event' and 'map' (for instance, copy an event field to map)
|
103
|
+
- in the final event, you can execute a last code (for instance, add map data to final event)
|
104
|
+
- after the final event, the map attached to task is deleted
|
105
|
+
- in one filter configuration, it is recommanded to define a timeout option to protect the filter against unterminated tasks. It tells the filter to delete expired maps
|
106
|
+
- if no timeout is defined, by default, all maps older than 1800 seconds are automatically deleted
|
107
|
+
- finally, if `code` execution raises an exception, the error is logged and event is tagged '_aggregateexception'
|
108
|
+
|
109
|
+
## Aggregate Plugin Options
|
110
|
+
- **task_id :**
|
111
|
+
The expression defining task ID to correlate logs.
|
112
|
+
This value must uniquely identify the task in the system.
|
113
|
+
This option is required.
|
114
|
+
Example value : `"%{application}%{my_task_id}"`
|
115
|
+
|
116
|
+
- **code:**
|
117
|
+
The code to execute to update map, using current event.
|
118
|
+
Or on the contrary, the code to execute to update event, using current map.
|
119
|
+
You will have a 'map' variable and an 'event' variable available (that is the event itself).
|
120
|
+
This option is required.
|
121
|
+
Example value : `"map['sql_duration'] += event['duration']"`
|
122
|
+
|
123
|
+
- **map_action:**
|
124
|
+
Tell the filter what to do with aggregate map (default : "create_or_update").
|
125
|
+
`create`: create the map, and execute the code only if map wasn't created before
|
126
|
+
`update`: doesn't create the map, and execute the code only if map was created before
|
127
|
+
`create_or_update`: create the map if it wasn't created before, execute the code in all cases
|
128
|
+
Default value: `create_or_update`
|
129
|
+
|
130
|
+
- **end_of_task:**
|
131
|
+
Tell the filter that task is ended, and therefore, to delete map after code execution.
|
132
|
+
Default value: `false`
|
133
|
+
|
134
|
+
- **timeout:**
|
135
|
+
The amount of seconds after a task "end event" can be considered lost.
|
136
|
+
The task "map" is then evicted.
|
137
|
+
The default value is 0, which means no timeout so no auto eviction.
|
138
|
+
|
139
|
+
|
140
|
+
## Need Help?
|
141
|
+
|
142
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
143
|
+
|
144
|
+
|
145
|
+
## Want to contribute?
|
146
|
+
|
147
|
+
Read [BUILD.md](BUILD.md).
|