top of page

MongoDB Monitoring


MongoDB Monitoring

MongoDB provides various commands and tools for monitoring the health and performance of your database. These commands help you gather insights into the system's status, diagnose potential issues, and optimize your MongoDB deployment. Below are some essential MongoDB monitoring commands:


1. db.stats():

Provides an overview of the database's statistics, including the number of objects, data size, storage size, and index size.

builddevops> db.stats()
{
  db: 'builddevops',
  collections: Long('1'),
  views: Long('0'),
  objects: Long('2'),
  avgObjSize: 38.5,
  dataSize: 77,
  storageSize: 20480,
  indexes: Long('1'),
  indexSize: 20480,
  totalSize: 40960,
  scaleFactor: Long('1'),
  fsUsedSize: 70450868224,
  fsTotalSize: 85887791104,
  ok: 1
}
builddevops>

2. db.serverStatus():


Retrieves a comprehensive set of metrics about the MongoDB server, such as connections, memory usage, network activity, and storage engine details.

builddevops> db.serverStatus()
{
  host: 'siddhesh',
  version: '7.0.3',
  process: 'mongod',
  pid: Long('20958'),
  uptime: 259065,
  uptimeMillis: Long('259065723'),
  uptimeEstimate: Long('259065'),
  localTime: ISODate('2023-11-30T17:27:19.760Z'),
  asserts: {
    regular: 0,
    warning: 0,
    msg: 0,
    user: 125,
    tripwire: 0,
    rollovers: 0
  },
OUTPUT TRUNCATED 
builddevops>

3. db.collection.stats():


Offers statistics specific to a particular collection, including document count, index details, and storage usage.

builddevops> db.mycollection.stats()
OUTPUT TRUNCATED
  sharded: false,
  size: 77,
  count: 2,
  numOrphanDocs: 0,
  storageSize: 20480,
  totalIndexSize: 20480,
  totalSize: 40960,
  indexSizes: { _id_: 20480 },
  avgObjSize: 38,
  ns: 'builddevops.mycollection',
  nindexes: 1,
  scaleFactor: 1
}
builddevops>

4. mongostat:


A command-line tool that provides a real-time overview of your MongoDB server's status, including various metrics like inserts, queries, updates, deletes, and more.

[root@siddhesh ~]# mongostat
insert query update delete getmore command dirty used flushes vsize  res qrw arw net_in net_out conn                time
    *0    *0     *0     *0       0     1|0  0.0% 0.0%       0 2.59G 147M 0|0 0|0   112b   69.4k    3 Nov 30 23:02:52.510
    *0    *0     *0     *0       0     1|0  0.0% 0.0%       0 2.59G 147M 0|0 0|0   112b   69.4k    3 Nov 30 23:02:53.510
    *0    *0     *0     *0       0     0|0  0.0% 0.0%       0 2.59G 147M 0|0 0|0   111b   69.2k    3 Nov 30 23:02:54.512
    *0    *0     *0     *0       0     1|0  0.0% 0.0%       0 2.59G 147M 0|0 0|0   112b   69.5k    3 Nov 30 23:02:55.510
    *0    *0     *0     *0       0     1|0  0.0% 0.0%       0 2.59G 147M 0|0 0|0   112b   69.4k    3 Nov 30 23:02:56.509
[root@siddhesh ~]#

The output of mongostat includes various columns such as:


Insert: Number of insert operations per second.

Query: Number of query operations per second.

Update: Number of update operations per second.

Delete: Number of delete operations per second.

Command: Number of commands per second.

Query Response Time: Average time per query in milliseconds.

Update Response Time: Average time per update in milliseconds.

Delete Response Time: Average time per delete in milliseconds.

Connection: Number of open connections to the database.

Queued Reads: Number of queued read operations.

Queued Writes: Number of queued write operations.

Active Users: Number of active users connected to the database.


5. mongotop:

Monitors the read and write activity of a MongoDB instance by displaying the amount of time a MongoDB instance spends reading and writing data.

[root@siddhesh ~]# mongotop
2023-11-30T23:06:01.080+0530	connected to: mongodb://localhost/

                      ns    total    read    write    2023-11-30T23:06:02+05:30
    admin.$cmd.aggregate      0ms     0ms      0ms
          admin.atlascli      0ms     0ms      0ms
    admin.system.version      0ms     0ms      0ms
builddevops.mycollection      0ms     0ms      0ms
      config.collections      0ms     0ms      0ms
  config.system.sessions      0ms     0ms      0ms
     config.transactions      0ms     0ms      0ms
    local.system.replset      0ms     0ms      0ms

                      ns    total    read    write    2023-11-30T23:06:03+05:30
    admin.$cmd.aggregate      0ms     0ms      0ms
          admin.atlascli      0ms     0ms      0ms
    admin.system.version      0ms     0ms      0ms
builddevops.mycollection      0ms     0ms      0ms
      config.collections      0ms     0ms      0ms
  config.system.sessions      0ms     0ms      0ms
     config.transactions      0ms     0ms      0ms
    local.system.replset      0ms     0ms      0ms
[root@siddhesh ~]#

The columns in the mongotop output include:

ns: The namespace (collection or database) where the operation is occurring.

total: The total time, in milliseconds, spent on operations in this namespace.

read: The time, in milliseconds, spent on read operations in this namespace.

write: The time, in milliseconds, spent on write operations in this namespace.

other: The time, in milliseconds, spent on other operations in this namespace.


Comentarios

Obtuvo 0 de 5 estrellas.
No se pudieron cargar los comentarios
Parece que hubo un problema técnico. Intenta volver a conectarte o actualiza la página.
bottom of page