Using Percona Toolkit pt-mongodb-summary

Percona Server for MongoDB

pt-mongodb-summaryThis blog post is another in the series on the Percona Server for MongoDB 3.4 bundle release. In this blog post, we’ll look at the

pt-mongodb-summary
 tool in Percona Toolkit.

The

pt-mongodb-summary
 tool from Percona Toolkit provides a quick at-a-glance overview of MongoDB and Percona Server for MongoDB instances. It is equivalent to
pt-mysql-summary
 for MySQL. 

pt-mongodb-summary
 also collects information about a MongoDB cluster. It collects information from several sources to provide an overview of the cluster.

How It Works

The usage for the command is as follows:

pt-mongodb-summary [OPTIONS] [HOST[:PORT]]

Options:

  • -a, –auth-db: Specifies the database used to establish credentials and privileges with a MongoDB server. By default, the admin database is used.
  • -p, –password: Specifies the password to use when connecting to a server with authentication enabled. Do not add a space between the option and its value:
    -p<password>
    .
    If you specify the option without any value,
    pt-mongodb-summary
     will ask for the password interactively.
  • -u, –user: Specifies the user name for connecting to a server with authentication enabled.

By default, if you run

pt-mongodb-summary
 without parameters, it tries to connect to the localhost on port 27017. It collects information about the MongoDB instances by running administration commands, and formatting the output.

Sections

Instances

The first thing the tool does is get the list of hosts connected to the specified MongoDB instance by running the

listShards
 command. It also runs
replSetGetStatus
 
on every instance to collect the ID, type, and replica set for each instance.

This host

Next, it gathers information about the host it is connected to by grouping information collected from

hostInfo
,
getCmdLineOpts
,
serverStatus
 
and the OS process (by process ID). The result provides an overview of the running instance and the underlying OS.

Running ops

This section collects statistics by running the

serverStatus
 command five times at regular intervals (every one second), and provides the minimum, maximum and average operation counters for
insert
,
query
,
update
,
delete
,
getMore
 and
command
 operations.

Security

This collects information about security configurations by parsing the 

getCmdLineOpts
 command and asking the admin.system.users, and admin.system.roles collections.

Oplog

From the MongoDB website:

The oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. MongoDB applies database operations on the primary and then records the operations on the primary’s oplog. The secondary members then copy and apply these operations in an asynchronous process. All replica set members contain a copy of the oplog, in the local.oplog.rs collection, which allows them to maintain the current state of the database.

How do we get the oplog info? The program collects statistics from the oplog for every host in the cluster, and returns the information on the statistics having the smaller

TimeDiffHours
  value.

Cluster-wide

This section provides information about the number of sharded/unsharded databases, collections and their size.The information is collected by running the

listDatabases
 command, and then running
collStats
 
for every collection in every database.

Conditional Sections

You may notice not all sections appear all the time. This is because there are three main patterns:

Sharded Connection to Mongos

  • Instances
  • This host
  • Running ops
  • Security
  • Cluster-wide

ReplicaSet Connection

  • Instances (limited to the current Replica Set)
  • This host
  • Running ops
  • Security
  • Oplog

Standalone Connection

  • Instances (limited to this host)
  • This host
  • Running ops
  • Security

Output Example

The following is an example of the output for

pt-mongodb-summary
:

./pt-mongodb-summary
# Instances ##############################################################################################
  PID    Host                         Type                      ReplSet                   Engine
 11037 localhost:17001                SHARDSVR/PRIMARY          r1                    wiredTiger
 11065 localhost:17002                SHARDSVR/SECONDARY        r1                    wiredTiger
 11136 localhost:17003                SHARDSVR/SECONDARY        r1                    wiredTiger
 11256 localhost:17004                SHARDSVR/ARBITER          r1                    wiredTiger
 11291 localhost:18001                SHARDSVR/PRIMARY          r2                    wiredTiger
 11362 localhost:18002                SHARDSVR/SECONDARY        r2                    wiredTiger
 11435 localhost:18003                SHARDSVR/SECONDARY        r2                    wiredTiger
 11513 localhost:18004                SHARDSVR/ARBITER          r2                    wiredTiger
 11548 localhost:19001                CONFIGSVR                 -                     wiredTiger
 11571 localhost:19002                CONFIGSVR                 -                     wiredTiger
 11592 localhost:19003                CONFIGSVR                 -                     wiredTiger
# This host
# Mongo Executable #######################################################################################
       Path to executable | /home/karl/tmp/MongoDB32Labs/3.2/bin/mongos
# Report On karl-HP-ENVY ########################################
                     User | karl
                PID Owner | mongos
                 Hostname | karl-HP-ENVY
                  Version | 3.2.4
                 Built On | Linux x86_64
                  Started | 2017-02-22 11:39:20 -0300 ART
                Processes | 12
             Process Type | mongos
# Running Ops ############################################################################################
Type         Min        Max        Avg
Insert           0          0          0/5s
Query            0          0          0/5s
Update           0          0          0/5s
Delete           0          0          0/5s
GetMore          0          0          0/5s
Command          1          1          5/5s
# Security ###############################################################################################
Users  : 0
Roles  : 0
Auth   : disabled
SSL    : disabled
Port   : 0
Bind IP:
# Cluster wide ###########################################################################################
            Databases: 4
          Collections: 21
  Sharded Collections: 5
Unsharded Collections: 16
    Sharded Data Size: 134.87 MB
  Unsharded Data Size: 1.44 GB
          ###  Chunks:
                   5 : samples.col2
                 132 : carlos.sample4
                 400 : carlos.sample3
                  50 : carlos.sample2
                 100 : carlos.sample1
# Balancer (per day)
              Success: 18
               Failed: 0
               Splits: 682
                Drops: 0

 The following is an output example when connected to a secondary in the replica set.

./pt-mongodb-summary localhost:17002
# Instances ##############################################################################################
  PID    Host                         Type                      ReplSet                   Engine
  9247 localhost:17001                SHARDSVR/PRIMARY          r1                    wiredTiger
  9318 localhost:17002                SHARDSVR/SECONDARY        r1                    wiredTiger
  9391 localhost:17003                SHARDSVR/SECONDARY        r1                    wiredTiger
  9466 localhost:17004                SHARDSVR/ARBITER          r1                    wiredTiger
# This host
# Mongo Executable #######################################################################################
       Path to executable | /home/karl/tmp/MongoDB32Labs/3.2/bin/mongod
# Report On karl-HP-ENVY:17002 ########################################
                     User | karl
                PID Owner | mongod
                 Hostname | karl-HP-ENVY:17002
                  Version | 3.2.4
                 Built On | Linux x86_64
                  Started | 2017-02-23 10:26:27 -0300 ART
                  Datadir | labs/r1-2
                Processes | 12
             Process Type | replset
# Running Ops ############################################################################################
Type         Min        Max        Avg
Insert           0          0          0/5s
Query            0          0          0/5s
Update           0          0          0/5s
Delete           0          0          0/5s
GetMore          0          1          1/5s
Command          1          3         13/5s
# Security ###############################################################################################
Users  : 0
Roles  : 0
Auth   : disabled
SSL    : disabled
Port   : 17002
Bind IP:

This next example shows when it is connected to a stand alone instance:

/pt-mongodb-summary localhost:27018
# Instances ##############################################################################################
PID Host Type ReplSet Engine
1 localhost:27018 - wiredTiger
# This host
# Report On 2f8862dce6c4 ########################################
PID Owner | mongod
Hostname | 2f8862dce6c4
Version | 3.2.10
Built On | Linux x86_64
Started | 2017-02-23 08:57:36 -0300 ART
Processes | 1
Process Type | mongod
# Running Ops ############################################################################################
Type Min Max Avg
Insert 0 0 0/5s
Query 0 0 0/5s
Update 0 0 0/5s
Delete 0 0 0/5s
GetMore 0 0 0/5s
Command 1 1 5/5s
# Security ###############################################################################################
Users : 0
Roles : 0
Auth : disabled
SSL : disabled
Port : 0
Bind IP:

Conclusion

The tool

pt-mongodb-summary
is new in Percona Toolkit. In the future, we hope we can make this grow to the size of its MySQL big brother!

关注dbDao.com的新浪微博

扫码加入微信Oracle小密圈,了解Oracle最新技术下载分享资源

TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569