db.collection.latencyStats()

    在本页面

    定义

    • db.collection. latencyStats(选项)

      • db.collection.latencyStats()返回给定集合的延迟统计信息。它是一个包装 $collStats

    此方法具有以下形式:

    1. db.collection.latencyStats( { histograms: <boolean> } )

    histograms参数是可选的 boolean。如果histograms: true则latencyStats()将延迟直方图添加到 return 文档。

    也可以看看

    $collStats

    输出

    latencyStats()返回包含字段latencyStats的文档,其中包含以下字段:

    字段 描述
    reads 读取请求的延迟统计信息。
    writes 写请求的延迟统计信息。
    commands 数据库命令的延迟统计信息。

    每个字段都包含一个包含以下字段的嵌入式文档:

    字段 描述
    latency 一个64位整数,以毫秒为单位给出总的组合延迟。
    ops 一个64位整数,给出自启动以来对集合执行的操作总数。
    histogram 嵌入式文档的 array,每个都代表一个延迟范围。每个文档涵盖以前文档范围的两倍。对于介于 2048 微秒和大约 1 秒之间的上限值,直方图包括 half-steps。
    此字段仅在latencyStats: { histograms: true }选项的情况下存在。输出中省略了具有零count的空范围。
    每个文档都包含以下字段:
    字段 :描述
    micros :一个64位整数,以毫秒为单位给出当前等待时间范围的上限时间。该文档的范围介于上一个文档的 micros值(不包括此值)和该文档的 值(包括不包括在内)之间。
    count :一个64位整数,给出延迟小于或等于的操作数micros
    例如,如果collStats返回以下直方图:
    histogram: [
    { micros: NumberLong(1), count: NumberLong(10) },
    { micros: NumberLong(2), count: NumberLong(1) },
    { micros: NumberLong(4096), count: NumberLong(1) },
    { micros: NumberLong(16384), count: NumberLong(1000) },
    { micros: NumberLong(49152), count: NumberLong(100) }
    ]
    这表示:
    10 次操作占用 1 微秒或更少,
    1 操作范围(1,2)微秒,
    1 操作范围内的范围(3072,4096)微秒,
    1000 次操作(12288,16384)和范围内的
    100 次操作(32768,49152)。

    例子

    您可以在mongo shell 中运行latencyStats(),如下所示:

    1. db.data.latencyStats( { histograms: true } ).pretty()

    latencyStats()返回如下文档:

    1. {
    2. "ns" : "test.data",
    3. "localTime" : ISODate("2016-11-01T21:56:28.962Z"),
    4. "latencyStats" : {
    5. "reads" : {
    6. "histogram" : [
    7. {
    8. "micros" : NumberLong(16),
    9. "count" : NumberLong(6)
    10. },
    11. {
    12. "micros" : NumberLong(512),
    13. "count" : NumberLong(1)
    14. }
    15. ],
    16. "latency" : NumberLong(747),
    17. "ops" : NumberLong(7)
    18. },
    19. "writes" : {
    20. "histogram" : [
    21. {
    22. "micros" : NumberLong(64),
    23. "count" : NumberLong(1)
    24. },
    25. {
    26. "micros" : NumberLong(24576),
    27. "count" : NumberLong(1)
    28. }
    29. ],
    30. "latency" : NumberLong(26845),
    31. "ops" : NumberLong(2)
    32. },
    33. "commands" : {
    34. "histogram" : [ ],
    35. "latency" : NumberLong(0),
    36. "ops" : NumberLong(0)
    37. }
    38. }
    39. }

    译者:李冠飞

    校对:

    参见

    原文 - db.collection.latencyStats()