**Zabbix 监控mongodb做后整理**
System Maintenance engineer Li Chao
Because of my safety, we can only do it. Through the MONGO client to remotely monitor the MONGO server.
1, if you do not operate on the MONGO server, please refer to my section below, if it is installed directly on the MongoDB server zabbix_agnetd please refer to the other articles on the web. (very many documents are installed directly on the MONGODB server Zabbix client).
2. The following first installs the MONGO client: My system is: ubuntu16.04, installs the MONGO client direct Apt-get installs can (here does not introduce more, but should notice apt is generally the lower version, wants 4.0 version can update apt here not to do the introduction, the net may search to the related content).
3. When the MongoDB client installation is complete, we execute the command below
/bin/echo "Db.serverstatus ()" |/usr/bin/mongo 192.168.16.111:20001/admin-ulichao-plichao
With this command you can test the system parameters that know MONGO, and we monitor these system parameters to
The results of the implementation are as follows:
MongoDB Shell version v4.0.0
Connecting To:mongodb://192.168.16.111:20001/admin
MongoDB Server version:3.4.9
Warning:shell and server versions do not match
{
"Host": "iz2zeem1uivcbfbr01nmnrz:20000",
"Version": "3.4.9",
"Process": "MONGOs",
"pid": Numberlong (10828),
"Uptime": 24441734,
"Uptimemillis": Numberlong ("24441733680"),
"Uptimeestimate": Numberlong (24441733),
"LocalTime": Isodate ("2018-08-02t09:34:54.400z"),
"asserts": {
"Regular": 0,
"Warning": 0,
"MSG": 0,
"User": 1763423,
"Rollovers": 0
},
"Connections": {
"Current": 86,
"Available": 52342,
"Totalcreated": 118672
},
"Extra_info": {
"Note": "Fields vary by platform",
"Page_faults": 14
},
"Network": {
"Bytesin": Numberlong ("467536962787"),
"Bytesout": Numberlong ("111369070632"),
"Physicalbytesin": Numberlong ("467536962787"),
"Physicalbytesout": Numberlong ("108213593338"),
"Numrequests": Numberlong ("2582169303")
},
"Opcounters": {
"Insert": 619611,
"Query": 406777,
"Update": 122426978,
"Delete": 61,
"Getmore": 308,
"Command": 215576153
},
"Sharding": {
"Configsvrconnectionstring": "config/iz2ze7s6pfi7t4x18mx417z:22000,iz2ze7s6pfi7t4x18mx418z:22000, iz2ze7s6pfi7t4x18mx419z:22000 ",
"Lastseenconfigserveroptime": {
"TS": Timestamp (1533202490, 2),
"T": Numberlong (3)
}
},
"Tcmalloc": {
"GENERIC": {
"Current_allocated_bytes": 4007000,
"Heap_size": Numberlong ("3108966400")
},
"Tcmalloc": {
"Pageheap_free_bytes": 36864,
"Pageheap_unmapped_bytes": Numberlong ("3090604032"),
"Max_total_thread_cache_bytes": Numberlong (1073741824),
"Current_total_thread_cache_bytes": 5583584,
"Total_free_bytes": 14318504,
"Central_cache_free_bytes": 3283112,
"Transfer_cache_free_bytes": 5451808,
"Thread_cache_free_bytes": 5583584,
"Aggressive_memory_decommit": 0,
"Formattedstring": "------------------------------------------------\nmalloc:4007000 (3.8 MiB) Bytes in use by Applica Tion\nmalloc: + 36864 (0.0 MIB) Bytes in page heap Freelist\nmalloc: + 3283112 (3.1 MiB) Bytes in central cache freelist \nmalloc: + 5451808 (5.2 MiB) Bytes in transfer cache Freelist\nmalloc: + 5583584 (5.3 MiB) Bytes in thread cache Freeli Sts\nmalloc: + 8577216 (8.2 MiB) Bytes in malloc metadata\nmalloc:------------\nmalloc: = 26939584 (25.7 MiB) Actual me Mory Used (physical + swap) \nmalloc: + 3090604032 (2947.4 MiB) Bytes released to OS (aka unmapped) \nmalloc:------------\ Nmalloc: = 3117543616 (2973.1 MiB) Virtual address space used\nmalloc:\nmalloc:2014 Spans in use\nmalloc:115 Thread hea PS in use\nmalloc:4096 tcmalloc page size\n------------------------------------------------\ncall releasefreememory ( ) to release freelist memory to the OS (via Madvise ()). \nbytes released to the OS take up virtual address space but no PHY Sical memory.\n "
}
},
"Mem": {
"Bits": 64,
"Resident": 174,
"Virtual": 3426,
"Supported": TRUE
},
"Metrics": {
"Cursor": {
"TimedOut": Numberlong (380),
"Open": {
"Multitarget": Numberlong (0),
"Singletarget": Numberlong (0),
"Pinned": Numberlong (0),
"Total": Numberlong (0)
}
},
"Commands": {
"<UNKNOWN>": Numberlong (1),
"Aggregate": {
"Failed": Numberlong (142),
"Total": Numberlong (8980)
},
"Authenticate": {
"Failed": Numberlong (12),
"Total": Numberlong (12)
},
"Buildinfo": {
"Failed": Numberlong (0),
"Total": Numberlong (635407)
},
"Collstats": {
"Failed": Numberlong (65),
"Total": Numberlong (6827)
},
"Count": {
"Failed": Numberlong (388),
"Total": Numberlong (491985789)
},
"Create": {
"Failed": Numberlong (0),
"Total": Numberlong (10)
},
"Createindexes": {
"Failed": Numberlong (1),
"Total": Numberlong (69)
},
"CreateUser": {
"Failed": Numberlong (6),
"Total": Numberlong (10)
},
"Currentop": {
"Failed": Numberlong (0),
"Total": Numberlong (15)
},
"DbStats": {
"Failed": Numberlong (7),
"Total": Numberlong (917)
},
"Delete": {
"Failed": Numberlong (0),
"Total": Numberlong (705)
},
"Distinct": {
"Failed": Numberlong (17),
"Total": Numberlong (5105)
},
"Drop": {
"Failed": Numberlong (0),
"Total": Numberlong (67)
},
"Dropdatabase": {
"Failed": Numberlong (0),
"Total": Numberlong (7)
},
"Dropindexes": {
"Failed": Numberlong (7),
"Total": Numberlong (23)
},
"Enablesharding": {
"Failed": Numberlong (1),
"Total": Numberlong (2)
},
"Explain": {
"Failed": Numberlong (0),
"Total": Numberlong (13)
},
"Find": {
"Failed": Numberlong (131),
"Total": Numberlong (1764517)
},
"Findandmodify": {
"Failed": Numberlong (1),
"Total": Numberlong (772)
},
"GetLastError": {
"Failed": Numberlong (0),
"Total": Numberlong (1989)
},
"GetLog": {
"Failed": Numberlong (0),
"Total": Numberlong (2)
},
"Getmore": {
"Failed": Numberlong (17),
"Total": Numberlong (1791)
},
"Getnonce": {
"Failed": Numberlong (0),
"Total": Numberlong (38)
},
"Insert": {
"Failed": Numberlong (0),
"Total": Numberlong (207939962)
},
"IsMaster": {
"Failed": Numberlong (0),
"Total": Numberlong (35391424)
},
"Killcursors": {
"Failed": Numberlong (0),
"Total": Numberlong (79)
},
"Listcollections": {
"Failed": Numberlong (0),
"Total": Numberlong (862)
},
"ListDatabases": {
"Failed": Numberlong (0),
"Total": Numberlong (263)
},
"Listindexes": {
"Failed": Numberlong (0),
"Total": Numberlong (8)
},
"Logout": {
"Failed": Numberlong (0),
"Total": Numberlong (8658)
},
"MapReduce": {
"Failed": Numberlong (24),
"Total": Numberlong (64)
},
"Ping": {
"Failed": Numberlong (0),
"Total": Numberlong (5980)
},
"Profile": {
"Failed": Numberlong (4),
"Total": Numberlong (4)
},
"Renamecollection": {
"Failed": Numberlong (0),
"Total": Numberlong (2)
},
"RepairDatabase": {
"Failed": Numberlong (0),
"Total": Numberlong (1)
},
"Replsetgetstatus": {
"Failed": Numberlong (88870),
"Total": Numberlong (88870)
},
"Rolesinfo": {
"Failed": Numberlong (0),
"Total": Numberlong (491)
},
"Saslcontinue": {
"Failed": Numberlong (4),
"Total": Numberlong (183362)
},
"Saslstart": {
"Failed": Numberlong (8),
"Total": Numberlong (91691)
},
"Serverstatus": {
"Failed": Numberlong (0),
"Total": Numberlong (223111)
},
"Shardcollection": {
"Failed": Numberlong (0),
"Total": Numberlong (3)
},
"Update": {
"Failed": Numberlong (0),
"Total": Numberlong (552681439)
},
"Usersinfo": {
"Failed": Numberlong (0),
"Total": Numberlong (493)
},
"Whatsmyuri": {
"Failed": Numberlong (0),
"Total": Numberlong (54513)
}
}
},
"OK": 1
}
Bye
Above is we execute the command from the MONGO server to obtain the parameters of the MONGO server, the following to monitor him.
First build the script check_mongo.sh
#!/bin/bash
#mongodb status
#b. Serverstatus (). OK
#memory status
#Physical memory: Db.serverstatus (). Mem.resident
#Virtual memory:db.serverStatus (). mem.virtual
#opcounters Status
#insert : Db.serverstatus (). Opcounters.insert
#query: Db.serverstatus (). Opcounters.query
#update: Db.serverstatus () . opcounters.update
#delete: Db.serverstatus (). Opcounters.delete
#connections status
#current connections : Db.serverstatus (). Connections.current
Mongodbpath= "/usr/bin/mongo"
host= "47.94.37.221"
port= "$"
Mongodb_pa= "$MONGODBPATH ${host}:${port}/admin-uroot-pkeytech2017"
If [$# = = 3];then
result=$ (/bin/echo "D B.serverstatus (). $2.$3 "| $MONGODB _pa--quiet)
Echo $result
elif [$# = = 2];then
result=$ (/bin/echo "Db.serverstatus (). $" | $MONGODB _PA --quiet)
Echo $result
Else
echo "usage:$0 PORT Mem resident"
Fi
Save Exit!
Here we can test the usability of our script:
Our tests here are entered in combination with the parameters shown after the first command is executed, such as:
This is the meaning of the argument behind the script. $: Port $ $: Main parameter $ $: The parameter you want to extract
And then we build the key we want.
Don't ask me what this directory is for, if you don't know it, learn Zabbix from the beginning.
In this directory I supervise a. conf file
This is everything inside of my key file, but the contents of the top are only written here.
userparameter=mongodb.totalcreated,/data/zabbix/scripts/check_mongodb.sh 20001 Connections totalCreated
userparameter=mongodb.available,/data/zabbix/scripts/check_mongodb.sh 20001 Connections Available
These two articles
The remaining two will be used (the bottom will say what these two do)
Add those two and we'll save the exit and then go to the web to customize the key for monitoring
Save, after a while to monitor the image will come out,
Ok! Monitoring complete
But ... MONGO so many surveillance items we're only monitoring two things right now, if you think the way you're yelling, you're going to have to follow your own. All keys are to be thanked, and other methods are described below.
The second way is what I said above, directly define key, in the key file inside the command as follows
Userparameter=mongodb.status[*],/bin/echo "Db.serverstatus (). $" |/usr/bin/mongo 192.168.16.111:20001/admin- Ulichao-plichao | grep "\<$2\>" |awk-f: ' {print $$2} ' |awk-f, ' {print $$1} '
Userparameter=mongodb.byesout,/bin/echo "Db.serverstatus (). Network" |/usr/bin/mongo 192.168.16.111:20001/admin- Ulichao-plichao | grep "Bytesout" | Awk-f: ' {print $} ' | Awk-f, ' {print $} ' | Awk-f \ "' {print $} '
Userparameter=mongodb.bytesin,/bin/echo "Db.serverstatus (). Network" |/usr/bin/mongo 192.168.16.111:20001/admin- Ulichao-plichao | grep "Bytesin" | Awk-f: ' {print $} ' | Awk-f, ' {print $} ' | Awk-f \ "' {print $} '
Add complete save save to exit.
Then directly import the template monitoring can. Template in this: Https://pan.baidu.com/s/1PFrhealedPUejz7ACI_WVA
Add to the Web I'm you can see on the graph
By this MONGO monitoring is complete.
系统运维工程师 李超
Online combat Zabbix Monitoring MongoDB detailed steps