Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added alldb monitor

  • Loading branch information...
commit a3b2b89fd56d5f66cd568fd0cced9790cb9c263f 1 parent 3a0274a
Satoshi Miyauchi bibrost authored
94 mongo_collcount_alldb
... ... @@ -0,0 +1,94 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +# vim: set sts=4 sw=4 encoding=utf-8
  4 +
  5 +# Copyright (c) 2010, Rene Jochum
  6 +# All rights reserved.
  7 +#
  8 +# Redistribution and use in source and binary forms, with or without
  9 +# modification, are permitted provided that the following conditions are met:
  10 +# * Redistributions of source code must retain the above copyright
  11 +# notice, this list of conditions and the following disclaimer.
  12 +# * Redistributions in binary form must reproduce the above copyright
  13 +# notice, this list of conditions and the following disclaimer in the
  14 +# documentation and/or other materials provided with the distribution.
  15 +# * Neither the name of the Rene Jochum nor the
  16 +# names of its contributors may be used to endorse or promote products
  17 +# derived from this software without specific prior written permission.
  18 +#
  19 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21 +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22 +# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  23 +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25 +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26 +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27 +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28 +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29 +
  30 +
  31 +from pymongo import Connection
  32 +
  33 +settings_host = '127.0.0.1'
  34 +settings_port = 27017
  35 +settings_db = 'mydb'
  36 +
  37 +
  38 +def getCollstats():
  39 + con = Connection(settings_host, int(settings_port), slave_okay=True)
  40 +
  41 + stats_tmp = {}
  42 + for dbname in con.database_names():
  43 + db = con[dbname]
  44 + for coll in db.collection_names():
  45 + if coll.startswith('system.'):
  46 + continue
  47 + stats = db.command("collstats", coll)
  48 + collname = coll.replace('.', '_')
  49 + if not stats_tmp.has_key(collname):
  50 + stats_tmp[collname] = 0
  51 + stats_tmp[collname] += long(stats['count'])
  52 +
  53 + con.disconnect()
  54 +
  55 + for collname, stats in sorted(stats_tmp.items()):
  56 + yield ("%s_count" % collname, stats,)
  57 +
  58 +
  59 +def doData():
  60 + for coll, stats in getCollstats():
  61 + print "%s.value %s" % (coll, stats)
  62 +
  63 +
  64 +def doConfig():
  65 +
  66 + print "graph_title MongoDB total collection count"
  67 + print "graph_args --base 1000 -l 0"
  68 + print "graph_vlabel documents"
  69 + print "graph_category MongoDB"
  70 + print "graph_total total"
  71 +
  72 + for k,v in getCollstats():
  73 + print "%s.label %s" % (k, k)
  74 + print "%s.min 0" % k
  75 + print "%s.draw LINE1" % k
  76 +
  77 +
  78 +if __name__ == "__main__":
  79 + from sys import argv
  80 + from os import environ
  81 +
  82 + # Could be done by a for loop
  83 + # but i think if's are faster
  84 + if 'HOST' in environ:
  85 + settings_host = environ['HOST']
  86 + if 'PORT' in environ:
  87 + settings_port = environ['PORT']
  88 + if 'DB' in environ:
  89 + settings_db = environ['DB']
  90 +
  91 + if len(argv) > 1 and argv[1] == "config":
  92 + doConfig()
  93 + else:
  94 + doData()
99 mongo_collsize_alldb
... ... @@ -0,0 +1,99 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +# vim: set sts=4 sw=4 encoding=utf-8
  4 +
  5 +# Copyright (c) 2010, Rene Jochum
  6 +# All rights reserved.
  7 +#
  8 +# Redistribution and use in source and binary forms, with or without
  9 +# modification, are permitted provided that the following conditions are met:
  10 +# * Redistributions of source code must retain the above copyright
  11 +# notice, this list of conditions and the following disclaimer.
  12 +# * Redistributions in binary form must reproduce the above copyright
  13 +# notice, this list of conditions and the following disclaimer in the
  14 +# documentation and/or other materials provided with the distribution.
  15 +# * Neither the name of the Rene Jochum nor the
  16 +# names of its contributors may be used to endorse or promote products
  17 +# derived from this software without specific prior written permission.
  18 +#
  19 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21 +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22 +# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  23 +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25 +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26 +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27 +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28 +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29 +
  30 +
  31 +from pymongo import Connection
  32 +
  33 +settings_host = '127.0.0.1'
  34 +settings_port = 27017
  35 +settings_db = 'mydb'
  36 +settings_collection = 'things'
  37 +settings_fields = {'totalIndexSize': 'index', 'storageSize': 'storage', 'size': 'data'}
  38 +
  39 +
  40 +def getCollstats():
  41 + con = Connection(settings_host, int(settings_port), slave_okay=True)
  42 +
  43 + stats_tmp = {}
  44 + for dbname in con.database_names():
  45 + db = con[dbname]
  46 + for coll in db.collection_names():
  47 + if coll.startswith('system.'):
  48 + continue
  49 + stats = db.command("collstats", coll)
  50 + collname = coll.replace('.', '_')
  51 + if not stats_tmp.has_key(collname):
  52 + stats_tmp[collname] = 0
  53 + stats_tmp[collname] += long(stats['size'])
  54 + con.disconnect()
  55 +
  56 + for collname, stats in sorted(stats_tmp.items()):
  57 + yield ("%s_size" % collname, stats,)
  58 +
  59 +
  60 +def doData():
  61 + for coll, stats in getCollstats():
  62 + print "%s.value %s" % (coll, stats)
  63 +
  64 +
  65 +def doConfig():
  66 +
  67 + print "graph_title MongoDB total collection size"
  68 + print "graph_args --base 1024 -l 0"
  69 + print "graph_vlabel Kb"
  70 + print "graph_category MongoDB"
  71 + print "graph_total total"
  72 +
  73 + for k,v in getCollstats():
  74 + print "%s.label %s" % (k, k)
  75 + print "%s.min 0" % k
  76 + print "%s.draw LINE1" % k
  77 +
  78 +
  79 +if __name__ == "__main__":
  80 + from sys import argv
  81 + from os import environ
  82 +
  83 + # Could be done by a for loop
  84 + # but i think if's are faster
  85 + if 'HOST' in environ:
  86 + settings_host = environ['HOST']
  87 + if 'PORT' in environ:
  88 + settings_port = environ['PORT']
  89 + if 'DB' in environ:
  90 + settings_db = environ['DB']
  91 +
  92 + sp = argv[0].split('_')
  93 + if len(sp) > 1:
  94 + settings_collection = sp[-1]
  95 +
  96 + if len(argv) > 1 and argv[1] == "config":
  97 + doConfig()
  98 + else:
  99 + doData()
94 mongo_indexsize_alldb
... ... @@ -0,0 +1,94 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +# vim: set sts=4 sw=4 encoding=utf-8
  4 +
  5 +# Copyright (c) 2010, Rene Jochum
  6 +# All rights reserved.
  7 +#
  8 +# Redistribution and use in source and binary forms, with or without
  9 +# modification, are permitted provided that the following conditions are met:
  10 +# * Redistributions of source code must retain the above copyright
  11 +# notice, this list of conditions and the following disclaimer.
  12 +# * Redistributions in binary form must reproduce the above copyright
  13 +# notice, this list of conditions and the following disclaimer in the
  14 +# documentation and/or other materials provided with the distribution.
  15 +# * Neither the name of the Rene Jochum nor the
  16 +# names of its contributors may be used to endorse or promote products
  17 +# derived from this software without specific prior written permission.
  18 +#
  19 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21 +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22 +# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  23 +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25 +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26 +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27 +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28 +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29 +
  30 +
  31 +from pymongo import Connection
  32 +
  33 +settings_host = '127.0.0.1'
  34 +settings_port = 27017
  35 +settings_db = 'mydb'
  36 +
  37 +
  38 +def getCollstats():
  39 + con = Connection(settings_host, int(settings_port), slave_okay=True)
  40 +
  41 + stats_tmp = {}
  42 + for dbname in con.database_names():
  43 + db = con[dbname]
  44 + for coll in db.collection_names():
  45 + if coll.startswith('system.'):
  46 + continue
  47 + stats = db.command("collstats", coll)
  48 + collname = coll.replace('.', '_')
  49 + if not stats_tmp.has_key(collname):
  50 + stats_tmp[collname] = 0
  51 + stats_tmp[collname] += long(stats['totalIndexSize'])
  52 +
  53 + con.disconnect()
  54 +
  55 + for collname, stats in sorted(stats_tmp.items()):
  56 + yield ("%s_size" % collname, stats,)
  57 +
  58 +
  59 +def doData():
  60 + for coll, stats in getCollstats():
  61 + print "%s.value %s" % (coll, stats)
  62 +
  63 +
  64 +def doConfig():
  65 +
  66 + print "graph_title MongoDB toral collection index sizes"
  67 + print "graph_args --base 1024 -l 0"
  68 + print "graph_vlabel Kb"
  69 + print "graph_category MongoDB"
  70 + print "graph_total total"
  71 +
  72 + for k,v in getCollstats():
  73 + print "%s.label %s" % (k, k)
  74 + print "%s.min 0" % k
  75 + print "%s.draw LINE1" % k
  76 +
  77 +
  78 +if __name__ == "__main__":
  79 + from sys import argv
  80 + from os import environ
  81 +
  82 + # Could be done by a for loop
  83 + # but i think if's are faster
  84 + if 'HOST' in environ:
  85 + settings_host = environ['HOST']
  86 + if 'PORT' in environ:
  87 + settings_port = environ['PORT']
  88 + if 'DB' in environ:
  89 + settings_db = environ['DB']
  90 +
  91 + if len(argv) > 1 and argv[1] == "config":
  92 + doConfig()
  93 + else:
  94 + doData()
93 mongo_storagesize_alldb
... ... @@ -0,0 +1,93 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +# vim: set sts=4 sw=4 encoding=utf-8
  4 +
  5 +# Copyright (c) 2010, Rene Jochum
  6 +# All rights reserved.
  7 +#
  8 +# Redistribution and use in source and binary forms, with or without
  9 +# modification, are permitted provided that the following conditions are met:
  10 +# * Redistributions of source code must retain the above copyright
  11 +# notice, this list of conditions and the following disclaimer.
  12 +# * Redistributions in binary form must reproduce the above copyright
  13 +# notice, this list of conditions and the following disclaimer in the
  14 +# documentation and/or other materials provided with the distribution.
  15 +# * Neither the name of the Rene Jochum nor the
  16 +# names of its contributors may be used to endorse or promote products
  17 +# derived from this software without specific prior written permission.
  18 +#
  19 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21 +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22 +# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  23 +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25 +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26 +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27 +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28 +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29 +
  30 +
  31 +from pymongo import Connection
  32 +
  33 +settings_host = '127.0.0.1'
  34 +settings_port = 27017
  35 +settings_db = 'mydb'
  36 +
  37 +
  38 +def getCollstats():
  39 + con = Connection(settings_host, int(settings_port), slave_okay=True)
  40 +
  41 + stats_tmp = {}
  42 + for dbname in con.database_names():
  43 + db = con[dbname]
  44 + for coll in db.collection_names():
  45 + if coll.startswith('system.'):
  46 + continue
  47 + stats = db.command("collstats", coll)
  48 + collname = coll.replace('.', '_')
  49 + if not stats_tmp.has_key(collname):
  50 + stats_tmp[collname] = 0
  51 + stats_tmp[collname] += long(stats['storageSize'])
  52 + con.disconnect()
  53 +
  54 + for collname, stats in sorted(stats_tmp.items()):
  55 + yield ("%s_size" % collname, stats,)
  56 +
  57 +
  58 +def doData():
  59 + for coll, stats in getCollstats():
  60 + print "%s.value %s" % (coll, stats)
  61 +
  62 +
  63 +def doConfig():
  64 +
  65 + print "graph_title MongoDB total storage sizes"
  66 + print "graph_args --base 1024 -l 0"
  67 + print "graph_vlabel Kb"
  68 + print "graph_category MongoDB"
  69 + print "graph_total total"
  70 +
  71 + for k,v in getCollstats():
  72 + print "%s.label %s" % (k, k)
  73 + print "%s.min 0" % k
  74 + print "%s.draw LINE1" % k
  75 +
  76 +
  77 +if __name__ == "__main__":
  78 + from sys import argv
  79 + from os import environ
  80 +
  81 + # Could be done by a for loop
  82 + # but i think if's are faster
  83 + if 'HOST' in environ:
  84 + settings_host = environ['HOST']
  85 + if 'PORT' in environ:
  86 + settings_port = environ['PORT']
  87 + if 'DB' in environ:
  88 + settings_db = environ['DB']
  89 +
  90 + if len(argv) > 1 and argv[1] == "config":
  91 + doConfig()
  92 + else:
  93 + doData()

0 comments on commit a3b2b89

Please sign in to comment.
Something went wrong with that request. Please try again.