Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1684995
  • 博文数量: 186
  • 博客积分: 3044
  • 博客等级: 中校
  • 技术积分: 2493
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-25 15:04
文章分类

全部博文(186)

文章存档

2024年(2)

2022年(4)

2021年(3)

2020年(1)

2019年(5)

2018年(13)

2017年(6)

2016年(10)

2015年(11)

2014年(11)

2013年(13)

2012年(23)

2011年(25)

2010年(2)

2008年(1)

2007年(5)

2006年(51)

分类: NOSQL

2018-12-18 15:34:11

使用mongo shell连到mongos
执行命令:AllChunkInfo("dbname.cellname",true)

点击(此处)折叠或打开

  1. AllChunkInfo = function(ns, est){
  2.     var chunks = db.getSiblingDB("config").chunks.find({"ns" : ns}).sort({min:1}); //this will return all chunks for the ns ordered by min
  3.     //some counters for overall stats at the end
  4.     var totalChunks = 0;
  5.     var totalSize = 0;
  6.     var totalEmpty = 0;
  7.     print("ChunkID,Shard,ChunkSize,ObjectsInChunk"); // header row
  8.     // iterate over all the chunks, print out info for each
  9.     chunks.forEach(
  10.         function printChunkInfo(chunk) {

  11.         var db1 = db.getSiblingDB(chunk.ns.split(".")[0]); // get the database we will be running the command against later
  12.         var key = db.getSiblingDB("config").collections.findOne({_id:chunk.ns}).key; // will need this for the dataSize call
  13.         // dataSize returns the info we need on the data, but using the estimate option to use counts is less intensive
  14.         var dataSizeResult = db1.runCommand({datasize:chunk.ns, keyPattern:key, min:chunk.min, max:chunk.max, estimate:est});
  15.         // printjson(dataSizeResult); // uncomment to see how long it takes to run and status
  16.         print(chunk._id+","+chunk.shard+","+dataSizeResult.size+","+dataSizeResult.numObjects);
  17.         totalSize += dataSizeResult.size;
  18.         totalChunks++;
  19.         if (dataSizeResult.size == 0) { totalEmpty++ }; //count empty chunks for summary
  20.         }
  21.     )
  22.     print("***********Summary Chunk Information***********");
  23.     print("Total Chunks: "+totalChunks);
  24.     print("Average Chunk Size (bytes): "+(totalSize/totalChunks));
  25.     print("Empty Chunks: "+totalEmpty);
  26.     print("Average Chunk Size (non-empty): "+(totalSize/(totalChunks-totalEmpty)));
阅读(7140) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~