Zabbix应用八:Zabbix监控MongoDB

利用Zabbix监控MongoDB

一、首先介绍mongodb采集到的数据含义:

1、状态采集命令:

>db.serverStatus();

2、输出内容:

{
    "host" : "localhost",
    "version" : "2.2.6",
    "process" : "mongod",  
    "pid" : 55123,
    "uptime" : 18654536,
    "uptimeMillis" : NumberLong("18654536224"),
    "uptimeEstimate" : 18407100,
    "localTime" : ISODate("2017-07-10T08:06:17.628Z"),
    "locks" : {
        "." : {
            "timeLockedMicros" : {
                "R" : NumberLong(1203), #所有库全局读锁总微秒数
                "W" : NumberLong(1607)  #所有全库局写锁总微妙数
            },
            "timeAcquiringMicros" : {
                "R" : NumberLong(168),  #所有库全局读锁的锁等待总微秒数
                "W" : NumberLong(41)    #所有库全局写锁的锁等待总微秒数
            }
        },
        "admin" : {
            "timeLockedMicros" : {      
                
            },
            "timeAcquiringMicros" : {
                
            }
        },
        "local" : {
            "timeLockedMicros" : {
                "r" : NumberLong(4118711),
                "w" : NumberLong(0)
            },
            "timeAcquiringMicros" : {
                "r" : NumberLong(2191541),
                "w" : NumberLong(0)
            }
        },
        "org_center" : {
            "timeLockedMicros" : {
                "r" : NumberLong("13835793898"),
                "w" : NumberLong("20466120642")
            },
            "timeAcquiringMicros" : {
                "r" : NumberLong(352664878),
                "w" : NumberLong("29283950076")
            }
        },
        "org_centr" : {
            "timeLockedMicros" : {
                "r" : NumberLong(124236),
                "w" : NumberLong(180)
            },
            "timeAcquiringMicros" : {
                "r" : NumberLong(10119),
                "w" : NumberLong(10)
            }
        },
        "shopProduct" : {
            "timeLockedMicros" : {
                "r" : NumberLong(134997),
                "w" : NumberLong(0)
            },
            "timeAcquiringMicros" : {
                "r" : NumberLong(14241),
                "w" : NumberLong(0)
            }
        },
        "tb_shop" : {
            "timeLockedMicros" : {
                "r" : NumberLong(1405192),
                "w" : NumberLong(0)
            },
            "timeAcquiringMicros" : {
                "r" : NumberLong(146122),
                "w" : NumberLong(0)
            }
        },
        "test" : {
            "timeLockedMicros" : {
                "r" : NumberLong(3090622),
                "w" : NumberLong(2170)
            },
            "timeAcquiringMicros" : {
                "r" : NumberLong(414040),
                "w" : NumberLong(130)
            }
        }
    },
    "globalLock" : {
        "totalTime" : NumberLong("18654536224000"),
        "lockTime" : NumberLong(1607),
        "currentQueue" : {
            "total" : 0,
            "readers" : 0,
            "writers" : 0
        },
        "activeClients" : {
            "total" : 0,
            "readers" : 0,
            "writers" : 0
        }
    },
    "mem" : {
        "bits" : 64,         #64位操作系统
        "resident" : 238,    #共占用屋里内存M
        "virtual" : 448,     #占用虚拟内存
        "supported" : true,
        "mapped" : 256       #映射内存
    },
    "connections" : {
        "current" : 16,      #当前活跃连接数
        "available" : 803    #剩余空闲连接数
    },
    "extra_info" : {
        "note" : "fields vary by platform",
        "heap_usage_bytes" : 30607592,
        "page_faults" : 200
    },
    "indexCounters" : {
        "btree" : {
            "accesses" : 24067164,  #索引被访问次数
            "hits" : 24067164,      #索引命中量
            "misses" : 0,
            "resets" : 0,
            "missRatio" : 0
        }
    },
    "backgroundFlushing" : {
        "flushes" : 310905,                   #数据库刷新写到磁盘的次数
        "total_ms" : 214212,                  #数据库刷新数据到磁盘花费的微秒数
        "average_ms" : 0.688995030636368,     #执行单次刷新花费的平均微秒数
        "last_ms" : 5,
        "last_finished" : ISODate("2017-07-10T08:05:26.598Z")
    },
    "cursors" : {
        "totalOpen" : 0,
        "clientCursors_size" : 0,
        "timedOut" : 60
    },
    "network" : {
        "bytesIn" : 5150258135,       #流入数据库总量
        "bytesOut" : 10535203727,     #从数据库流出总量
        "numRequests" : 32203604      #数据库总请求数
    },
    "opcounters" : {
        "insert" : 6010564,       #总insert数据量
        "query" : 7507450,        #总query数据量
        "update" : 573085,        #总update数据量
        "delete" : 2563194,       #总delete数据量
        "getmore" : 308,          #游标调用的getMore总次数
        "command" : 16077462      #执行命令的总次数
    },
    "asserts" : {
        "regular" : 0,
        "warning" : 0,
        "msg" : 0,
        "user" : 37,
        "rollovers" : 0
    },
    "writeBacksQueued" : false,
    "recordStats" : {
        "accessesNotInMemory" : 0,
        "pageFaultExceptionsThrown" : 0,
        "org_center" : {
            "accessesNotInMemory" : 0,
            "pageFaultExceptionsThrown" : 0
        },
        "tb_shop" : {
            "accessesNotInMemory" : 0,
            "pageFaultExceptionsThrown" : 0
        },
        "test" : {
            "accessesNotInMemory" : 0,
            "pageFaultExceptionsThrown" : 0
        }
    },
    "ok" : 1
}

 zabbix监控页面的主要数据开源就是这里。 

 3、利用zabbix用户自定义监控功能 userparameter 来监控MongoDB:

   3.1、修改zabbix_agentd.conf,允许接受自定义参数:

UnsafeUserParameters=1

  3.2、定义数据采集命令:

UserParameter=MongoDB.status[*],/bin/echo "db.serverStatus().$1" |/data/mongodb/bin/mongo admin | grep "$2" | awk -F ':' '{print $$2}' | awk -F ',' '{print $$1}'

  注意:不同环境,请注意主机ip和端口号等。

4、zabbix监控页面新建监控模版、添加监控项、生成图形:

创建模版:Template App MongoDB(已经手动创建完毕,并创建监控项,需要者可自行下载)

由于监控项众多,本例只贴出其中一个监控项的配置,如下图:

需要注意的是 键值 项,需和 UserParameter 中定义的格式一致。

5、模版创建完成后,套用到被监控的主机即可。

最终效果如下图:

原文地址:https://www.cnblogs.com/ahaii/p/7146290.html