MongoDB create report for hour wise

we have 2 requirements:

  1. How to create report with Mongotop and mongostat generating report either excel sheet or csv file and also those reports export into emails.

  2. Hour wise Read and write ,connections create one report this one also export into emails like below table sample format.

| Date/Time | Reads| writes| Connections|
|03/05/2020:1:28:00| 1 | 0 | 0|
|03/05/2020:1:40:00| 2 | 5 | 9|

can you please anybody know how to do above requirement script or available commands in mongoDB please let me know.

@hari_dba A more typical approach would be to use a monitoring platform to collect and chart ongoing metrics. For example, MongoDB Cloud Manager for detailed metrics or Free Monitoring for basic metrics. Trends in metrics are generally better visualised in charts rather than tabular text format.

If you want to write something custom for metric collection, refer to Database Commands Used by Monitoring in Cloud Manager for relevant diagnostic & administrative database commands. These are the same commands used by monitoring agents and tools like mongotop/mongostat.

Alternatively, you could write a cron saving the output of mongotop & mongostat (perhaps using the --json option).

A downside of using command line tools is that you will be sampling at a certain rate (for example, an interval in seconds). If you use database commands like serverStatus you can get counters that will allow you to derive a better picture of activity over time. For example, opcounters are a cumulative count of database operations by type since the mongod instance last started.

Regards,
Stennie

2 Likes

Hi Stennie,

Thanks for reply…

Can you please provide script for output of Mongotop and Mongostat to .cs file or excel format and also that output will be export into direct emails, if it possible please tell me that solution

How to take output mongotop and mongostat by using --json option this option display output horizontal wise and how to generate into .CS file excel sheet export into email.

If this is your preferred approach, you’ll have to find or create a solution.

If your goal is metrics & monitoring, I’d recommend using an existing monitoring solution such as MongoDB Cloud Manager or Free Monitoring.

JSON output will give you structured documents that you can save or manipulate programatically. Writing a program to work with JSON and Excel files or email is not specific to MongoDB. You need to look into available libraries and tooling available in your preferred programming language.

Regards,
Stennie

1 Like

I believe @Stennie answered your question perfectly and showed you the best solution, but I also believe there are so many people out there like “you”, don’t know how to process JSON.

So, here we go; I wrote a script extends mongotop, and filter/format output of it; check it out at https://github.com/anars/mongodb-dba-tools

How to install : (these instructions for linux and macos)

First of all, make sure you have NodeJS is install and up-to-date on your system. to check type;

node --version

Secondly, make sure you have MongoTop is install and up-to-date on your system. to check type;

mongotop --version

then, download the script

curl -o mongotopx https://raw.githubusercontent.com/anars/mongodb-dba-tools/master/build/mongotopx

Change the permission

chmod +x mongotopx

and finally type

./mongotopx --help

for parameters

In your case, same parameters you used for mongotop, and add these 2 parameters --csv --delimiter=\|

for example;

./mongotopx --authenticationDatabase=admin -u admin -p admin --csv --delimiter=\|

and output will be something like this

timestamp|admin.system.users (total time)|admin.system.users (total count)|admin.system.users (read time)|admin.system.users (read count)|admin.system.users (write time)|admin.system.users (write count)
2020-03-12T16:49:35.262468992Z|0|0|0|0|0|0
2020-03-12T16:49:36.267576976Z|0|0|0|0|0|0
2020-03-12T16:49:37.269237744Z|0|0|0|0|0|0
2020-03-12T16:49:38.271095919Z|0|0|0|0|0|0

p.s. I will document other feature later this weekend, and put to github. And (if have a time) I may implement a script for mongostat.

2 Likes