Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1730406
  • 博文数量: 150
  • 博客积分: 660
  • 博客等级: 上士
  • 技术积分: 2480
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-08 11:39
文章分类

全部博文(150)

文章存档

2019年(4)

2018年(36)

2017年(53)

2016年(7)

2015年(3)

2014年(3)

2013年(27)

2012年(2)

2011年(1)

2006年(1)

2005年(13)

分类: NOSQL

2019-03-07 11:17:38

输出mongodb所有库中各表的大小的shell

环境

  • mongodb 3.4.4
  • centos 7

shell

[root@db01 ~]# cat get_table_size.sh
#!/bin/sh
MONGO=/usr/bin/mongo
function get_dbs() {
  $MONGO << EOF
show dbs
EOF
}
function get_tables() {
    # $1 is dbname
    DB=$1
    $MONGO  << EOF
use $DB ;
show tables;
EOF
}
function get_a_table_size() {
  DB=$1
  TABLE=$2
  $MONGO  << EOF
use $DB ;
db.$TABLE.totalSize()
EOF
}

function get_size() {
  for dbname in `get_dbs |head -n -1 |tail -n +5|awk '{print $1}'`
  do
    for i in `get_tables $dbname |head -n -1 |tail -n +5`
    do
      SIZE=`get_a_table_size $dbname $i |head -n -1 |tail -n +5`
      echo "$dbname  $i    $SIZE"
    done
  done
}

get_size $1 |sort  -k3nr
阅读(11452) | 评论(0) | 转发(0) |
0

上一篇:open falcon针对nginx监控的shell实现版

下一篇:没有了

给主人留下些什么吧!~~