logstash-filter-aggregate 2.0.5 → 2.1.0
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 +28 -24
- data/CONTRIBUTORS +13 -13
- data/Gemfile +2 -2
- data/LICENSE +13 -13
- data/README.md +167 -161
- data/lib/logstash/filters/aggregate.rb +316 -288
- data/logstash-filter-aggregate.gemspec +24 -24
- data/spec/filters/aggregate_spec.rb +210 -185
- data/spec/filters/aggregate_spec_helper.rb +49 -49
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 847b68e7346466cf927e4975469593a48ebb9771
|
4
|
+
data.tar.gz: 9b0dd0eb302cfba006c09970a2442ccf5d316fa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8d934c2ba456f1d828bf97e7cee1c5027d424e08340d6fd1be63944558c03daec0cf387b33621b4cb769dda443adb1e1693a7cf3e14b41990bd4d5b87673a34
|
7
|
+
data.tar.gz: 6cdf6281964d83d2c64dc19eb764b9d15e50fdfd9fc50d29e1d7d0af10edb67f7757eef66bb2bc70dbe856dda67ee9d9c1f4908de4b33adc85411b44356e2c6e
|
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,24 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
-
|
15
|
-
|
16
|
-
|
17
|
-
-
|
18
|
-
|
19
|
-
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
-
|
24
|
-
-
|
1
|
+
## 2.1.0
|
2
|
+
- new feature: add new option "aggregate_maps_path" so that aggregate maps can be stored at logstash shutdown and reloaded at logstash startup
|
3
|
+
|
4
|
+
## 2.0.5
|
5
|
+
- internal,deps: Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
|
6
|
+
|
7
|
+
## 2.0.4
|
8
|
+
- internal,deps: New dependency requirements for logstash-core for the 5.0 release
|
9
|
+
|
10
|
+
## 2.0.3
|
11
|
+
- bugfix: fix issue #10 : numeric task_id is now well processed
|
12
|
+
|
13
|
+
## 2.0.2
|
14
|
+
- bugfix: fix issue #5 : when code call raises an exception, the error is logged and the event is tagged '_aggregateexception'. It avoids logstash crash.
|
15
|
+
|
16
|
+
## 2.0.0
|
17
|
+
- internal: Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
18
|
+
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
19
|
+
- internal,deps: Dependency on logstash-core update to 2.0
|
20
|
+
|
21
|
+
## 0.1.3
|
22
|
+
- breaking: remove "milestone" method call which is deprecated in logstash 1.5, break compatibility with logstash 1.4
|
23
|
+
- internal,test: enhanced tests using 'expect' command
|
24
|
+
- docs: add a second example in documentation
|
25
|
+
|
26
|
+
## 0.1.2
|
27
|
+
- compatible with logstash 1.4
|
28
|
+
- first version available on github
|
data/CONTRIBUTORS
CHANGED
@@ -1,13 +1,13 @@
|
|
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
|
-
Maintainers:
|
5
|
-
* Fabien Baligand (fbaligand)
|
6
|
-
|
7
|
-
Contributors:
|
8
|
-
* Fabien Baligand (fbaligand)
|
9
|
-
|
10
|
-
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
11
|
-
Logstash, and you aren't on the list above and want to be, please let us know
|
12
|
-
and we'll make sure you're here. Contributions from folks like you are what make
|
13
|
-
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
|
+
Maintainers:
|
5
|
+
* Fabien Baligand (fbaligand)
|
6
|
+
|
7
|
+
Contributors:
|
8
|
+
* Fabien Baligand (fbaligand)
|
9
|
+
|
10
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
11
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
12
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
13
|
+
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,161 +1,167 @@
|
|
1
|
-
# Logstash Filter Aggregate Documentation
|
2
|
-
|
3
|
-
[![Build Status](
|
4
|
-
|
5
|
-
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.
|
6
|
-
|
7
|
-
You should be very careful to set logstash filter workers to 1 (`-w 1` flag) for this filter to work
|
8
|
-
correctly otherwise documents
|
9
|
-
may be processed out of sequence and unexpected results will occur.
|
10
|
-
|
11
|
-
## Example #1
|
12
|
-
|
13
|
-
* with these given logs :
|
14
|
-
```
|
15
|
-
INFO - 12345 - TASK_START - start
|
16
|
-
INFO - 12345 - SQL - sqlQuery1 - 12
|
17
|
-
INFO - 12345 - SQL - sqlQuery2 - 34
|
18
|
-
INFO - 12345 - TASK_END - end
|
19
|
-
```
|
20
|
-
|
21
|
-
* you can aggregate "sql duration" for the whole task with this configuration :
|
22
|
-
``` ruby
|
23
|
-
filter {
|
24
|
-
grok {
|
25
|
-
match => [ "message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
|
26
|
-
}
|
27
|
-
|
28
|
-
if [logger] == "TASK_START" {
|
29
|
-
aggregate {
|
30
|
-
task_id => "%{taskid}"
|
31
|
-
code => "map['sql_duration'] = 0"
|
32
|
-
map_action => "create"
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
if [logger] == "SQL" {
|
37
|
-
aggregate {
|
38
|
-
task_id => "%{taskid}"
|
39
|
-
code => "map['sql_duration'] += event['duration']"
|
40
|
-
map_action => "update"
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
if [logger] == "TASK_END" {
|
45
|
-
aggregate {
|
46
|
-
task_id => "%{taskid}"
|
47
|
-
code => "event['sql_duration'] = map['sql_duration']"
|
48
|
-
map_action => "update"
|
49
|
-
end_of_task => true
|
50
|
-
timeout => 120
|
51
|
-
}
|
52
|
-
}
|
53
|
-
}
|
54
|
-
```
|
55
|
-
|
56
|
-
* the final event then looks like :
|
57
|
-
``` ruby
|
58
|
-
{
|
59
|
-
"message" => "INFO - 12345 - TASK_END - end",
|
60
|
-
"sql_duration" => 46
|
61
|
-
}
|
62
|
-
```
|
63
|
-
|
64
|
-
the field `sql_duration` is added and contains the sum of all sql queries durations.
|
65
|
-
|
66
|
-
## Example #2
|
67
|
-
|
68
|
-
* If you have the same logs than example #1, but without a start log :
|
69
|
-
```
|
70
|
-
INFO - 12345 - SQL - sqlQuery1 - 12
|
71
|
-
INFO - 12345 - SQL - sqlQuery2 - 34
|
72
|
-
INFO - 12345 - TASK_END - end
|
73
|
-
```
|
74
|
-
|
75
|
-
* you can also aggregate "sql duration" with a slightly different configuration :
|
76
|
-
``` ruby
|
77
|
-
filter {
|
78
|
-
grok {
|
79
|
-
match => [ "message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
|
80
|
-
}
|
81
|
-
|
82
|
-
if [logger] == "SQL" {
|
83
|
-
aggregate {
|
84
|
-
task_id => "%{taskid}"
|
85
|
-
code => "map['sql_duration'] ||= 0 ; map['sql_duration'] += event['duration']"
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
if [logger] == "TASK_END" {
|
90
|
-
aggregate {
|
91
|
-
task_id => "%{taskid}"
|
92
|
-
code => "event['sql_duration'] = map['sql_duration']"
|
93
|
-
end_of_task => true
|
94
|
-
timeout => 120
|
95
|
-
}
|
96
|
-
}
|
97
|
-
}
|
98
|
-
```
|
99
|
-
|
100
|
-
* the final event is exactly the same than example #1
|
101
|
-
* the key point is the "||=" ruby operator.
|
102
|
-
it allows to initialize 'sql_duration' map entry to 0 only if this map entry is not already initialized
|
103
|
-
|
104
|
-
|
105
|
-
## How it works
|
106
|
-
- the filter needs a "task_id" to correlate events (log lines) of a same task
|
107
|
-
- at the task beggining, filter creates a map, attached to task_id
|
108
|
-
- for each event, you can execute code using 'event' and 'map' (for instance, copy an event field to map)
|
109
|
-
- in the final event, you can execute a last code (for instance, add map data to final event)
|
110
|
-
- after the final event, the map attached to task is deleted
|
111
|
-
- 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
|
112
|
-
- if no timeout is defined, by default, all maps older than 1800 seconds are automatically deleted
|
113
|
-
- finally, if `code` execution raises an exception, the error is logged and event is tagged '_aggregateexception'
|
114
|
-
|
115
|
-
## Use Cases
|
116
|
-
- extract some cool metrics from task logs and push them into task final log event (like in example #1 and #2)
|
117
|
-
- extract error information in any task log line, and push it in final task event (to get a final document with all error information if any)
|
118
|
-
- extract all back-end calls as a list, and push this list in final task event (to get a task profile)
|
119
|
-
- extract all http headers logged in several lines to push this list in final task event (complete http request info)
|
120
|
-
- for every back-end call, collect call details available on several lines, analyse it and finally tag final back-end call log line (error, timeout, business-warning, ...)
|
121
|
-
- Finally, task id can be any correlation id matching your need : it can be a session id, a file path, ...
|
122
|
-
|
123
|
-
## Aggregate Plugin Options
|
124
|
-
- **task_id :**
|
125
|
-
The expression defining task ID to correlate logs.
|
126
|
-
This value must uniquely identify the task in the system.
|
127
|
-
This option is required.
|
128
|
-
Example value : `"%{application}%{my_task_id}"`
|
129
|
-
|
130
|
-
- **code:**
|
131
|
-
The code to execute to update map, using current event.
|
132
|
-
Or on the contrary, the code to execute to update event, using current map.
|
133
|
-
You will have a 'map' variable and an 'event' variable available (that is the event itself).
|
134
|
-
This option is required.
|
135
|
-
Example value : `"map['sql_duration'] += event['duration']"`
|
136
|
-
|
137
|
-
- **map_action:**
|
138
|
-
Tell the filter what to do with aggregate map (default : "create_or_update").
|
139
|
-
`create`: create the map, and execute the code only if map wasn't created before
|
140
|
-
`update`: doesn't create the map, and execute the code only if map was created before
|
141
|
-
`create_or_update`: create the map if it wasn't created before, execute the code in all cases
|
142
|
-
Default value: `create_or_update`
|
143
|
-
|
144
|
-
- **end_of_task:**
|
145
|
-
Tell the filter that task is ended, and therefore, to delete map after code execution.
|
146
|
-
Default value: `false`
|
147
|
-
|
148
|
-
- **timeout:**
|
149
|
-
The amount of seconds after a task "end event" can be considered lost.
|
150
|
-
The task "map" is
|
151
|
-
The default value is 0, which means no timeout so no auto eviction.
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
1
|
+
# Logstash Filter Aggregate Documentation
|
2
|
+
|
3
|
+
[![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-aggregate.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-aggregate)
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
You should be very careful to set logstash filter workers to 1 (`-w 1` flag) for this filter to work
|
8
|
+
correctly otherwise documents
|
9
|
+
may be processed out of sequence and unexpected results will occur.
|
10
|
+
|
11
|
+
## Example #1
|
12
|
+
|
13
|
+
* with these given logs :
|
14
|
+
```
|
15
|
+
INFO - 12345 - TASK_START - start
|
16
|
+
INFO - 12345 - SQL - sqlQuery1 - 12
|
17
|
+
INFO - 12345 - SQL - sqlQuery2 - 34
|
18
|
+
INFO - 12345 - TASK_END - end
|
19
|
+
```
|
20
|
+
|
21
|
+
* you can aggregate "sql duration" for the whole task with this configuration :
|
22
|
+
``` ruby
|
23
|
+
filter {
|
24
|
+
grok {
|
25
|
+
match => [ "message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
|
26
|
+
}
|
27
|
+
|
28
|
+
if [logger] == "TASK_START" {
|
29
|
+
aggregate {
|
30
|
+
task_id => "%{taskid}"
|
31
|
+
code => "map['sql_duration'] = 0"
|
32
|
+
map_action => "create"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
if [logger] == "SQL" {
|
37
|
+
aggregate {
|
38
|
+
task_id => "%{taskid}"
|
39
|
+
code => "map['sql_duration'] += event['duration']"
|
40
|
+
map_action => "update"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
if [logger] == "TASK_END" {
|
45
|
+
aggregate {
|
46
|
+
task_id => "%{taskid}"
|
47
|
+
code => "event['sql_duration'] = map['sql_duration']"
|
48
|
+
map_action => "update"
|
49
|
+
end_of_task => true
|
50
|
+
timeout => 120
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
* the final event then looks like :
|
57
|
+
``` ruby
|
58
|
+
{
|
59
|
+
"message" => "INFO - 12345 - TASK_END - end",
|
60
|
+
"sql_duration" => 46
|
61
|
+
}
|
62
|
+
```
|
63
|
+
|
64
|
+
the field `sql_duration` is added and contains the sum of all sql queries durations.
|
65
|
+
|
66
|
+
## Example #2
|
67
|
+
|
68
|
+
* If you have the same logs than example #1, but without a start log :
|
69
|
+
```
|
70
|
+
INFO - 12345 - SQL - sqlQuery1 - 12
|
71
|
+
INFO - 12345 - SQL - sqlQuery2 - 34
|
72
|
+
INFO - 12345 - TASK_END - end
|
73
|
+
```
|
74
|
+
|
75
|
+
* you can also aggregate "sql duration" with a slightly different configuration :
|
76
|
+
``` ruby
|
77
|
+
filter {
|
78
|
+
grok {
|
79
|
+
match => [ "message", "%{LOGLEVEL:loglevel} - %{NOTSPACE:taskid} - %{NOTSPACE:logger} - %{WORD:label}( - %{INT:duration:int})?" ]
|
80
|
+
}
|
81
|
+
|
82
|
+
if [logger] == "SQL" {
|
83
|
+
aggregate {
|
84
|
+
task_id => "%{taskid}"
|
85
|
+
code => "map['sql_duration'] ||= 0 ; map['sql_duration'] += event['duration']"
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
if [logger] == "TASK_END" {
|
90
|
+
aggregate {
|
91
|
+
task_id => "%{taskid}"
|
92
|
+
code => "event['sql_duration'] = map['sql_duration']"
|
93
|
+
end_of_task => true
|
94
|
+
timeout => 120
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
```
|
99
|
+
|
100
|
+
* the final event is exactly the same than example #1
|
101
|
+
* the key point is the "||=" ruby operator.
|
102
|
+
it allows to initialize 'sql_duration' map entry to 0 only if this map entry is not already initialized
|
103
|
+
|
104
|
+
|
105
|
+
## How it works
|
106
|
+
- the filter needs a "task_id" to correlate events (log lines) of a same task
|
107
|
+
- at the task beggining, filter creates a map, attached to task_id
|
108
|
+
- for each event, you can execute code using 'event' and 'map' (for instance, copy an event field to map)
|
109
|
+
- in the final event, you can execute a last code (for instance, add map data to final event)
|
110
|
+
- after the final event, the map attached to task is deleted
|
111
|
+
- 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
|
112
|
+
- if no timeout is defined, by default, all maps older than 1800 seconds are automatically deleted
|
113
|
+
- finally, if `code` execution raises an exception, the error is logged and event is tagged '_aggregateexception'
|
114
|
+
|
115
|
+
## Use Cases
|
116
|
+
- extract some cool metrics from task logs and push them into task final log event (like in example #1 and #2)
|
117
|
+
- extract error information in any task log line, and push it in final task event (to get a final document with all error information if any)
|
118
|
+
- extract all back-end calls as a list, and push this list in final task event (to get a task profile)
|
119
|
+
- extract all http headers logged in several lines to push this list in final task event (complete http request info)
|
120
|
+
- for every back-end call, collect call details available on several lines, analyse it and finally tag final back-end call log line (error, timeout, business-warning, ...)
|
121
|
+
- Finally, task id can be any correlation id matching your need : it can be a session id, a file path, ...
|
122
|
+
|
123
|
+
## Aggregate Plugin Options
|
124
|
+
- **task_id :**
|
125
|
+
The expression defining task ID to correlate logs.
|
126
|
+
This value must uniquely identify the task in the system.
|
127
|
+
This option is required.
|
128
|
+
Example value : `"%{application}%{my_task_id}"`
|
129
|
+
|
130
|
+
- **code:**
|
131
|
+
The code to execute to update map, using current event.
|
132
|
+
Or on the contrary, the code to execute to update event, using current map.
|
133
|
+
You will have a 'map' variable and an 'event' variable available (that is the event itself).
|
134
|
+
This option is required.
|
135
|
+
Example value : `"map['sql_duration'] += event['duration']"`
|
136
|
+
|
137
|
+
- **map_action:**
|
138
|
+
Tell the filter what to do with aggregate map (default : "create_or_update").
|
139
|
+
`create`: create the map, and execute the code only if map wasn't created before
|
140
|
+
`update`: doesn't create the map, and execute the code only if map was created before
|
141
|
+
`create_or_update`: create the map if it wasn't created before, execute the code in all cases
|
142
|
+
Default value: `create_or_update`
|
143
|
+
|
144
|
+
- **end_of_task:**
|
145
|
+
Tell the filter that task is ended, and therefore, to delete map after code execution.
|
146
|
+
Default value: `false`
|
147
|
+
|
148
|
+
- **timeout:**
|
149
|
+
The amount of seconds after a task "end event" can be considered lost.
|
150
|
+
When timeout occurs for a task, The task "map" is evicted.
|
151
|
+
The default value is 0, which means no timeout so no auto eviction.
|
152
|
+
|
153
|
+
- **aggregate_maps_path:**
|
154
|
+
The path to file where aggregate maps are stored when logstash stops and are loaded from when logstash starts.
|
155
|
+
If not defined, aggregate maps will not be stored at logstash stop and will be lost.
|
156
|
+
Should be defined for only one aggregate filter (as aggregate maps are global).
|
157
|
+
Example value : `"/path/to/.aggregate_maps"`
|
158
|
+
|
159
|
+
|
160
|
+
## Need Help?
|
161
|
+
|
162
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
163
|
+
|
164
|
+
|
165
|
+
## Want to contribute?
|
166
|
+
|
167
|
+
Read [BUILD.md](BUILD.md).
|