0
votes

I have a sharded cluster which is set up , Since my data is seamlessly growing , I need to keep monitoring the size of data and add new shards to the cluster .

Is there a command that I could use to know how much size is utilized in each sharded server , at any point of time .

For eg . lets say I have a database , and my show dbs command from mongos console shows like this

mongos> show dbs
company 0.375GB
config  0.046875GB
test    0.0625GB

I want to know how much data is used in each shard servers . for company database .

my implemented architecture is as follows

I have a single database sharded , in which each collection is sharded . 3 shard servers running mongod instances 1 server running mongos 1 server running config instance

My whole application layer is talking to mongos directly .

I need to know this because , I am planning to build a cron which checks the available size of the shard server and if it exceeds some amount it will send a notification to administrator to show some attention .

Thanks in advance for responding to this post

2
After digging in the mongo documentation , I could get a command which I could run from mongos console to know the size distribution of shards . it is db.collection_name.stats() , but The same I want run and get from php in my cron please let me know if any one has done that from php , I am using zend shanty library for in the cronAravind.HU

2 Answers

1
votes

After posting in the mongoDB user group , I got the solution on how we need to do this and what commands that could be used

Commands

To know about space utilization of a particular DB in each sharded server we have to use

db.stats() 

to know about space utilization of a particular Collection in each sharded server we have to use

db.<collectionname>.stats()

Now to use it in the php daemon/cron I could call these commands using php mongo driver

$con= new Mongo()

$stats=$con->dbName->command(array('dbStats' => 1));  // for db.stats()

$stats=$con->dbName->command(array('collStats' => 'collection_name'));

Still I couldn't find any method to execute such commands from Zend shanty mongo but I could use default PHP pecl mongo db driver to achieve this

Thank you all for responding to this post

0
votes

There are general monitoring solutions for that (nagios, zabbix, etc). They monitor many parameters of your machines and can be set up to send alerts in certain situations. You don't need to reinvent the wheel.

Such general solution can also warn you if you're running out of space on an app server (because its logs take all the space). Your specialized mongodb cron job won't be able to do that.