Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how long was a mongo instance running

Tags:

mongodb

ubuntu

I have MongoDb running on the machine on Ubuntu 10.04.4 LTS

I there a way to find for how long was it running without restarts without accessing mongo log files

like image 791
Salvador Dali Avatar asked Nov 14 '12 12:11

Salvador Dali


People also ask

How do I know if MongoDB is instance running?

systemctl status mongod: Displays the same status of MongoDB service as like above command as shown in figure 1. pgrep mongo: Prints the process ID of running mongo instance. pgrep command looks through the list of running processes and list down the process ids based on name.

Is a mongod instance already running?

Can you check if an instance of mongod is already running? On *nix systems, you can run ps -eaf | grep mongod to find out the process id of running mongod. Also, check whether the /data/db directory is already created. If created, check the permissions whether you can write/read data.

How do I view MongoDB logs?

MongoDB logs can be found in the MongoDB log files at /var/log/mongodb/mongodb. log. If you can't find the log files from this location, you can check the mongodb. conf.

What is a mongo instance?

For a sharded cluster, the mongos instances provide the interface between the client applications and the sharded cluster. The mongos instances route queries and write operations to the shards. From the perspective of the application, a mongos instance behaves identically to any other MongoDB instance.


2 Answers

In mongo shell

db.serverStatus().uptime

This will print the uptime with seconds

And you can use the following:

// minutes
db.serverStatus().uptime / 60

// hours
db.serverStatus().uptime / 3600

// days
db.serverStatus().uptime / 86400

A more convenient method:

mongo --quiet --eval "db.serverStatus().uptime"
like image 124
Chien-Wei Huang Avatar answered Oct 24 '22 18:10

Chien-Wei Huang


If you can, try:

ps -ef

it works for me. You get the STIME (start time) field for all processes, including mongodb.

I get something like

my_user_id 12853     1  0 Nov13 pts/1    00:00:00 /bin/bash ./bin/start_mongodb_mongod.sh
like image 44
Pixou Avatar answered Oct 24 '22 20:10

Pixou