Skip to content

Commit

Permalink
feat(plugin): Added Mongodb log plugin (#374)
Browse files Browse the repository at this point in the history
* Added mongodb plugin

Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>

* Added multiple logging paths to mongo

Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>

* Fixedup mondb plugin

Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>

* Added example log line to mongodb plugin

Signed-off-by: Corbin Phelps <corbin.phelps@bluemedora.com>
  • Loading branch information
Corbin Phelps authored Apr 27, 2022
1 parent 23d164f commit 93de7df
Showing 1 changed file with 136 additions and 0 deletions.
136 changes: 136 additions & 0 deletions plugins/mongodb_logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
version: 0.0.1
title: MongoDB
description: Log parser for MongoDB
parameters:
- name: log_paths
type: "[]string"
default:
- "/var/log/mongodb/mongodb.log*"
- "/var/log/mongodb/mongod.log*"
- name: start_at
type: string
supported:
- beginning
- end
default: end
template: |
receivers:
filelog:
include:
{{ range $fp := .log_paths }}
- '{{ $fp }}'
{{end}}
exclude:
{{ range $fp := .log_paths }}
- '{{ $fp }}*.gz'
{{end}}
start_at: {{ .start_at }}
operators:
- type: router
default: legacy_parser
routes:
- expr: 'body matches "^{.*}$|^{.*}\\n$"'
output: 4_4_parser
- id: legacy_parser
type: regex_parser
regex: '^(?P<timestamp>\S+)\s+(?P<severity>\w+)\s+(?P<component>[\w-]+)\s+\[(?P<context>\S+)\]\s+(?P<message>.*)$'
timestamp:
parse_from: attributes.timestamp
#2019-02-06T09:22:43.967-0500
layout: '%Y-%m-%dT%H:%M:%S.%f%z'
severity:
parse_from: attributes.severity
mapping:
fatal: F
error: E
warn: W
info: I
debug:
- D
- D1
- D2
- D3
- D4
- D5
output: add_log_type
# Example log line:
# {"t":{"$date":"2022-04-26T16:15:44.876+00:00"},"s":"I", "c":"INDEX", "id":20345, "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"config.system.sessions","index":"lsidTTLIndex","commitTimestamp":null}}
- id: 4_4_parser
type: json_parser
parse_from: body
timestamp:
parse_from: attributes.t.$date
#2020-11-03T14:24:07.436-05:00
layout: '%Y-%m-%dT%H:%M:%S.%f%j'
severity:
parse_from: attributes.s
mapping:
fatal: F
error: E
warn: W
info: I
debug:
- D
- D1
- D2
- D3
- D4
- D5
output: move_component
# Commented out remove operatore out and output until remove operator is added in.
# Tracking in PR https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/9545
#output: remove_t
# - id: remove_t
# type: remove
# field: attributes.t
- id: move_component
type: move
from: attributes.c
to: attributes.component
- id: move_context
type: move
from: attributes.ctx
to: attributes.context
- id: move_message
type: move
from: attributes.msg
to: attributes.message
# When message is 'WiredTiger message', data.attr.message
# always exists, and should be promoted to message
- id: wiredtiger_router
type: router
default: add_log_type
routes:
- expr: 'attributes.message == "WiredTiger message"'
output: move_wiredtiger_type
- id: move_wiredtiger_type
type: move
from: attributes.message
to: attributes.message_type
output: move_wiredtiger_msg
- id: move_wiredtiger_msg
type: move
from: attributes.attr.message
to: attributes.message
output: add_log_type
- id: add_log_type
type: add
field: 'attributes.log_type'
value: 'mongodb'
service:
pipelines:
logs:
receivers:
- filelog

0 comments on commit 93de7df

Please sign in to comment.