MongoDB is now getting more and more fire, to do a good job of mongodb monitoring needs to be from its installation configuration, to the simple command statement to use, and then to its operation mechanism and State acquisition method master.
MongoDB has three basic ways to get state:
1.mongostat
2. Turn on the 28017 listening port, Curl Http://127.0.0.1:28017/_status
3. Enter MONGO execute db.serverstatus command
I'm using the third method:
echo "Db.serverstatus ()" |/usr/local/mongodb/bin/mongo 192.168.1.123:27017/foo --quiet{ "Host" : "Tencent64.site", --server hostname "Version" : "2.0.5", --mongo version "Process" : "Mongod", --process name "Uptime" : 1238418, --Start time (unit: S) "Uptimeestimate" : 1230730, --based on MongoDB internal coarse-grained timer run time "LocalTime" : isodate ("2012-09-14t09:09:52.657z"), --server local time "GlobalLock" : { "TotalTime" : 1238418105923, --the time the global lock was created (unit:ms microseconds)     &NBsp; "LockTime" : 75055831911, --Global lock hold Time (unit:ms microseconds) "ratio" : 0.06060621332329477, --locktime and TotalTime's ratio "Currentqueue" : { "Total" : 0, --the number of operations in the queue waiting for global locks "Readers " : 0, --number of operations in queue waiting for read lock "Writers" : 0 -- Number of operations in queue waiting for write lock   &NBsp; }, "Activeclients" : { "Total" : 1, --the number of currently active clients connected to the server "Readers" : 1, --the number of currently active clients performing read operations "Writers" : 0 --the number of currently active clients performing the write operation } }, "Mem" :&nBsp { "Bits"  :  64, --64-bit machines "resident" : 18363, --occupies the amount of physical memory. "virtual" The amount of virtual memory occupied by : 478810, -- does the "supported" : true, --support extended memory "Mapped" : 233311, --the size of the data file mapped to memory, Very close to all of your database sizes. " Mappedwithjournal " : 466622, "Note" : "virtual minus mapped&Nbsp;is large. could indicate a memory leak " }, "Connections" : { "Current" : 737, --Current active connection amount. Current number of active connections to server "Available" : 82 --the amount of remaining idle connections. Number of available connections remaining }, " Extra_info " : { "Note" : "Fields vary by platform", "Heap_usage_bytes" : 3838448, -- The number of heap bytes in this procedure. Only available for linux "Page_faults" : 31058356 --the total number of failed page accesses in memory during this process. Only available for linux }, " Indexcounters " : { "Btree" : { "accesses" : 68229146, Number of accesses to the --btree Index (index accessed) "hits" : 68229146, -- The number of btree pages in memory. (Index hit volume) "Misses" : 0, --the number of btree that do not exist in memory. (Index deviation amount) (Number of index memory access failures) "resets" : 0, --index counter is reset to 0 times "Missratio" : 0 --Index deviation rate (not hit Ratio) } }, " Backgroundflushing " : { "Flushes" : 20640, --database flushes write to disk "Total_ms" : 2453287, -- The number of microseconds that the database spends on refreshing data to disk "Average_ms" : 118.8608042635659, --average number of microseconds spent performing a single refresh "Last_ms" : 1, --the number of microseconds spent in the last execution of the refresh data to disk "last_finished" : isodate ("2012-09-14t09 : 09:35.656z ") --timestamp when the last data refresh was completed }, "Cursors" : { "Totalopen" : 0, --server the total number of cursors (cursor) held for client "Clientcursors_size" : 0, -- the total number of cursors (cursor) timeouts since "TimedOut" : 24 --server started }, "Network" : { "Bytesin" : numberlong ("1929833164782"), -- Total data sent to the database (bytes) The total amount of data emitted by the Bytesout : 553137147925, --Database (bytes) "Numrequests" : 2475184328 --the amount of requests sent to the database }, "Opcounters" : { Total Insert Data volume since "Insert" : 687531883, --server started "Query" : 711010343, --server the total amount of query data since startup "Update" : 0, -- Total update data volume since server startup "Delete" : 0, --server the total amount of delete data since startup "Getmore" : 6484, -- Total number of Getmore calls to any cursor since server startup "Command" : 1287537 --server the total number of other commands executed since startup }, "asserts" : { "Regular" : 0, -- The total number of formal assertions (assert similar to exception handling) has been thrown since server startup "Warning" : 1, --serTotal number of alarms thrown since Ver started "MSG" : 0, --the number of message assertions. Good string errors defined inside the server "User" : 4, --number of users asserted. User-generated errors, such as: Full disk space, duplicate keys. "Rollovers" Number of Assert counters have rolled over since : 0 --server started }, "writebacksqueued"  : false, --whether there are retry operations performed from MONGOs "dur" : { "commits" : 30, --the number of times a commit has occurred in the journal log on the previous interval "JOURNALEDMB" : 0, --The amount of data written to the journal log on the previous interval (in MB) "WRITETODATAFILESMB" : 0, --the amount of data written to the data file on the previous interval journal log (in MB) "Compression" : 0, -- "Commitsinwritelock" : 0, --the number of times commits occurred during write lock "Earlycommits" : 0, -- Number of requests for commit before schedule time "Timems" : { "DT" : 3064, "PrepLogBuffer" : 0, --time spent preparing to write journal log "Writetojournal" : 0, - -The actual time spent writing journal logs "Writetodatafiles" : 0, -- Journal the time spent writing data files after logging "Remapprivateview" : 0 --the amount of time spent remapping copy-on-write memory mapped views } }, "OK" : 1 --serverstatus is returned correctly}
Above, we can take out the necessary parameters to make the monitoring item.
Define the key values first:
#mongodb. confuserparameter=mongodb_port_discovery,/usr/local/zabbix/exec/mongo_discovery.pyuserparameter= Mongodb_stats[*],/usr/local/zabbix/exec/mongo_status.sh $ $4
Write mongo_discovery.py script (for Port Discovery)
#!/usr/bin/env python#-*-coding:utf-8-*-import jsonimport subprocessjson_data = {"Data": []}net_cmd = "sudo netstat-n Lpt|awk '/mongo/{print $4} ' P = subprocess. Popen (Net_cmd, Shell=true, stdout=subprocess. PIPE) Net_result = P.stdout.readlines () for server in net_result:dic_content = {"{#MONGO_PORT}": Server.split (': ') [1].strip (), "{#MONGO_IPADDR}": Server.split (': ') [0].strip ()} json_data[' Data '].append (dic_content) result = Json.dumps (json_data,sort_keys=true,indent=4) Print result
Write mongo_status.sh State detection script
#!/bin/bash# #mongo_status. sh### #wuhf # #case $# in 3) output=$ (/bin/echo "Db.serverstatus (). $" |/usr/local/mongodb/ Bin/mongo $1:$2/foo--quiet);; 4) output=$ (/bin/echo "Db.serverstatus (). $3.$4" |/usr/local/mongodb/bin/mongo $1:$2/foo--quiet); 5) output=$ (/bin/echo "Db.serverstatus (). $3.$4.$5" |/usr/local/mongodb/bin/mongo $1:$2/foo--quiet); Esac if [["$output" =~ "Numberlong"]];then echo $output |sed-n ' S/numberlong (//p ' |sed-n ' s/)//p ' else echo $outputf I
Permission settings
chmod 755/usr/local/zabbix/exec/*chown Zabbix.zabbix/usr/local/zabbix/exec/*chown zabbix.zabbix/usr/local/zabbix/ Etc/zabbix_agentd.conf.d/*echo "Zabbix all= (Root) nopasswd:all" >>/etc/sudoerssed-i ' S/^defaults.*.requiretty /#Defaults requiretty/'/etc/sudoers
Make a MongoDB template
Defining Autodiscover Rules
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7A/FE/wKiom1bEU83gEnfsAAEuEdTC_0Q902.jpg "title=" Dll01.jpg "alt=" Wkiom1beu83genfsaaeuedtc_0q902.jpg "/>
Defining Monitoring items
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7A/FD/wKioL1bEVEOwDpbxAACk8k2f3q4965.jpg "title=" Dll02.jpg "alt=" Wkiol1beveowdpbxaack8k2f3q4965.jpg "/>
The final addition of the trigger and diagram is complete.
Note: After defining the key-value correspondence in the mongodb.conf configuration file, restart the Zabbix service to take effect
This article is from the "Tongluowan" blog, make sure to keep this source http://wuhf2015.blog.51cto.com/8213008/1742808
Zabbix How to monitor MongoDB