-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
MongoDB 4.4 uses structured JSON format for logging, add support for this format while keeping support for the old one too. (cherry picked from commit 3752526) Co-authored-by: Tetiana Kravchenko <tanya.kravchenko.v@gmail.com>
- Loading branch information
1 parent
ed515e1
commit 22aec29
Showing
12 changed files
with
302 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
description: Pipeline for parsing MongoDB logs in JSON format | ||
processors: | ||
- json: | ||
field: message | ||
target_field: mongodb.log | ||
- date: | ||
field: mongodb.log.t.$date | ||
target_field: '@timestamp' | ||
formats: | ||
- yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ | ||
- rename: | ||
field: mongodb.log.s | ||
target_field: log.level | ||
- rename: | ||
field: mongodb.log.c | ||
target_field: mongodb.log.component | ||
- rename: | ||
field: mongodb.log.ctx | ||
target_field: mongodb.log.context | ||
- append: | ||
field: event.type | ||
value: access | ||
if: ctx.mongodb.log.component == 'ACCESS' | ||
- append: | ||
field: event.type | ||
value: change | ||
if: ctx.mongodb.log.component == 'WRITE' | ||
- append: | ||
field: event.type | ||
value: info | ||
if: ctx.mongodb.log.component != 'WRITE' && ctx.mongodb.log.component != 'ACCESS' | ||
- append: | ||
field: event.type | ||
value: error | ||
if: ctx.log.level == 'F' || ctx.log.level == 'E' | ||
- remove: | ||
field: | ||
- mongodb.log.t | ||
- mongodb.log.attr | ||
- mongodb.log.tags | ||
- mongodb.log.truncated | ||
- mongodb.log.size | ||
ignore_missing: true | ||
on_failure: | ||
- set: | ||
field: error.message | ||
value: '{{ _ingest.on_failure_message }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
description: Pipeline for parsing MongoDB logs in plaintext | ||
processors: | ||
- grok: | ||
field: message | ||
patterns: | ||
- '%{TIMESTAMP_ISO8601:mongodb.log.timestamp}%{SPACE}%{MONGO3_SEVERITY:log.level}%{SPACE}%{MONGO3_COMPONENT:mongodb.log.component}%{SPACE}(?:\[%{DATA:mongodb.log.context}\])?%{SPACE}%{GREEDYDATA:message}' | ||
ignore_missing: true | ||
- date: | ||
field: mongodb.log.timestamp | ||
target_field: '@timestamp' | ||
formats: | ||
- yyyy-MM-dd'T'HH:mm:ss.SSSZZ | ||
- remove: | ||
field: mongodb.log.timestamp | ||
- append: | ||
field: event.type | ||
value: access | ||
if: "ctx?.mongodb?.log?.component == 'ACCESS'" | ||
- append: | ||
field: event.type | ||
value: change | ||
if: "ctx?.mongodb?.log?.component == 'WRITE'" | ||
- append: | ||
field: event.type | ||
value: info | ||
if: "ctx?.mongodb?.log?.component != 'WRITE' && ctx?.mongodb?.log?.component != 'ACCESS'" | ||
- append: | ||
field: event.type | ||
value: error | ||
if: "ctx?.log?.level == 'F' || ctx?.log?.level == 'E'" | ||
on_failure: | ||
- set: | ||
field: error.message | ||
value: '{{ _ingest.on_failure_message }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
filebeat/module/mongodb/log/test/mongodb-ubuntu-4.4.4-json.log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{"t":{"$date":"2021-03-22T21:21:20.349+00:00"},"s":"I", "c":"STORAGE", "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"6150fe65a89c"}} | ||
{"t":{"$date":"2021-03-22T21:21:20.350+00:00"},"s":"I", "c":"CONTROL", "id":23403, "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.4","gitVersion":"8db30a63db1a9d84bdcad0c83369623f708e0397","openSSLVersion":"OpenSSL 1.1.1 11 Sep 2018","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu1804","distarch":"x86_64","target_arch":"x86_64"}}}} | ||
{"t":{"$date":"2021-03-22T21:21:26.240+00:00"},"s":"I", "c":"RECOVERY", "id":23987, "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}} | ||
{"t":{"$date":"2021-03-22T21:21:26.363+00:00"},"s":"I", "c":"STORAGE", "id":20320, "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"admin.system.version","uuidDisposition":"provided","uuid":{"uuid":{"$uuid":"b383f03c-b97c-4584-87ae-ab1b8ea399c3"}},"options":{"uuid":{"$uuid":"b383f03c-b97c-4584-87ae-ab1b8ea399c3"}}}} | ||
{"t":{"$date":"2021-03-22T21:21:26.410+00:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"admin.system.version","index":"_id_","commitTimestamp":{"$timestamp":{"t":0,"i":0}}}} | ||
{"t":{"$date":"2021-03-22T21:21:26.412+00:00"},"s":"I", "c":"COMMAND", "id":20459, "ctx":"initandlisten","msg":"Setting featureCompatibilityVersion","attr":{"newVersion":"4.4"}} | ||
{"t":{"$date":"2021-03-22T21:21:26.451+00:00"},"s":"I", "c":"FTDC", "id":20625, "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"/data/db/diagnostic.data"}} |
156 changes: 156 additions & 0 deletions
156
filebeat/module/mongodb/log/test/mongodb-ubuntu-4.4.4-json.log-expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
[ | ||
{ | ||
"@timestamp": "2021-03-22T21:21:20.349Z", | ||
"event.category": [ | ||
"database" | ||
], | ||
"event.dataset": "mongodb.log", | ||
"event.kind": "event", | ||
"event.module": "mongodb", | ||
"event.type": [ | ||
"info" | ||
], | ||
"fileset.name": "log", | ||
"input.type": "log", | ||
"log.level": "I", | ||
"log.offset": 0, | ||
"message": "{\"t\":{\"$date\":\"2021-03-22T21:21:20.349+00:00\"},\"s\":\"I\", \"c\":\"STORAGE\", \"id\":4615611, \"ctx\":\"initandlisten\",\"msg\":\"MongoDB starting\",\"attr\":{\"pid\":1,\"port\":27017,\"dbPath\":\"/data/db\",\"architecture\":\"64-bit\",\"host\":\"6150fe65a89c\"}}", | ||
"mongodb.log.component": "STORAGE", | ||
"mongodb.log.context": "initandlisten", | ||
"mongodb.log.id": 4615611, | ||
"mongodb.log.msg": "MongoDB starting", | ||
"service.type": "mongodb" | ||
}, | ||
{ | ||
"@timestamp": "2021-03-22T21:21:20.350Z", | ||
"event.category": [ | ||
"database" | ||
], | ||
"event.dataset": "mongodb.log", | ||
"event.kind": "event", | ||
"event.module": "mongodb", | ||
"event.type": [ | ||
"info" | ||
], | ||
"fileset.name": "log", | ||
"input.type": "log", | ||
"log.level": "I", | ||
"log.offset": 231, | ||
"message": "{\"t\":{\"$date\":\"2021-03-22T21:21:20.350+00:00\"},\"s\":\"I\", \"c\":\"CONTROL\", \"id\":23403, \"ctx\":\"initandlisten\",\"msg\":\"Build Info\",\"attr\":{\"buildInfo\":{\"version\":\"4.4.4\",\"gitVersion\":\"8db30a63db1a9d84bdcad0c83369623f708e0397\",\"openSSLVersion\":\"OpenSSL 1.1.1 11 Sep 2018\",\"modules\":[],\"allocator\":\"tcmalloc\",\"environment\":{\"distmod\":\"ubuntu1804\",\"distarch\":\"x86_64\",\"target_arch\":\"x86_64\"}}}}", | ||
"mongodb.log.component": "CONTROL", | ||
"mongodb.log.context": "initandlisten", | ||
"mongodb.log.id": 23403, | ||
"mongodb.log.msg": "Build Info", | ||
"service.type": "mongodb" | ||
}, | ||
{ | ||
"@timestamp": "2021-03-22T21:21:26.240Z", | ||
"event.category": [ | ||
"database" | ||
], | ||
"event.dataset": "mongodb.log", | ||
"event.kind": "event", | ||
"event.module": "mongodb", | ||
"event.type": [ | ||
"info" | ||
], | ||
"fileset.name": "log", | ||
"input.type": "log", | ||
"log.level": "I", | ||
"log.offset": 621, | ||
"message": "{\"t\":{\"$date\":\"2021-03-22T21:21:26.240+00:00\"},\"s\":\"I\", \"c\":\"RECOVERY\", \"id\":23987, \"ctx\":\"initandlisten\",\"msg\":\"WiredTiger recoveryTimestamp\",\"attr\":{\"recoveryTimestamp\":{\"$timestamp\":{\"t\":0,\"i\":0}}}}", | ||
"mongodb.log.component": "RECOVERY", | ||
"mongodb.log.context": "initandlisten", | ||
"mongodb.log.id": 23987, | ||
"mongodb.log.msg": "WiredTiger recoveryTimestamp", | ||
"service.type": "mongodb" | ||
}, | ||
{ | ||
"@timestamp": "2021-03-22T21:21:26.363Z", | ||
"event.category": [ | ||
"database" | ||
], | ||
"event.dataset": "mongodb.log", | ||
"event.kind": "event", | ||
"event.module": "mongodb", | ||
"event.type": [ | ||
"info" | ||
], | ||
"fileset.name": "log", | ||
"input.type": "log", | ||
"log.level": "I", | ||
"log.offset": 826, | ||
"message": "{\"t\":{\"$date\":\"2021-03-22T21:21:26.363+00:00\"},\"s\":\"I\", \"c\":\"STORAGE\", \"id\":20320, \"ctx\":\"initandlisten\",\"msg\":\"createCollection\",\"attr\":{\"namespace\":\"admin.system.version\",\"uuidDisposition\":\"provided\",\"uuid\":{\"uuid\":{\"$uuid\":\"b383f03c-b97c-4584-87ae-ab1b8ea399c3\"}},\"options\":{\"uuid\":{\"$uuid\":\"b383f03c-b97c-4584-87ae-ab1b8ea399c3\"}}}}", | ||
"mongodb.log.component": "STORAGE", | ||
"mongodb.log.context": "initandlisten", | ||
"mongodb.log.id": 20320, | ||
"mongodb.log.msg": "createCollection", | ||
"service.type": "mongodb" | ||
}, | ||
{ | ||
"@timestamp": "2021-03-22T21:21:26.410Z", | ||
"event.category": [ | ||
"database" | ||
], | ||
"event.dataset": "mongodb.log", | ||
"event.kind": "event", | ||
"event.module": "mongodb", | ||
"event.type": [ | ||
"info" | ||
], | ||
"fileset.name": "log", | ||
"input.type": "log", | ||
"log.level": "I", | ||
"log.offset": 1167, | ||
"message": "{\"t\":{\"$date\":\"2021-03-22T21:21:26.410+00:00\"},\"s\":\"I\", \"c\":\"INDEX\", \"id\":20345, \"ctx\":\"initandlisten\",\"msg\":\"Index build: done building\",\"attr\":{\"buildUUID\":null,\"namespace\":\"admin.system.version\",\"index\":\"_id_\",\"commitTimestamp\":{\"$timestamp\":{\"t\":0,\"i\":0}}}}", | ||
"mongodb.log.component": "INDEX", | ||
"mongodb.log.context": "initandlisten", | ||
"mongodb.log.id": 20345, | ||
"mongodb.log.msg": "Index build: done building", | ||
"service.type": "mongodb" | ||
}, | ||
{ | ||
"@timestamp": "2021-03-22T21:21:26.412Z", | ||
"event.category": [ | ||
"database" | ||
], | ||
"event.dataset": "mongodb.log", | ||
"event.kind": "event", | ||
"event.module": "mongodb", | ||
"event.type": [ | ||
"info" | ||
], | ||
"fileset.name": "log", | ||
"input.type": "log", | ||
"log.level": "I", | ||
"log.offset": 1435, | ||
"message": "{\"t\":{\"$date\":\"2021-03-22T21:21:26.412+00:00\"},\"s\":\"I\", \"c\":\"COMMAND\", \"id\":20459, \"ctx\":\"initandlisten\",\"msg\":\"Setting featureCompatibilityVersion\",\"attr\":{\"newVersion\":\"4.4\"}}", | ||
"mongodb.log.component": "COMMAND", | ||
"mongodb.log.context": "initandlisten", | ||
"mongodb.log.id": 20459, | ||
"mongodb.log.msg": "Setting featureCompatibilityVersion", | ||
"service.type": "mongodb" | ||
}, | ||
{ | ||
"@timestamp": "2021-03-22T21:21:26.451Z", | ||
"event.category": [ | ||
"database" | ||
], | ||
"event.dataset": "mongodb.log", | ||
"event.kind": "event", | ||
"event.module": "mongodb", | ||
"event.type": [ | ||
"info" | ||
], | ||
"fileset.name": "log", | ||
"input.type": "log", | ||
"log.level": "I", | ||
"log.offset": 1617, | ||
"message": "{\"t\":{\"$date\":\"2021-03-22T21:21:26.451+00:00\"},\"s\":\"I\", \"c\":\"FTDC\", \"id\":20625, \"ctx\":\"initandlisten\",\"msg\":\"Initializing full-time diagnostic data capture\",\"attr\":{\"dataDirectory\":\"/data/db/diagnostic.data\"}}", | ||
"mongodb.log.component": "FTDC", | ||
"mongodb.log.context": "initandlisten", | ||
"mongodb.log.id": 20625, | ||
"mongodb.log.msg": "Initializing full-time diagnostic data capture", | ||
"service.type": "mongodb" | ||
} | ||
] |