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

Add support for reading structured logs (aka logv2) from MongoDB 4.4+ #806

Open
stennie opened this issue Jun 15, 2020 · 13 comments
Open

Add support for reading structured logs (aka logv2) from MongoDB 4.4+ #806

stennie opened this issue Jun 15, 2020 · 13 comments
Assignees
Milestone

Comments

@stennie
Copy link
Collaborator

stennie commented Jun 15, 2020

Starting in the MongoDB 4.4 release, mongod and mongos output all log messages in a new structured JSON format which is designed to be parseable using standard JSON libraries. JSON tools such as jq and mongoimport can also be used.

@stennie stennie added this to the 1.7.0 milestone Jun 15, 2020
@stennie stennie self-assigned this Jun 15, 2020
@nanangarsyad-mt
Copy link

Hi,

Thanks for this amazing tools.
Unfortunately, I'm really in need of mplotqueries, but my log already in a structured format (i'm using mongo 4.4). Is there any temporary workaround to solve this issue ?
Like for example, a way to convert a structured log into the old log, so mplotqueries could read the log again.

Best regards,

@stennie
Copy link
Collaborator Author

stennie commented Sep 7, 2020

@nanangarsyad-mt I'm not aware of a trivial conversion of JSON logs to the legacy log format, but that's the general scope of this improvement suggestion. Since MongoDB 4.4+ logs are in JSON format you can likely work out conversion using a JSON library or tool like jq, but some trial and error will be required to match the previous log output expected by mplotqueries. The MongoDB 4.4 documentation on log messages has some helpful examples of working with jq.

If you do work out an approach, please comment here with more info.

I also suggest having a look at the Keyhole project, which aims to provide more actionable insights than mtools including performance analytics, tuning, and monitoring. Keyhole supports legacy MongoDB log formats, 4.4+ structured logs, and also the compressed FTDC (Full Time Diagnostic data Capture) diagnostic data from MongoDB 3.2+.

There's a good series of blog posts with more info from Keyhole's creator: Peek at your MongoDB Clusters like a Pro with Keyhole Part 1, Part 2, and Part 3.

@derwaldgeist
Copy link

I am using MongoDB on an ATLAS cluster and was pretty surprised mtools cannot handle its default log format. I guess the issue is about addressing this?

@NareshBavisetty
Copy link

NareshBavisetty commented Oct 22, 2021

@stennie,

I am using Mongodb atlas, tried to convert the log files to old format it did but m tools unable to read it!

sed -E 's/^{"t":{"$date":"|"},"s":"|",[ ]{0,9}"c":"|",[ ]{0,9}"id":|,[ ]{0,9}"ctx":"|","msg":|}$/ /g' yourMongod4_4.log > mongodb.log

@stennie stennie assigned iamKushagra and unassigned stennie Dec 3, 2021
@stennie stennie modified the milestones: 1.7.0, 1.8.0 Jan 5, 2022
@itstin
Copy link

itstin commented Mar 31, 2022

Did we get any fix on this ?

@SteveH-US
Copy link

SteveH-US commented Jul 7, 2022

Having used keyhole, I can say that it attempts to be much more than what the log analysis part of mtools did, but without the features many like about mtools, including plotting queries and getting list of query shapes. The point is, that keyhole's target consumer appears to be someone like Ken, a MongoDB consultant, and not directly to someone like us, customers using MongoDB.

Additionally, having read through the three blog post, keyhole's features does not include log analysis.

@simagix
Copy link

simagix commented Oct 21, 2022

@SteveH-US, the keyhole log analytics blog is first available in the Peek at your MongoDB Clusters like a Pro with Keyhole Part 1. Additional blogs about the feature can be found at Feel The Pulse of Mongo and Streamline Keyhole and Maobi Reports Creation. Keyhole prints out a summary, but to get a better analytics report, use it with Maobi. The latest Moabi also plots ops in a chart.

@SteveH-US
Copy link

Hi Ken,

Having read through the three blog post, keyhole's features does not include log analysis.

@stennie stennie self-assigned this Oct 29, 2022
@inetufo
Copy link

inetufo commented Dec 7, 2022

hope to support

@simagix
Copy link

simagix commented Feb 13, 2023

@SteveH-US , I created Hatchet for JSON log processing, and it includes an audit page to report exceptions and usages as well as other reports and charts. A blog is also available. Ideas and suggestions are welcome.

@jhyearsley
Copy link

Any updates on this? Why not just hack it and use convert-json-logs-legacy as a dependency to handle the conversion

@jacobemcken
Copy link

jacobemcken commented Jul 2, 2023

Any updates on this? Why not just hack it and use convert-json-logs-legacy as a dependency to handle the conversion

convert-json-logs-to-legacy seems like a very nice workaround 👍

It took me a little while to figure out why I got the error:

bash: ./generate_mplot_logs.py: cannot execute: required file not found

The first line in the file generate_mplot_logs.py points to /usr/local/bin/python3 which I don't have.
I changed the line to point to where I have Python: /usr/bin/python3

I have now successfully parsed the converted content of a Mongo JSON file, with mloginfo.

@ghost
Copy link

ghost commented Jul 6, 2023

I've tried to use convert-json-logs-to-legacy but when I attempt to plot queries from a resulting log it shows no data for r or w, other mplotqueries modes like numYields, nScanned work fine:

>mplotqueries legacy.log --logscale --yaxis r


no data to plot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests