脚本统计MongoDB集合表数据量

脚本:

powershell 复制代码
#!/bin/bash
 
ip='xxx.xx.xx.xx'
port=xxxx
db='xxxdb'
#user=
#passw=
 
mongo -host ${ip}:${port} <<EOF 2>/dev/null|grep -vE 'version|not match|session|compressors|=|Warning|delivers|upcoming|installation|https|switched|bye' >collec
use ${db};
show tables;
EOF
 
cos=`wc -l collec|cut -d' ' -f1`
for n in `seq $cos`;do
  collname=$(sed -n "$n"p collec)
  cz=$(mongo ${ip}:${port}/${db} --eval "db.getCollection(\"$collname\").count()"|grep -vE 'version|not match|session|compressors')
echo $cz,$collname
done

1.执行:

sh xxx.sh

2.排序统计以降序排列

sh mon_list.sh |sort -rn -t',' -k1

3.计算库下面的集合总数据量

sh mon_list.sh |sort -rn -t',' -k1 |awk -F ',' '{sum+=$1}END{print sum}'

相关推荐
SelectDB3 分钟前
阶跃星辰基于 SelectDB 构建 PB 级 Agent 可观测平台
大数据·数据库·aigc
这个DBA有点耶1 小时前
GROUP BY优化全解:如何写出既不丢数据又飞快的分组查询
数据库·mysql·架构
掉头发的王富贵4 小时前
【StarRocks】极限十分钟入门StarRocks
数据库·sql·mysql
Nturmoils4 小时前
WHERE 条件别凭习惯写,常用查询先跑一遍
数据库
Databend1 天前
在 AWS 中国峰会逛了一天,我在 Databend 展台看到了 Agent 数据基础设施的新思路
数据库·人工智能·agent
葫芦和十三1 天前
图解 MongoDB 12|索引与查询优化地图:一条主线,三个判断轴
后端·mongodb·agent
葫芦和十三2 天前
图解 MongoDB 11|慢查询排查闭环:从 Profile 到 explain 的分层路径
后端·mongodb·agent
葫芦和十三2 天前
图解 MongoDB 09|explain 再读:从 queryPlanner 到 executionStats
后端·mongodb·agent
葫芦和十三2 天前
图解 MongoDB 10|覆盖查询:让索引把活干完,根本不用回表
后端·mongodb·agent
ClouGence2 天前
Oracle 数据同步为什么会出现数据不一致?长事务是常被忽略的原因
数据库·后端·oracle