MongoDB is a database based on distributed file storage. Written by the C + + language. Designed to provide scalable, high-performance data storage solutions for WEB applications.
MongoDB is a product between relational database and non relational database, and is the most powerful and relational database in the relational database.
MongoDB now more and more fire, to do a good job of monitoring the MONGODB needs from its installation configuration, to a simple command statement to use, and then to its operating mechanism and the State acquisition method master.
MongoDB has three basic modes of State acquisition:
1.mongostat
2. Open 28017 of the listening port, Curl Http://127.0.0.1:28017/_status
3. Enter MONGO execute db.serverstatus command
I'm using a 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 granularity timer run time "localtime": Isodate ("2012-09-14t09:09:52.657z"),--server Local Time "GlobalLock": {"TotalTime": 1238418105923,--Global lock creation time (in Ms microseconds) "Locktime": 75055831911,--Global lock guarantee Holding Time (in units: Ms microseconds) "ratio": 0.06060621332329477,--locktime and totaltime than "Currentqueue": {"total
": 0,--number of operations in queues waiting for global locks" readers ": 0,--number of operations in queues waiting for read locks" writers ": 0--Number of operations waiting in queue for write locks},
"Activeclients": {"Total": 1,-current number of active client connected to server "readers": 1,--Number of current active client performing read operations "Writers": 0--Current active client number for write operation}, "mem": {"bits": 64,--64-bit machine "Residen
T ": 18363--Takes up the amount of physical memory. "Virtual": 478810,-the amount of virtual memory occupied "supported": TRUE,--support extended RAM "mapped": 233311,--mapped to memory data file size, very close
To all of your database sizes. "Mappedwithjournal": 466622, "note": "Virtual minus mapped is large." Could indicate a memory leak "}," connections ": {" Current ": 737,--Currently active connection amount. Number of currently active connections to the server "available": 82--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. Applies only to Linux "Page_faults": 31058356-The total number of failed accesses to an in-memory page in this procedure.
Linux only, "Indexcounters": {"Btree": {"accesses": 68229146,--btree index access number (index is accessed) "Hits": 68229146, the number of btree pages in memory. (index hit) "misses": 0--the number of btree that do not exist in memory.
(Index deviation amount) (Number of index memory access failures) "resets": 0--Number of index counters reset to 0 "Missratio": 0--Index deviation rate (not hit)}}, "Backgroundflushing": {"Flushes": 20640,--the number of times the database refreshes write to disk "Total_ms": 2453287--The number of microseconds that the database refreshes the data to disk "Average_ms": 118.8608042635659, the average number of microseconds to perform a single refresh "Last_ms": 1,--Last execution complete Refresh data
The number of microseconds to disk "last_finished": Isodate ("2012-09-14t09:09:35.656z")--timestamp when the last refresh data was completed, "cursors": { "Totalopen": 0,--server for client-maintained cursors (cursor) Total "clientcursors_size": 0,--"timedout":--server started to The total number of cursor (cursor) timeouts}, "network": {"Bytesin": Numberlong ("1929833164782"),--total data sent to the database (bytes) "b
Ytesout ": 553137147925--total data emitted by the database (bytes)" numrequests ": 2475184328--Number of requests sent to the database}," Opcounters ": { Insert: 687531883, the total amount of INSERT data "query" since--server started: 711010343,--server total query data Volume "Update" since startup : 0,--server total update Data "delete": 0, the total number of delete data "Getmore" since--server started: 6484, GE with any cursors invoked since the start of--server Total number of Tmore "command": 1287537--server The total number of other commands performed since startup}, "asserts": {"regular": 0,--server since boot A formal assertion (assert a form similar to exception handling) is alwaysNumber "Warning": 1,--server the total number of alarms thrown since the start of "MSG": 0,--Number of message assertions. Good string errors defined within the server "user": 4, the number of user assertions.
User-generated errors, such as: Disk space full, duplicate key. "rollovers": 0--server since the start, assert counters have rolled over the number of times}, "writebacksqueued": false,--whether there is a ret executed from the MONGOs ry operation "Dur": {"commits": 30,-the number of times the previous interval journal log commit was "JOURNALEDMB": 0, the amount of data written to the journal log in the previous interval (units: MB) "WRITETODATAFILESMB": 0--The amount of data written to the data file in the previous interval journal log (in MB) "compression": 0,--"Commitsinwri Telock ": 0,--the number of commits occurred during the write lock" earlycommits ": 0, the number of times a commit was requested before--schedule time" Timems ": {" dt "
: 3064, "Preplogbuffer": 0,--the time spent preparing to write the journal log "writetojournal": 0,--The actual time spent writing the journal Log "Writetodatafiles": 0,--journal the time spent writing data files after the log "Remapprivateview": 0--the amount of times spent Remappi ng Copy-on-write Memory mapped views}, "OK": 1--serverstatus return correct}
Above, we can make the monitor by pumping out the required parameters.
Define Key values First:
#mongodb. conf
userparameter=mongodb_port_discovery,/usr/local/zabbix/exec/mongo_discovery.py
USERPARAMETER=MONGODB_STATS[*],/USR/LOCAL/ZABBIX/EXEC/MONGO_STATUS.SH $ $ $ $
Write mongo_discovery.py script (for Port Discovery)
#!/usr/bin/env python
#-*-coding:utf-8-*-
import JSON
import subprocess
= {"Data": []}
Net_cmd = ' sudo netstat-nlpt|awk '/mongo/{print $} '
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 # #
$# 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)
5)
output=$ (/bin/echo "Db.serverstatus (). $3.$4.$5" |/usr/local/mongodb/bin/mongo $1:$2/foo)
Esac
If [["$output" =~ "Numberlong" ]];then
echo $output |sed-n ' S/numberlong//p ' |sed-n ' s/'
Else
echo $output
fi
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/sudoers
sed-i ' s/^defaults.*.requiretty/#Defaults requiretty/'/etc/sudoers
Make MongoDB template
Defining automatic discovery Rules
Defining Monitoring items
The final addition of triggers and graphs is complete
Note: You must restart the Zabbix service in order to take effect when the key value correspondence is defined in the mongodb.conf configuration file