Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): Added Mongodb log plugin #374

Merged
merged 4 commits into from
Apr 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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