Reputation: 11
I am using mongodb and for finding the statistics I am using the command mongostat --host localhost --port 27017 --all in which i am getting the statistics. My problem is that I am using the same command in writing inside a script and I want the same to stop automatically after desired time say 5 seconds like giving the time interval. Please guide me.
Upvotes: 1
Views: 582
Reputation: 1
mongostat by default gets one iteration per second. You can use the "--rowcount 5" option which will terminate mongostat after the 5th iteration. I am doing a similar thing but my iteration runs only once every 60 seconds and inserts the output into a separate db.
Upvotes: 0
Reputation: 65393
mongostat
has a -n
(aka --rowcount
) option you can use:
-n [ --rowcount ] arg (=0) number of stats lines to print (0 for indefinite)
So if you want to get 5 seconds of stats (using the default interval of 1 second):
mongostat --host localhost --port 27017 --all -n 5
Or more concisely, if you are using the default host and port:
mongostat --all -n 5
To see all command line options for your version of mongostat
:
mongostat --help
Upvotes: 1