├── LICENSE.md ├── README.md ├── mongodb-2.2 ├── MongoDB_Plugin_template_export.xml ├── mikoomi-mongodb-plugin.php └── mikoomi-mongodb-plugin.sh ├── mongodb-2.4 ├── MongoDB_Plugin_template_export-24.xml ├── mikoomi-mongodb-plugin-24.php └── mikoomi-mongodb-plugin-24.sh └── mongodb-3.2 ├── MongoDB_Plugin_template_export-32.xml ├── mikoomi-mongodb-plugin-32.php └── mikoomi-mongodb-plugin-32.sh /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jayesh Thakrar , Pal David Gergely 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MongoDB Zabbix monitoring plugin 2 | 3 | Overview 4 | ======== 5 | 6 | The *MongoDB Plugin* can be used to monitor standalone, replicated as well as clustered MongoDB instances with Zabbix. The plugin monitors availability, resource utilization, health, performance and other important metrics of a MongoDB environment. Coupled with the Zabbix OS level monitoring, the MongoDB plugin provides great peace of mind knowing that MongoDB is being monitored 24x7 and sufficient data would be available for sizing, scalability, troubleshooting and support. 7 | 8 | Important notes on Zabbix and MongoDB versions 9 | ============================================== 10 | 11 | **In general: try to use Zabbix and MongoDB versions "close" to each other and use the scripts from the right directory.** There will be a merge of versions and only new releases of MongoDB and Zabbix will be supported in some point in time later on, and then hopefully this confusion will be cleared. 12 | 13 | * **Zabbix 3.0.x and up:** there is a partially done and working script for this Zabbix version. Please test it using the `mongodb-3.2` directory as a basline. Any improvements on this are welcome for this part of the tool. That script should also support MongoDB version 3.2 as the directory suggests. 14 | * **Zabbix 2.4.x:** you should use files from the directory `mongodb-2.4` with the prefixes `-24` (`MongoDB_Plugin_template_export-24.xml`, `mikoomi-mongodb-plugin-24.php` and `mikoomi-mongodb-plugin-24.sh`) at any place where this README tells you about the version without the suffix. This may also work with MongoDB 3.0, but it's not guaranteed. 15 | * **Zabbix 2.2 and below:** You should just use `mongodb-2.2` directory and the documentation below in this README. 16 | 17 | Setup and Configuration 18 | ======================= 19 | 20 | The MongoDB plugin uses the MongoDB PHP driver which needs to be installed on the MongoDB node being monitored. For this, install and setup the following packages: 21 | 22 | * **php5-dev (or php5-devel)** = Files for PHP5 module development 23 | * **php5-pear** = PEAR - PHP Extension and Application Repository 24 | * **gcc** = GNU C Compiler 25 | * **make** = make utility 26 | 27 | For the above use the right package manager for your distribution (aptitude, yum, etc.) 28 | 29 | Now install the php MongoDB driver using the instructions at [http://us2.php.net/manual/en/mongo.installation.php](http://us2.php.net/manual/en/mongo.installation.php) 30 | 31 | Also you need the mongo PECL package for PHP which can be installed either by the package manager of your distribution or with this PECL command: 32 | 33 | ``` 34 | pecl install mongo 35 | ``` 36 | 37 | If you installed MongoDB driver via the PECL command, then you need to enable it for PHP. Edit the PHP configration of the server (e.g.: `/etc/php5/cli/php.ini`) and make sure the following line is present in it: 38 | 39 | ``` 40 | extension=mongo.so 41 | ``` 42 | 43 | Ensure that the php MongoDB driver is setup and configured properly by testing out one of the sample php programs for MongoDB driver ([http://us2.php.net/manual/en/mongo.tutorial.php](http://us2.php.net/manual/en/mongo.tutorial.php)). 44 | 45 | Download the MongoDB Plugin shell script and php file from [https://github.com/nightw/mikoomi-zabbix-mongodb-monitoring/find/master](https://github.com/nightw/mikoomi-zabbix-mongodb-monitoring/find/master) and copy them into `externalscripts` (e.g. `/etc/zabbix/externalscripts`) directory on the MongoDB node you want to monitor. **Make sure that the php script and shell script are made executable.** 46 | 47 | Next open up a browser and download the MongoDB Zabbix template. 48 | Now login to the Zabbix frontend (if it still has the default user and password, then it should be Admin/zabbix). 49 | 50 | Navigate as follows: 51 | 52 | * Configuration >> Templates 53 | * Click on the "Import Template" button on the top right-hand corner 54 | * In the "Import file" dialog box, browse/search/enter the filename of the Zabbix template that was downloaded 55 | * Upload the template 56 | 57 | Monitoring a MongoDB Environment (single server, replicaset or cluster) 58 | ======================================================================= 59 | 60 | Follow these steps to start monitoring a MongoDB server 61 | 62 | * Setting up Zabbix server's side 63 | * Make sure the host running the MongoDB is added to Zabbix Hosts previously (see host addition [here](https://www.zabbix.com/documentation/3.0/manual/quickstart/host)) 64 | * Login to the Zabbix front-end and navigate to **_Configuration >> Hosts_** 65 | * Click on host which is running the MongoDB button on the left 66 | * Click on **Templates** in the top menu bar 67 | * Use the **Select** button on the right side 68 | * Select the **Mikoomi Templates** group in the upper right corner 69 | * Check **Template_MongoDB** 70 | * Click on **Select** button 71 | * Click on **Add** button 72 | * Click **Save** 73 | * Setting up the MongoDB server node 74 | * Add something like this (look out especially for the **ZABBIX_HOSTNAME** variable, which must meet the name of the node in the Zabbix server which we attached the template to in the previous steps) the following to the Zabbix user's crontab: 75 | ``` 76 | ZABBIX_HOSTNAME=$(hostname -f) 77 | * * * * * /etc/zabbix/externalscripts/mikoomi-mongodb-plugin.sh -z $ZABBIX_HOSTNAME 78 | ``` 79 | 80 | **Note that in a sharded and/or replicated MongoDB environment, you need to monitor only ONE of the mongos process**. However that process needs to be aware of the entire Mongo environment (or cluster) - i.e. all the shards and all the replicas within each replicaset. 81 | 82 | Now data should be collected by the template at intervals of 60 seconds. 83 | 84 | If something is wrong (data does not show up in the Zabbix server, etc.) then you should run the script with the `-D` option for debug mode and then look at the output at /tmp/mikoomi-mongodb-plugin.php_*.log file. 85 | 86 | Monitored Metrics 87 | ================= 88 | 89 | The MongoDB plugin monitors the following metrics or items during each cycle: 90 | 91 | * Asserts: Total Msg Asserts 92 | * Asserts: Total Regular Asserts 93 | * Asserts: Total Assert Rollovers 94 | * Asserts: Total User Asserts 95 | * Asserts: Total Warning Asserts 96 | * Background Flushing: Background Flush Average Time (ms) 97 | * Background Flushing: Number of Flushes in Last 1 Minute 98 | * Background Flushing: Last Background Flush Time (ms) 99 | * Background Flushing: Total Background Flush Time (ms) in Last 1 Minute 100 | * Cursors: Client Cursor Size 101 | * Cursors: Cursor Time Outs 102 | * Cursors: Open Curors 103 | * Database Connections: Connections Available 104 | * Database Connections: Current Connections 105 | * Databases and Collections: List of All Database Stats 106 | * Databases and Collections: List of Database Average Object Size 107 | * Databases and Collections: List of Database Collection Count 108 | * Databases and Collections: Database Count 109 | * Databases and Collections: List of Database Data Size 110 | * Databases and Collections: List of Database File Size 111 | * Databases and Collections: List of Database Index Count 112 | * Databases and Collections: List of Database Index Size 113 | * Databases and Collections: Total Collections Across All Databases 114 | * Databases and Collections: Total Indexes Across All Collections 115 | * Databases and Collections: Total Objects Across All Databases 116 | * Databases and Collections: Total Size of All Databases (MB) 117 | * Databases and Collections: List of Database Extent Count 118 | * Databases and Collections: List of Database Object Count 119 | * Databases and Collections: List of Database Storage Size 120 | * Global Locking: Current Reader Queue Length 121 | * Global Locking: Current Total Queue Length 122 | * Global Locking: Current Writer Queue Length 123 | * Global Locking: Total Lock Time (microseconds) in Last 1 Minute 124 | * Index Effectiveness: Total Btree Accesses in Last 1 Minute 125 | * Index Effectiveness: Total Btree Hits in Last 1 Minute 126 | * Index Effectiveness: Total Btree Misses in Last 1 Minute 127 | * Index Effectiveness: Btree Miss Ratio 128 | * Index Effectiveness: Total Btree Resets 129 | * Journaling: Commits in last 1 Minute 130 | * Journaling: Commits in Writelocks in last 1 Minute 131 | * Journaling: Datafile Write Time (ms) in last 1 Minute 132 | * Journaling: Datafile Writes (MB) in last 1 Minute 133 | * Journaling: Early Commits in last 1 Minute 134 | * Journaling: Journal Write Time (ms) in last 1 Minute 135 | * Journaling: Journal Writes (MB) in last 1 Minute 136 | * Journaling: Log Buffer Prep Time (ms) in last 1 Minute 137 | * Memory: Heap Memory Size (MB) 138 | * Memory: Page Faults/minute 139 | * Memory: Memory Addressing (32/64 bit) 140 | * Memory: Resident Memory Size (MB) 141 | * Memory: Virtual Memory Size (MB) 142 | * Miscellaneous: MongoDB Plugin Checksum 143 | * Miscellaneous: MongoDB Plugin Data Collection Time (seconds) 144 | * Miscellaneous: MongoDB Plugin Version 145 | * Miscellaneous: MongoDB Version 146 | * Miscellaneous: MongoDB Uptime (seconds) 147 | * Network Activity: Network Inbound Traffic (MB) 148 | * Network Activity: Network Outbound Traffic (MB) 149 | * Network Activity: Network Requests 150 | * Performance: Is there any writeback operations queued 151 | * OpCounters: Total Commands in Last 1 Minute 152 | * OpCounters: Total Delete Ops in Last 1 Minute 153 | * OpCounters: Total Getmore Ops in Last 1 Minute 154 | * OpCounters: Total Insert Ops in Last 1 Minute 155 | * OpCounters: Total Query Ops in Last 1 Minute 156 | * OpCounters: Total Update Ops in Last 1 Minute 157 | * Replication: Is Mongo Server Part of a ReplicatSet 158 | * Replication: Entries in oplog.rs Collection 159 | * Replication: Count of ReplicaSet Members Needing Attention 160 | * Replication: List of ReplicaSet Members in Attention State 161 | * Replication: ReplicaSet Host Names 162 | * Replication: ReplicaSet Member Count 163 | * Replication: ReplicaSet Name 164 | * Sharding: Is Mongo Server a Cluster Router (mongos process) 165 | * Sharding: List of Sharded Databases and Collections 166 | * Sharding: Total Number of Chunks 167 | * Sharding: Total Number of Shards 168 | * Sharding: List of Shards in Cluster 169 | * Sharding: List of Sharded Collections in Cluster 170 | * Sharding: Total Number of Sharded Collections 171 | 172 | Pre-canned Triggers 173 | =================== 174 | 175 | Triggers in Zabbix are events of interest that happen with respect to the monitored metrics. For example, the plugin keeps track of the total number of collections. If this count changes, it flags this event by firing a trigger. You can choose to ignore this trigger or you can choose to take an action - e.g. send an email or run a shell script. 176 | 177 | The MongoDB plugin comes with the following built-in triggers: 178 | 179 | * One or more databases have been created 180 | * One or more databases have been destroyed 181 | * No Data Received in 5 minutes 182 | * One or more replication members need attention 183 | * One or more members have been removed from the ReplicaSet 184 | * One or more members have been added to the ReplicaSet 185 | * One or more new shard chunks have been created 186 | * One or more shards have been added to the cluster 187 | * One or more shards have been removed from the cluster 188 | * One or more new sharded collections have been created 189 | * One or more collections have been dropped 190 | * One or more collections have been added 191 | * One or more indexes have been dropped 192 | * One or more indexes have been added 193 | 194 | Pre-canned Graphs 195 | ================= 196 | 197 | While Zabbix allows creating graphing one or more monitored metric, the plugin comes with the following pre-canned graphs to get you productive immediately: 198 | 199 | **MongoDB Cumulative Database Size in MB** 200 | 201 | **MongoDB Memory Footprint:** This graph plots the following metrics 202 | 203 | * Virtual Memory Size (MB) 204 | * Heap Memory Size (MB) 205 | * Resident Memory Size (MB) 206 | 207 | **MongoDB Database Operations:** This graph plots the following metrics 208 | 209 | * Total Query Ops in Last 1 Minute 210 | * Total Update Ops in Last 1 Minute 211 | * Total Insert Ops in Last 1 Minute 212 | * Total Delete Ops in Last 1 Minute 213 | * Total Command Ops in Last 1 Minute 214 | * Total Get More Ops in Last 1 Minute 215 | 216 | **MongoDB Journaling:** This graph plots the following metrics 217 | 218 | * Commits in last 1 Minute 219 | * Datafile Writes (MB) in last 1 Minute 220 | * Datafile Write Time (ms) in last 1 Minute 221 | * Journaling: Journal Writes (MB) in last 1 Minute 222 | * Journaling: Journal Write Time (ms) in last 1 Minute 223 | -------------------------------------------------------------------------------- /mongodb-2.2/mikoomi-mongodb-plugin.php: -------------------------------------------------------------------------------- 1 | ] [-p ] [--ssl] [-u ] [-x ] [-H ] [-P ] -z 42 | where 43 | -D = Run in detail/debug mode 44 | -h = Hostname or IP address of server running MongoDB 45 | -p = Port number on which to connect to the mongod or mongos process 46 | -z = Name (hostname) of MongoDB instance or cluster in the Zabbix UI 47 | -u = User name for database authentication 48 | -x = Password for database authentication 49 | -H = Zabbix server IP or hostname 50 | -P = Zabbix server Port or hostname 51 | --ssl = Use SSL when connecting to MongoDB 52 | " ; 53 | 54 | exit ; 55 | } 56 | 57 | //-------------------------------------------------------------------------// 58 | // Setup log file, data file and zabbix hostname. 59 | //-------------------------------------------------------------------------// 60 | $zabbix_name = $options['z'] ; 61 | 62 | // Remove spaces from zabbix name for file data and log file creation 63 | $file_base_name = str_replace(' ', '_', $zabbix_name); 64 | 65 | $zabbix_server = ($options['H'] ? $options['H'] : '127.0.0.1'); 66 | $zabbix_server_port = ($options['P'] ? $options['P'] : '10051'); 67 | 68 | $debug_mode = isset($options['D']) ; 69 | 70 | $ssl = isset($options['ssl']) ; 71 | 72 | if ($ssl && !MONGO_SUPPORTS_SSL) { 73 | echo "WARNING: --ssl option is specified, but we will not use it, because the PHP Mongo extension does not support SSL!\n" ; 74 | $ssl = false ; 75 | } 76 | 77 | $data_lines = array() ; 78 | 79 | $md5_checksum_string = md5_file($argv[0]) ; 80 | 81 | if ($debug_mode) { 82 | write_to_log("version $command_version") ; 83 | } 84 | //-------------------------------------------------------------------------// 85 | 86 | //-------------------------------------------------------------------------// 87 | function write_to_log($output_line) 88 | //-------------------------------------------------------------------------// 89 | { 90 | global $command_name ; 91 | fprintf(STDERR, "%s: %s\n", $command_name, $output_line) ; 92 | } 93 | //-------------------------------------------------------------------------// 94 | 95 | 96 | 97 | //-------------------------------------------------------------------------// 98 | function write_to_data_lines($zabbix_name, $key, $value) 99 | //-------------------------------------------------------------------------// 100 | { 101 | global $data_lines ; 102 | 103 | // Only if we have a value do we want to record this metric 104 | if(isset($value) && $value !== '') 105 | { 106 | $data_line = sprintf("\"%s\" \"%s\" \"%s\"", $zabbix_name, $key, $value) ; 107 | $data_lines[] = $data_line ; 108 | } 109 | } 110 | //-------------------------------------------------------------------------// 111 | 112 | 113 | //-------------------------------------------------------------------------// 114 | // Now starts the heart of mongoDB monitoring !! 115 | //-------------------------------------------------------------------------// 116 | 117 | //----------------------------- 118 | // Setup connection to mongoDB 119 | //----------------------------- 120 | $mongodb_host = empty($options['h']) ? Mongo::DEFAULT_HOST : $options['h'] ; 121 | $mongodb_port = empty($options['p']) ? Mongo::DEFAULT_PORT : $options['p'] ; 122 | 123 | if ((!empty($options['u'])) && (!empty($options['x']))) { 124 | $connect_string = $options['u'] . ':' . $options['x'] . '@' . $mongodb_host . ':' . $mongodb_port ; 125 | } 126 | else { 127 | $connect_string = $mongodb_host . ':' . $mongodb_port ; 128 | } 129 | 130 | if ($ssl) { 131 | $connect_string .= "/?ssl=true" ; 132 | } 133 | 134 | $mongo_connection = new Mongo("mongodb://$connect_string") ; 135 | 136 | if (is_null($mongo_connection)) { 137 | write_to_log("Error in connection to mongoDB using connect string $connect_string") ; 138 | exit ; 139 | } 140 | else { 141 | write_to_log("Successfully connected to mongoDB using connect string $connect_string") ; 142 | } 143 | 144 | 145 | //----------------------------- 146 | // Get server statistics 147 | //----------------------------- 148 | $mongo_db_handle = $mongo_connection->selectDB("config") ; 149 | 150 | $server_status = $mongo_db_handle->command(array('serverStatus'=>1)) ; 151 | 152 | if (!isset($server_status['ok'])) { 153 | write_to_log("Error in executing $command.") ; 154 | exit ; 155 | } 156 | 157 | $mongo_version = $server_status['version'] ; 158 | write_to_data_lines($zabbix_name, "mongodb_version", $mongo_version) ; 159 | 160 | $uptime = $server_status['uptime'] ; 161 | write_to_data_lines($zabbix_name, "uptime", $uptime) ; 162 | 163 | if ($server_status['globalLock']['lockTime'] != null) { 164 | $globalLock_lockTime = $server_status['globalLock']['lockTime'] ; 165 | write_to_data_lines($zabbix_name, "globalLock_lockTime", $globalLock_lockTime) ; 166 | } 167 | 168 | if ($server_status['globalLock']['totalTime'] != null) { 169 | $globalLock_totalTime = $server_status['globalLock']['totalTime'] ; 170 | write_to_data_lines($zabbix_name, "globalLock_totalTime", $globalLock_totalTime) ; 171 | } 172 | 173 | $globalLock_currentQueue_total = $server_status['globalLock']['currentQueue']['total'] ; 174 | write_to_data_lines($zabbix_name, "globalLock_currentQueue_total", $globalLock_currentQueue_total) ; 175 | 176 | $globalLock_currentQueue_readers = $server_status['globalLock']['currentQueue']['readers'] ; 177 | write_to_data_lines($zabbix_name, "globalLock_currentQueue_readers", $globalLock_currentQueue_readers) ; 178 | 179 | $globalLock_currentQueue_writers = $server_status['globalLock']['currentQueue']['writers'] ; 180 | write_to_data_lines($zabbix_name, "globalLock_currentQueue_writers", $globalLock_currentQueue_writers) ; 181 | 182 | $mem_bits = $server_status['mem']['bits'] ; 183 | write_to_data_lines($zabbix_name, "mem_bits", $mem_bits) ; 184 | 185 | $mem_resident = $server_status['mem']['resident'] ; 186 | write_to_data_lines($zabbix_name, "mem_resident", $mem_resident) ; 187 | 188 | $mem_virtual = $server_status['mem']['virtual'] ; 189 | write_to_data_lines($zabbix_name, "mem_virtual", $mem_virtual) ; 190 | 191 | $connections_current = $server_status['connections']['current'] ; 192 | write_to_data_lines($zabbix_name, "connections_current", $connections_current) ; 193 | 194 | $connections_available = $server_status['connections']['available'] ; 195 | write_to_data_lines($zabbix_name, "connections_available", $connections_available) ; 196 | 197 | $extra_info_heap_usage = round(($server_status['extra_info']['heap_usage_bytes'])/(1024*124), 2) ; 198 | write_to_data_lines($zabbix_name, "extra_info_heap_usage", $extra_info_heap_usage) ; 199 | 200 | $extra_info_page_faults = $server_status['extra_info']['page_faults']; 201 | write_to_data_lines($zabbix_name, "extra_info_page_faults", $extra_info_page_faults) ; 202 | 203 | if ($server_status['indexCounters']['btree']['accesses'] != null) { 204 | $indexCounters_btree_accesses = $server_status['indexCounters']['btree']['accesses'] ; 205 | } else { 206 | $indexCounters_btree_accesses = $server_status['indexCounters']['accesses'] ; 207 | } 208 | write_to_data_lines($zabbix_name, "indexCounters_btree_accesses", $indexCounters_btree_accesses) ; 209 | 210 | if ($server_status['indexCounters']['btree']['hits'] != null) { 211 | $indexCounters_btree_hits = $server_status['indexCounters']['btree']['hits'] ; 212 | } else { 213 | $indexCounters_btree_hits = $server_status['indexCounters']['hits'] ; 214 | } 215 | write_to_data_lines($zabbix_name, "indexCounters_btree_hits", $indexCounters_btree_hits) ; 216 | 217 | if ($server_status['indexCounters']['btree']['misses'] != null) { 218 | $indexCounters_btree_misses = $server_status['indexCounters']['btree']['misses'] ; 219 | } else { 220 | $indexCounters_btree_misses = $server_status['indexCounters']['misses'] ; 221 | } 222 | write_to_data_lines($zabbix_name, "indexCounters_btree_misses", $indexCounters_btree_misses) ; 223 | 224 | if ($server_status['indexCounters']['btree']['resets'] != null) { 225 | $indexCounters_btree_resets = $server_status['indexCounters']['btree']['resets'] ; 226 | } else { 227 | $indexCounters_btree_resets = $server_status['indexCounters']['resets'] ; 228 | } 229 | write_to_data_lines($zabbix_name, "indexCounters_btree_resets", $indexCounters_btree_resets) ; 230 | 231 | if ($server_status['indexCounters']['btree']['missRatio'] != null) { 232 | $indexCounters_btree_missRatio = $server_status['indexCounters']['btree']['missRatio'] ; 233 | } else { 234 | $indexCounters_btree_missRatio = $server_status['indexCounters']['missRatio'] ; 235 | } 236 | write_to_data_lines($zabbix_name, "indexCounters_btree_missRatio", $indexCounters_btree_missRatio) ; 237 | 238 | $backgroundFlushing_flushes = $server_status['backgroundFlushing']['flushes'] ; 239 | write_to_data_lines($zabbix_name, "backgroundFlushing_flushes", $backgroundFlushing_flushes) ; 240 | 241 | $backgroundFlushing_total_ms = $server_status['backgroundFlushing']['total_ms'] ; 242 | write_to_data_lines($zabbix_name, "backgroundFlushing_total_ms", $backgroundFlushing_total_ms) ; 243 | 244 | $backgroundFlushing_average_ms = $server_status['backgroundFlushing']['average_ms'] ; 245 | write_to_data_lines($zabbix_name, "backgroundFlushing_average_ms", $backgroundFlushing_average_ms) ; 246 | 247 | $backgroundFlushing_last_ms = $server_status['backgroundFlushing']['last_ms'] ; 248 | write_to_data_lines($zabbix_name, "backgroundFlushing_last_ms", $backgroundFlushing_last_ms) ; 249 | 250 | $cursors_totalOpen = $server_status['cursors']['totalOpen'] ; 251 | write_to_data_lines($zabbix_name, "cursors_totalOpen", $cursors_totalOpen) ; 252 | 253 | $cursors_clientCursors_size = $server_status['cursors']['clientCursors_size'] ; 254 | write_to_data_lines($zabbix_name, "cursors_clientCursors_size", $cursors_clientCursors_size) ; 255 | 256 | $cursors_timedOut = $server_status['cursors']['timedOut'] ; 257 | write_to_data_lines($zabbix_name, "cursors_timedOut", $cursors_timedOut) ; 258 | 259 | $opcounters_insert = $server_status['opcounters']['insert'] ; 260 | write_to_data_lines($zabbix_name, "opcounters_insert", $opcounters_insert) ; 261 | 262 | $opcounters_query = $server_status['opcounters']['query'] ; 263 | write_to_data_lines($zabbix_name, "opcounters_query", $opcounters_query) ; 264 | 265 | $opcounters_update = $server_status['opcounters']['update'] ; 266 | write_to_data_lines($zabbix_name, "opcounters_update", $opcounters_update) ; 267 | 268 | $opcounters_delete = $server_status['opcounters']['delete'] ; 269 | write_to_data_lines($zabbix_name, "opcounters_delete", $opcounters_delete) ; 270 | 271 | $opcounters_getmore = $server_status['opcounters']['getmore'] ; 272 | write_to_data_lines($zabbix_name, "opcounters_getmore", $opcounters_getmore) ; 273 | 274 | $opcounters_command = $server_status['opcounters']['command'] ; 275 | write_to_data_lines($zabbix_name, "opcounters_command", $opcounters_command) ; 276 | 277 | $asserts_regular = $server_status['asserts']['regular'] ; 278 | write_to_data_lines($zabbix_name, "asserts_regular", $asserts_regular) ; 279 | 280 | $asserts_warning = $server_status['asserts']['warning'] ; 281 | write_to_data_lines($zabbix_name, "asserts_warning", $asserts_warning) ; 282 | 283 | $asserts_msg = $server_status['asserts']['msg'] ; 284 | write_to_data_lines($zabbix_name, "asserts_msg", $asserts_msg) ; 285 | 286 | $asserts_user = $server_status['asserts']['user'] ; 287 | write_to_data_lines($zabbix_name, "asserts_user", $asserts_user) ; 288 | 289 | $asserts_rollovers = $server_status['asserts']['rollovers'] ; 290 | write_to_data_lines($zabbix_name, "asserts_rollovers", $asserts_rollovers) ; 291 | 292 | $network_inbound_traffic_mb = ($server_status['network']['bytesIn'])/(1024*1024) ; 293 | write_to_data_lines($zabbix_name, "network_inbound_traffic_mb", $network_inbound_traffic_mb) ; 294 | 295 | $network_outbound_traffic_mb = ($server_status['network']['bytesOut'])/(1024*1024) ; 296 | write_to_data_lines($zabbix_name, "network_outbound_traffic_mb", $network_outbound_traffic_mb) ; 297 | 298 | $network_requests = $server_status['network']['numRequests'] ; 299 | write_to_data_lines($zabbix_name, "network_requests", $network_requests) ; 300 | 301 | $write_backs_queued = $server_status['writeBacksQueued'] ; 302 | if ($write_backs_queued) { 303 | write_to_data_lines($zabbix_name, "write_backs_queued", "Yes") ; 304 | } else { 305 | write_to_data_lines($zabbix_name, "write_backs_queued", "No") ; 306 | } 307 | 308 | $logging_commits = $server_status['dur']['commits'] ; 309 | write_to_data_lines($zabbix_name, "logging_commits", $logging_commits) ; 310 | 311 | $logging_journal_writes_mb = $server_status['dur']['journaledMB'] ; 312 | write_to_data_lines($zabbix_name, "logging_journal_writes_mb", $logging_journal_writes_mb) ; 313 | 314 | $logging_datafile_writes_mb = $server_status['dur']['writeToDataFilesMB'] ; 315 | write_to_data_lines($zabbix_name, "logging_datafile_writes_mb", $logging_datafile_writes_mb) ; 316 | 317 | $logging_commits_in_writelock = $server_status['dur']['commitsInWriteLock'] ; 318 | write_to_data_lines($zabbix_name, "logging_commits_in_writelock", $logging_commits_in_writelock) ; 319 | 320 | $logging_early_commits = $server_status['dur']['earlyCommits'] ; 321 | write_to_data_lines($zabbix_name, "logging_early_commits", $logging_early_commits) ; 322 | 323 | $logging_log_buffer_prep_time_ms = $server_status['dur']['timeMs']['prepLogBuffer'] ; 324 | write_to_data_lines($zabbix_name, "logging_log_buffer_prep_time_ms", $logging_log_buffer_prep_time_ms) ; 325 | 326 | $logging_journal_write_time_ms = $server_status['dur']['timeMs']['writeToJournal'] ; 327 | write_to_data_lines($zabbix_name, "logging_journal_write_time_ms", $logging_journal_write_time_ms) ; 328 | 329 | $logging_datafile_write_time_ms = $server_status['dur']['timeMs']['writeToDataFiles'] ; 330 | write_to_data_lines($zabbix_name, "logging_datafile_write_time_ms", $logging_datafile_write_time_ms) ; 331 | 332 | //----------------------------- 333 | // Get DB list and cumulative DB info 334 | //----------------------------- 335 | $db_list = $mongo_connection->listDBs() ; 336 | 337 | $db_count = count($db_list) ; 338 | write_to_data_lines($zabbix_name, "db_count", $db_count) ; 339 | 340 | $totalSize = round(($db_list['totalSize'])/(1024*1024), 2) ; 341 | write_to_data_lines($zabbix_name, "totalSize", $totalSize) ; 342 | 343 | $sharded_db_count = 0 ; 344 | $total_collection_count = 0 ; 345 | $total_object_count = 0 ; 346 | $total_index_count = 0 ; 347 | $total_index_size = 0.0 ; 348 | 349 | $is_sharded = 'No' ; 350 | 351 | $db_info_array = '' ; 352 | $db_info_collections = '' ; 353 | $db_info_objects = '' ; 354 | $db_info_indexes = '' ; 355 | $db_info_avgObjSize = '' ; 356 | $db_info_dataSize = '' ; 357 | $db_info_indexSize = '' ; 358 | $db_info_storageSize = '' ; 359 | $db_info_numExtents_array = '' ; 360 | $db_info_fileSize = '' ; 361 | 362 | 363 | foreach($db_list['databases'] as $db) { 364 | if(isset($db['shards'])) { 365 | $is_sharded = 'Yes' ; 366 | } 367 | else { 368 | // Do nothing ! 369 | } 370 | 371 | $mongo_db_handle = $mongo_connection->selectDB($db['name']) ; 372 | $db_stats = $mongo_db_handle->command(array('dbStats'=>1)) ; 373 | 374 | $execute_status = $db_stats['ok'] ; 375 | 376 | if ($execute_status == 0) { 377 | write_to_log("Error in executing $command for database ".$db['name']) ; 378 | exit ; 379 | } 380 | 381 | $total_collection_count += $db_stats['collections'] ; 382 | $total_object_count += $db_stats['objects'] ; 383 | $total_index_count += $db_stats['indexes'] ; 384 | $total_index_size += $db_stats['indexSize'] ; 385 | 386 | $db_info_array[$db['name']] .= ' collections=' . $db_stats['collections'] . 387 | ', objects=' . $db_stats['objects'] . 388 | ', indexes=' . $db_stats['indexes'] . 389 | ', avgObjSize=' . $db_stats['avgObjSize'] . 390 | ', dataSize=' . $db_stats['dataSize'] . 391 | ', indexSize=' . $db_stats['indexSize'] . 392 | ', storageSize=' . $db_stats['storageSize'] . 393 | ', numExtents=' . $db_stats['numExtents'] . 394 | ', fileSize=' . $db_stats['fileSize'] ; 395 | 396 | $db_info_collections .= $db['name'] . '=' . $db_stats['collections'] . ' || ' ; 397 | $db_info_objects .= $db['name'] . '=' . $db_stats['objects'] . ' || ' ; 398 | $db_info_indexes .= $db['name'] . '=' . $db_stats['indexes'] . ' || ' ; 399 | $db_info_avgObjSize .= $db['name'] . '=' . $db_stats['avgObjSize'] . ' || '; 400 | $db_info_dataSize .= $db['name'] . '=' . $db_stats['dataSize'] . ' || '; 401 | $db_info_indexSize .= $db['name'] . '=' . $db_stats['indexSize'] . ' || '; 402 | $db_info_storageSize .= $db['name'] . '=' . $db_stats['storageSize'] . ' || '; 403 | $db_info_numExtents_array .= $db['name'] . '=' . $db_stats['numExtents'] . ' || '; 404 | $db_info_fileSize .= $db['name'] . '=' . $db_stats['fileSize'] . ' || '; 405 | } 406 | 407 | $db_info = ''; 408 | foreach($db_info_array as $key=>$value) { 409 | $db_info .= $key . ':' . $value . ' || ' ; 410 | } 411 | 412 | write_to_data_lines($zabbix_name, "database_info", $db_info) ; 413 | 414 | write_to_data_lines($zabbix_name, "is_sharded", $is_sharded) ; 415 | 416 | write_to_data_lines($zabbix_name, "total_collection_count", $total_collection_count) ; 417 | 418 | write_to_data_lines($zabbix_name, "total_object_count", $total_object_count) ; 419 | 420 | write_to_data_lines($zabbix_name, "total_index_count", $total_index_count) ; 421 | 422 | $total_index_size = round($total_index_size/(1024*1024), 2) ; 423 | write_to_data_lines($zabbix_name, "total_index_size", $total_index_size) ; 424 | 425 | write_to_data_lines($zabbix_name, "db_collections", $db_info_collections) ; 426 | write_to_data_lines($zabbix_name, "db_objects", $db_info_objects) ; 427 | write_to_data_lines($zabbix_name, "db_indexes", $db_info_indexes) ; 428 | write_to_data_lines($zabbix_name, "db_avgObjSize", $db_info_avgObjSize) ; 429 | write_to_data_lines($zabbix_name, "db_dataSize", $db_info_dataSize) ; 430 | write_to_data_lines($zabbix_name, "db_indexSize", $db_info_indexSize) ; 431 | write_to_data_lines($zabbix_name, "db_storageSize", $db_info_storageSize) ; 432 | write_to_data_lines($zabbix_name, "db_numExtents", $db_info_numExtents_array) ; 433 | write_to_data_lines($zabbix_name, "db_fileSize", $db_info_fileSize) ; 434 | 435 | 436 | //----------------------------- 437 | // Check for replication / replicaSets 438 | //----------------------------- 439 | if ($is_sharded == 'No') { 440 | $mongo_db_handle = $mongo_connection->selectDB('admin') ; 441 | $rs_status = $mongo_db_handle->command(array('replSetGetStatus'=>1)) ; 442 | 443 | if (!($rs_status['ok'])) { 444 | write_to_data_lines($zabbix_name, "is_replica_set", "No") ; 445 | } 446 | else { 447 | write_to_data_lines($zabbix_name, "is_replica_set", "Yes") ; 448 | write_to_data_lines($zabbix_name, "replica_set_name", $rs_status['set']) ; 449 | write_to_data_lines($zabbix_name, "replica_set_member_count", count($rs_status['members']) ) ; 450 | 451 | $repl_set_member_names = '' ; 452 | foreach ($rs_status['members'] as $repl_set_member) { 453 | $repl_set_member_names .= 'host#' . $repl_set_member['_id'] . ' = ' . $repl_set_member['name'] . ' || ' ; 454 | } 455 | write_to_data_lines($zabbix_name, "replica_set_hosts", $repl_set_member_names) ; 456 | 457 | $local_mongo_db_handle = $mongo_connection->selectDB('local') ; 458 | $col_name = 'oplog.rs' ; 459 | $mongo_collection = $local_mongo_db_handle->$col_name ; 460 | $oplog_rs_count = $mongo_collection->count() ; 461 | write_to_data_lines($zabbix_name, "oplog.rs_count", $oplog_rs_count) ; 462 | 463 | //$rs_status = $mongo_db_handle->execute("$command") ; 464 | $repl_member_attention_state_count = 0 ; 465 | $repl_member_attenntion_state_info = '' ; 466 | 467 | foreach($rs_status['members'] as $member) { 468 | $member_state = $member['state'] ; 469 | 470 | $host = explode(':', $member['name']); 471 | $hostname = $host[0]; 472 | 473 | if ($member_state == 1) { 474 | $master_optime = $member['optime']; 475 | } 476 | 477 | $fqdn = explode('.', $mongodb_host); 478 | $mongodb_host_simple = $fqdn[0]; 479 | 480 | if (!in_array($hostname, array($mongodb_host_simple, $mongodb_host))) { 481 | continue; 482 | } 483 | 484 | $mongo_host_optime = $member['optime']; 485 | $seconds = $master_optime->sec - $mongo_host_optime->sec; 486 | 487 | if ($seconds < 0) { 488 | $seconds = 0; 489 | } 490 | 491 | write_to_data_lines($zabbix_name, "repl_member_replication_lag_sec", $seconds) ; 492 | 493 | if($member_state == 0 or $member_state == 3 or $member_state == 4 or $member_state == 5 or $member_state == 6 or $member_state == 8) { 494 | // 0 = Starting up, phase 1 495 | // 1 = primary 496 | // 2 = secondary 497 | // 3 = recovering 498 | // 4 = fatal error 499 | // 5 = starting up, phase 2 500 | // 6 = unknown state 501 | // 7 = arbiter 502 | echo "aaa\n" ; 503 | // 8 = down 504 | $repl_member_attention_state_count++ ; 505 | switch ($member_state) { 506 | case 0: $member_state = 'starting up, phase 1' ; 507 | break ; 508 | case 3: $member_state = 'recovering' ; 509 | break ; 510 | case 4: $member_state = 'fatal error' ; 511 | break ; 512 | case 5: $member_state = 'starting up, phase 2' ; 513 | break ; 514 | case 6: $member_state = 'unknown' ; 515 | break ; 516 | case 8: $member_state = 'down' ; 517 | break ; 518 | default: $member_state = 'unknown' ; 519 | break ; 520 | } 521 | $repl_member_attention_state_info .= $member['name'] . ' is in state ' . $member_state . ' ||' ; 522 | } 523 | } 524 | write_to_data_lines($zabbix_name, "repl_member_attention_state_count", $repl_member_attention_state_count) ; 525 | write_to_data_lines($zabbix_name, "repl_member_attention_state_info", ($repl_member_attention_state_count > 0 ? $repl_member_attention_state_info : 'empty') ) ; 526 | } 527 | 528 | } 529 | 530 | //----------------------------- 531 | // Check for sharding 532 | //----------------------------- 533 | if ($is_sharded == 'Yes') { 534 | $mongo_db_handle = $mongo_connection->selectDB('config') ; 535 | 536 | $mongo_collection = $mongo_db_handle->chunks ; 537 | $shard_info = $mongo_collection->count() ; 538 | write_to_data_lines($zabbix_name, "shard_chunk_count", $shard_info) ; 539 | 540 | $mongo_collection = $mongo_db_handle->collections ; 541 | $shard_info = $mongo_collection->count() ; 542 | write_to_data_lines($zabbix_name, "sharded_collections_count", $shard_info) ; 543 | 544 | $collection = $mongo_connection->selectDB('config')->selectCollection('collections') ; 545 | $cursor = $collection->find() ; 546 | $collection_array = iterator_to_array($cursor) ; 547 | $collection_info = '' ; 548 | foreach ($collection_array as $shard) { 549 | $collection_info .= $shard['_id'] . ' || ' ; 550 | } 551 | write_to_data_lines($zabbix_name, "sharded_collection_info", $collection_info) ; 552 | 553 | 554 | $command = "db.shards.count" ; 555 | $mongo_collection = $mongo_db_handle->shards ; 556 | $shard_info = $mongo_collection->count() ; 557 | write_to_data_lines($zabbix_name, "shard_count", $shard_info) ; 558 | 559 | $collection = $mongo_connection->selectDB('config')->selectCollection('shards') ; 560 | $cursor = $collection->find() ; 561 | $shards_array = iterator_to_array($cursor) ; 562 | $shard_info = '' ; 563 | foreach ($shards_array as $shard) { 564 | $shard_info .= $shard['_id'] . ' = ' . $shard['host'] . ' || ' ; 565 | } 566 | write_to_data_lines($zabbix_name, "shard_info", $shard_info) ; 567 | 568 | $collection = $mongo_connection->selectDB('config')->selectCollection('databases') ; 569 | $cursor = $collection->find() ; 570 | $db_array = iterator_to_array($cursor) ; 571 | $db_info = '' ; 572 | foreach ($db_array as $db) { 573 | if( $db['partitioned'] ) { 574 | $partitioned = 'yes' ; 575 | } 576 | else { 577 | $partitioned = 'no' ; 578 | } 579 | $db_info .= $db['_id'] . ' : ' . 'partitioned = ' . $partitioned . ', primary = ' . $db['primary'] . ' || ' ; 580 | } 581 | write_to_data_lines($zabbix_name, "db_info", $db_info) ; 582 | 583 | 584 | } 585 | 586 | //-------------------------------------------------------------------------// 587 | 588 | 589 | // Get data collection end time (we will use this to compute the total data collection time) 590 | $end_time = time() ; 591 | $data_collection_time = $end_time - $start_time ; 592 | write_to_data_lines($zabbix_name, "mongoDB_plugin_data_collection_time", $data_collection_time) ; 593 | 594 | write_to_data_lines($zabbix_name, "mongoDB_plugin_version", $command_version) ; 595 | write_to_data_lines($zabbix_name, "mongoDB_plugin_checksum", $md5_checksum_string) ; 596 | 597 | // For DEBUG 598 | if ($debug_mode) { 599 | $data_file_name = "/tmp/${command_name}_${file_base_name}.data" ; 600 | file_put_contents($data_file_name, implode("\n", $data_lines) . "\n") ; 601 | } 602 | 603 | $descriptorspec = array( 604 | 0 => array("pipe", "r"), // stdin 605 | 1 => array("pipe", "w"), // stdout 606 | 2 => array("pipe", "w") // stderr 607 | ) ; 608 | $process = proc_open("zabbix_sender -vv -z $zabbix_server -p $zabbix_server_port -i - 2>&1", $descriptorspec, $pipes) ; 609 | 610 | if (is_resource($process)) { 611 | fwrite($pipes[0], implode("\n", $data_lines)) ; 612 | fclose($pipes[0]) ; 613 | 614 | while($s = fgets($pipes[1], 1024)) { 615 | write_to_log("O: " . trim($s)) ; 616 | } 617 | fclose($pipes[1]); 618 | 619 | while($s= fgets($pipes[2], 1024)) { 620 | write_to_log("E: " . trim($s)) ; 621 | } 622 | fclose($pipes[2]) ; 623 | } 624 | 625 | exit ; 626 | 627 | ?> 628 | -------------------------------------------------------------------------------- /mongodb-2.2/mikoomi-mongodb-plugin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=$PATH:/etc/zabbix/externalscripts:/opt/zabbix/externalscripts:/opt/zabbix/bin:/home/zabbix/bin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin 3 | export PATH 4 | BASE_DIR="`dirname $0`" 5 | /usr/bin/php $BASE_DIR/mikoomi-mongodb-plugin.php $* 6 | echo 0 7 | -------------------------------------------------------------------------------- /mongodb-2.4/mikoomi-mongodb-plugin-24.php: -------------------------------------------------------------------------------- 1 | ] [-p ] [--ssl] [-u ] [-x ] [-H ] [-P ] -z 42 | where 43 | -D = Run in detail/debug mode 44 | -h = Hostname or IP address of server running MongoDB 45 | -p = Port number on which to connect to the mongod or mongos process 46 | -z = Name (hostname) of MongoDB instance or cluster in the Zabbix UI 47 | -u = User name for database authentication 48 | -x = Password for database authentication 49 | -H = Zabbix server IP or hostname 50 | -P = Zabbix server Port or hostname 51 | --ssl = Use SSL when connecting to MongoDB 52 | " ; 53 | 54 | exit ; 55 | } 56 | 57 | //-------------------------------------------------------------------------// 58 | // Setup log file, data file and zabbix hostname. 59 | //-------------------------------------------------------------------------// 60 | $zabbix_name = $options['z'] ; 61 | 62 | // Remove spaces from zabbix name for file data and log file creation 63 | $file_base_name = str_replace(' ', '_', $zabbix_name); 64 | 65 | $zabbix_server = ($options['H'] ? $options['H'] : '127.0.0.1'); 66 | $zabbix_server_port = ($options['P'] ? $options['P'] : '10051'); 67 | 68 | $debug_mode = isset($options['D']) ; 69 | 70 | $ssl = isset($options['ssl']) ; 71 | 72 | if ($ssl && !MONGO_SUPPORTS_SSL) { 73 | echo "WARNING: --ssl option is specified, but we will not use it, because the PHP Mongo extension does not support SSL!\n" ; 74 | $ssl = false ; 75 | } 76 | 77 | $data_lines = array() ; 78 | 79 | $md5_checksum_string = md5_file($argv[0]) ; 80 | 81 | if ($debug_mode) { 82 | write_to_log("version $command_version") ; 83 | } 84 | //-------------------------------------------------------------------------// 85 | 86 | //-------------------------------------------------------------------------// 87 | function write_to_log($output_line) 88 | //-------------------------------------------------------------------------// 89 | { 90 | global $command_name ; 91 | fprintf(STDERR, "%s: %s\n", $command_name, $output_line) ; 92 | } 93 | //-------------------------------------------------------------------------// 94 | 95 | 96 | 97 | //-------------------------------------------------------------------------// 98 | function write_to_data_lines($zabbix_name, $key, $value) 99 | //-------------------------------------------------------------------------// 100 | { 101 | global $data_lines ; 102 | 103 | // Only if we have a value do we want to record this metric 104 | if(isset($value) && $value !== '') 105 | { 106 | $data_line = sprintf("\"%s\" \"mongodb.%s\" \"%s\"", $zabbix_name, $key, $value) ; 107 | $data_lines[] = $data_line ; 108 | } 109 | } 110 | //-------------------------------------------------------------------------// 111 | 112 | 113 | //-------------------------------------------------------------------------// 114 | // Now starts the heart of mongoDB monitoring !! 115 | //-------------------------------------------------------------------------// 116 | 117 | //----------------------------- 118 | // Setup connection to mongoDB 119 | //----------------------------- 120 | $mongodb_host = empty($options['h']) ? Mongo::DEFAULT_HOST : $options['h'] ; 121 | $mongodb_port = empty($options['p']) ? Mongo::DEFAULT_PORT : $options['p'] ; 122 | 123 | if ((!empty($options['u'])) && (!empty($options['x']))) { 124 | $connect_string = $options['u'] . ':' . $options['x'] . '@' . $mongodb_host . ':' . $mongodb_port ; 125 | } 126 | else { 127 | $connect_string = $mongodb_host . ':' . $mongodb_port ; 128 | } 129 | 130 | if ($ssl) { 131 | $connect_string .= "/?ssl=true" ; 132 | } 133 | 134 | $mongo_connection = new Mongo("mongodb://$connect_string") ; 135 | 136 | if (is_null($mongo_connection)) { 137 | write_to_log("Error in connection to mongoDB using connect string $connect_string") ; 138 | exit ; 139 | } 140 | else { 141 | write_to_log("Successfully connected to mongoDB using connect string $connect_string") ; 142 | } 143 | 144 | 145 | //----------------------------- 146 | // Get server statistics 147 | //----------------------------- 148 | $mongo_db_handle = $mongo_connection->selectDB("config") ; 149 | 150 | $server_status = $mongo_db_handle->command(array('serverStatus'=>1)) ; 151 | 152 | if (!isset($server_status['ok'])) { 153 | write_to_log("Error in executing $command.") ; 154 | exit ; 155 | } 156 | 157 | $mongo_version = $server_status['version'] ; 158 | write_to_data_lines($zabbix_name, "version", $mongo_version) ; 159 | 160 | $uptime = $server_status['uptime'] ; 161 | write_to_data_lines($zabbix_name, "uptime", $uptime) ; 162 | 163 | if ($server_status['globalLock']['lockTime'] != null) { 164 | $globalLock_lockTime = $server_status['globalLock']['lockTime'] ; 165 | write_to_data_lines($zabbix_name, "globalLock.lockTime", $globalLock_lockTime) ; 166 | } 167 | 168 | if ($server_status['globalLock']['totalTime'] != null) { 169 | $globalLock_totalTime = $server_status['globalLock']['totalTime'] ; 170 | write_to_data_lines($zabbix_name, "globalLock.totalTime", $globalLock_totalTime) ; 171 | } 172 | 173 | $globalLock_currentQueue_total = $server_status['globalLock']['currentQueue']['total'] ; 174 | write_to_data_lines($zabbix_name, "globalLock.currentQueue.total", $globalLock_currentQueue_total) ; 175 | 176 | $globalLock_currentQueue_readers = $server_status['globalLock']['currentQueue']['readers'] ; 177 | write_to_data_lines($zabbix_name, "globalLock.currentQueue.readers", $globalLock_currentQueue_readers) ; 178 | 179 | $globalLock_currentQueue_writers = $server_status['globalLock']['currentQueue']['writers'] ; 180 | write_to_data_lines($zabbix_name, "globalLock.currentQueue.writers", $globalLock_currentQueue_writers) ; 181 | 182 | $mem_bits = $server_status['mem']['bits'] ; 183 | write_to_data_lines($zabbix_name, "mem.bits", $mem_bits) ; 184 | 185 | $mem_resident = $server_status['mem']['resident'] ; 186 | write_to_data_lines($zabbix_name, "mem.resident", $mem_resident) ; 187 | 188 | $mem_virtual = $server_status['mem']['virtual'] ; 189 | write_to_data_lines($zabbix_name, "mem.virtual", $mem_virtual) ; 190 | 191 | $connections_current = $server_status['connections']['current'] ; 192 | write_to_data_lines($zabbix_name, "connections.current", $connections_current) ; 193 | 194 | $connections_available = $server_status['connections']['available'] ; 195 | write_to_data_lines($zabbix_name, "connections.available", $connections_available) ; 196 | 197 | $extra_info_heap_usage = round(($server_status['extra_info']['heap_usage_bytes'])/(1024*124), 2) ; 198 | write_to_data_lines($zabbix_name, "extra_info.heap_usage", $extra_info_heap_usage) ; 199 | 200 | $extra_info_page_faults = $server_status['extra_info']['page_faults']; 201 | write_to_data_lines($zabbix_name, "extra_info.page_faults", $extra_info_page_faults) ; 202 | 203 | if ($server_status['indexCounters']['btree']['accesses'] != null) { 204 | $indexCounters_btree_accesses = $server_status['indexCounters']['btree']['accesses'] ; 205 | } else { 206 | $indexCounters_btree_accesses = $server_status['indexCounters']['accesses'] ; 207 | } 208 | write_to_data_lines($zabbix_name, "indexCounters.btree.accesses", $indexCounters_btree_accesses) ; 209 | 210 | if ($server_status['indexCounters']['btree']['hits'] != null) { 211 | $indexCounters_btree_hits = $server_status['indexCounters']['btree']['hits'] ; 212 | } else { 213 | $indexCounters_btree_hits = $server_status['indexCounters']['hits'] ; 214 | } 215 | write_to_data_lines($zabbix_name, "indexCounters.btree.hits", $indexCounters_btree_hits) ; 216 | 217 | if ($server_status['indexCounters']['btree']['misses'] != null) { 218 | $indexCounters_btree_misses = $server_status['indexCounters']['btree']['misses'] ; 219 | } else { 220 | $indexCounters_btree_misses = $server_status['indexCounters']['misses'] ; 221 | } 222 | write_to_data_lines($zabbix_name, "indexCounters.btree.misses", $indexCounters_btree_misses) ; 223 | 224 | if ($server_status['indexCounters']['btree']['resets'] != null) { 225 | $indexCounters_btree_resets = $server_status['indexCounters']['btree']['resets'] ; 226 | } else { 227 | $indexCounters_btree_resets = $server_status['indexCounters']['resets'] ; 228 | } 229 | write_to_data_lines($zabbix_name, "indexCounters.btree.resets", $indexCounters_btree_resets) ; 230 | 231 | if ($server_status['indexCounters']['btree']['missRatio'] != null) { 232 | $indexCounters_btree_missRatio = $server_status['indexCounters']['btree']['missRatio'] ; 233 | } else { 234 | $indexCounters_btree_missRatio = $server_status['indexCounters']['missRatio'] ; 235 | } 236 | write_to_data_lines($zabbix_name, "indexCounters.btree.missRatio", $indexCounters_btree_missRatio) ; 237 | 238 | $backgroundFlushing_flushes = $server_status['backgroundFlushing']['flushes'] ; 239 | write_to_data_lines($zabbix_name, "backgroundFlushing.flushes", $backgroundFlushing_flushes) ; 240 | 241 | $backgroundFlushing_total_ms = $server_status['backgroundFlushing']['total_ms'] ; 242 | write_to_data_lines($zabbix_name, "backgroundFlushing.total_ms", $backgroundFlushing_total_ms) ; 243 | 244 | $backgroundFlushing_average_ms = $server_status['backgroundFlushing']['average_ms'] ; 245 | write_to_data_lines($zabbix_name, "backgroundFlushing.average_ms", $backgroundFlushing_average_ms) ; 246 | 247 | $backgroundFlushing_last_ms = $server_status['backgroundFlushing']['last_ms'] ; 248 | write_to_data_lines($zabbix_name, "backgroundFlushing.last_ms", $backgroundFlushing_last_ms) ; 249 | 250 | $cursors_totalOpen = $server_status['cursors']['totalOpen'] ; 251 | write_to_data_lines($zabbix_name, "cursors.totalOpen", $cursors_totalOpen) ; 252 | 253 | $cursors_clientCursors_size = $server_status['cursors']['clientCursors_size'] ; 254 | write_to_data_lines($zabbix_name, "cursors.clientCursors_size", $cursors_clientCursors_size) ; 255 | 256 | $cursors_timedOut = $server_status['cursors']['timedOut'] ; 257 | write_to_data_lines($zabbix_name, "cursors.timedOut", $cursors_timedOut) ; 258 | 259 | $opcounters_insert = $server_status['opcounters']['insert'] ; 260 | write_to_data_lines($zabbix_name, "opcounters.insert", $opcounters_insert) ; 261 | 262 | $opcounters_query = $server_status['opcounters']['query'] ; 263 | write_to_data_lines($zabbix_name, "opcounters.query", $opcounters_query) ; 264 | 265 | $opcounters_update = $server_status['opcounters']['update'] ; 266 | write_to_data_lines($zabbix_name, "opcounters.update", $opcounters_update) ; 267 | 268 | $opcounters_delete = $server_status['opcounters']['delete'] ; 269 | write_to_data_lines($zabbix_name, "opcounters.delete", $opcounters_delete) ; 270 | 271 | $opcounters_getmore = $server_status['opcounters']['getmore'] ; 272 | write_to_data_lines($zabbix_name, "opcounters.getmore", $opcounters_getmore) ; 273 | 274 | $opcounters_command = $server_status['opcounters']['command'] ; 275 | write_to_data_lines($zabbix_name, "opcounters.command", $opcounters_command) ; 276 | 277 | $asserts_regular = $server_status['asserts']['regular'] ; 278 | write_to_data_lines($zabbix_name, "asserts.regular", $asserts_regular) ; 279 | 280 | $asserts_warning = $server_status['asserts']['warning'] ; 281 | write_to_data_lines($zabbix_name, "asserts.warning", $asserts_warning) ; 282 | 283 | $asserts_msg = $server_status['asserts']['msg'] ; 284 | write_to_data_lines($zabbix_name, "asserts.msg", $asserts_msg) ; 285 | 286 | $asserts_user = $server_status['asserts']['user'] ; 287 | write_to_data_lines($zabbix_name, "asserts.user", $asserts_user) ; 288 | 289 | $asserts_rollovers = $server_status['asserts']['rollovers'] ; 290 | write_to_data_lines($zabbix_name, "asserts.rollovers", $asserts_rollovers) ; 291 | 292 | $network_inbound_traffic_mb = ($server_status['network']['bytesIn'])/(1024*1024) ; 293 | write_to_data_lines($zabbix_name, "network.inbound.traffic_mb", $network_inbound_traffic_mb) ; 294 | 295 | $network_outbound_traffic_mb = ($server_status['network']['bytesOut'])/(1024*1024) ; 296 | write_to_data_lines($zabbix_name, "network.outbound.traffic_mb", $network_outbound_traffic_mb) ; 297 | 298 | $network_requests = $server_status['network']['numRequests'] ; 299 | write_to_data_lines($zabbix_name, "network.requests", $network_requests) ; 300 | 301 | $write_backs_queued = $server_status['writeBacksQueued'] ; 302 | if ($write_backs_queued) { 303 | write_to_data_lines($zabbix_name, "write_backs_queued", "Yes") ; 304 | } else { 305 | write_to_data_lines($zabbix_name, "write_backs_queued", "No") ; 306 | } 307 | 308 | $logging_commits = $server_status['dur']['commits'] ; 309 | write_to_data_lines($zabbix_name, "logging.commits", $logging_commits) ; 310 | 311 | $logging_journal_writes_mb = $server_status['dur']['journaledMB'] ; 312 | write_to_data_lines($zabbix_name, "logging.journal_writes_mb", $logging_journal_writes_mb) ; 313 | 314 | $logging_datafile_writes_mb = $server_status['dur']['writeToDataFilesMB'] ; 315 | write_to_data_lines($zabbix_name, "logging.datafile_writes_mb", $logging_datafile_writes_mb) ; 316 | 317 | $logging_commits_in_writelock = $server_status['dur']['commitsInWriteLock'] ; 318 | write_to_data_lines($zabbix_name, "logging.commits_in_writelock", $logging_commits_in_writelock) ; 319 | 320 | $logging_early_commits = $server_status['dur']['earlyCommits'] ; 321 | write_to_data_lines($zabbix_name, "logging.early_commits", $logging_early_commits) ; 322 | 323 | $logging_log_buffer_prep_time_ms = $server_status['dur']['timeMs']['prepLogBuffer'] ; 324 | write_to_data_lines($zabbix_name, "logging.log_buffer_prep_time_ms", $logging_log_buffer_prep_time_ms) ; 325 | 326 | $logging_journal_write_time_ms = $server_status['dur']['timeMs']['writeToJournal'] ; 327 | write_to_data_lines($zabbix_name, "logging.journal_write_time_ms", $logging_journal_write_time_ms) ; 328 | 329 | $logging_datafile_write_time_ms = $server_status['dur']['timeMs']['writeToDataFiles'] ; 330 | write_to_data_lines($zabbix_name, "logging.datafile_write_time_ms", $logging_datafile_write_time_ms) ; 331 | 332 | //----------------------------- 333 | // Get DB list and cumulative DB info 334 | //----------------------------- 335 | $db_list = $mongo_connection->listDBs() ; 336 | 337 | $db_count = count($db_list) ; 338 | write_to_data_lines($zabbix_name, "db.count", $db_count) ; 339 | 340 | $totalSize = round(($db_list['totalSize'])/(1024*1024), 2) ; 341 | write_to_data_lines($zabbix_name, "total.size", $totalSize) ; 342 | 343 | $sharded_db_count = 0 ; 344 | $total_collection_count = 0 ; 345 | $total_object_count = 0 ; 346 | $total_index_count = 0 ; 347 | $total_index_size = 0.0 ; 348 | 349 | $is_sharded = 'No' ; 350 | 351 | $db_info_array = array() ; 352 | $db_info_collections = array() ; 353 | $db_info_objects = array() ; 354 | $db_info_indexes = array() ; 355 | $db_info_avgObjSize = array() ; 356 | $db_info_dataSize = array() ; 357 | $db_info_indexSize = array() ; 358 | $db_info_storageSize = array() ; 359 | $db_info_numExtents_array = array() ; 360 | $db_info_fileSize = array() ; 361 | 362 | 363 | foreach($db_list['databases'] as $db) { 364 | if(isset($db['shards'])) { 365 | $is_sharded = 'Yes' ; 366 | } 367 | else { 368 | // Do nothing ! 369 | } 370 | 371 | $mongo_db_handle = $mongo_connection->selectDB($db['name']) ; 372 | $db_stats = $mongo_db_handle->command(array('dbStats'=>1)) ; 373 | 374 | $execute_status = $db_stats['ok'] ; 375 | 376 | if ($execute_status == 0) { 377 | write_to_log("Error in executing $command for database ".$db['name']) ; 378 | exit ; 379 | } 380 | 381 | $total_collection_count += $db_stats['collections'] ; 382 | $total_object_count += $db_stats['objects'] ; 383 | $total_index_count += $db_stats['indexes'] ; 384 | $total_index_size += $db_stats['indexSize'] ; 385 | 386 | $db_info_array[] = array("{#DBNAME}" => $db['name']) ; 387 | $db_info_collections[$db['name']] = $db_stats['collections'] ; 388 | $db_info_objects[$db['name']] = $db_stats['objects'] ; 389 | $db_info_indexes[$db['name']] = $db_stats['indexes'] ; 390 | $db_info_avgObjSize[$db['name']] = $db_stats['avgObjSize'] ; 391 | $db_info_dataSize[$db['name']] = $db_stats['dataSize'] ; 392 | $db_info_indexSize[$db['name']] = $db_stats['indexSize'] ; 393 | $db_info_storageSize[$db['name']] = $db_stats['storageSize'] ; 394 | $db_info_numExtents_array[$db['name']] = $db_stats['numExtents'] ; 395 | $db_info_fileSize[$db['name']] = $db_stats['fileSize'] ; 396 | } 397 | 398 | write_to_data_lines($zabbix_name, "db.discovery", str_replace("\"", "\\\"", json_encode(array("data" => $db_info_array)))) ; 399 | 400 | write_to_data_lines($zabbix_name, "is_sharded", $is_sharded) ; 401 | 402 | write_to_data_lines($zabbix_name, "total.collection.count", $total_collection_count) ; 403 | 404 | write_to_data_lines($zabbix_name, "total.object.count", $total_object_count) ; 405 | 406 | write_to_data_lines($zabbix_name, "total.index.count", $total_index_count) ; 407 | 408 | $total_index_size = round($total_index_size/(1024*1024), 2) ; 409 | write_to_data_lines($zabbix_name, "total.index.size", $total_index_size) ; 410 | 411 | foreach($db_info_collections as $name => $dummy) { 412 | write_to_data_lines($zabbix_name, "db.collections[" . $name . "]", $db_info_collections[$name]) ; 413 | write_to_data_lines($zabbix_name, "db.objects[" . $name . "]", $db_info_objects[$name]) ; 414 | write_to_data_lines($zabbix_name, "db.indexes[" . $name . "]", $db_info_indexes[$name]) ; 415 | write_to_data_lines($zabbix_name, "db.avgObjSize[" . $name . "]", $db_info_avgObjSize[$name]) ; 416 | write_to_data_lines($zabbix_name, "db.dataSize[" . $name . "]", $db_info_dataSize[$name]) ; 417 | write_to_data_lines($zabbix_name, "db.indexSize[" . $name . "]", $db_info_indexSize[$name]) ; 418 | write_to_data_lines($zabbix_name, "db.storageSize[" . $name . "]", $db_info_storageSize[$name]) ; 419 | write_to_data_lines($zabbix_name, "db.numExtents[" . $name . "]", $db_info_numExtents_array[$name]) ; 420 | write_to_data_lines($zabbix_name, "db.fileSize[" . $name . "]", $db_info_fileSize[$name]) ; 421 | } 422 | 423 | 424 | //----------------------------- 425 | // Check for replication / replicaSets 426 | //----------------------------- 427 | if ($is_sharded == 'No') { 428 | $mongo_db_handle = $mongo_connection->selectDB('admin') ; 429 | $rs_status = $mongo_db_handle->command(array('replSetGetStatus'=>1)) ; 430 | 431 | if (!($rs_status['ok'])) { 432 | write_to_data_lines($zabbix_name, "is_replica_set", "No") ; 433 | } 434 | else { 435 | write_to_data_lines($zabbix_name, "is_replica_set", "Yes") ; 436 | write_to_data_lines($zabbix_name, "replica_set_name", $rs_status['set']) ; 437 | write_to_data_lines($zabbix_name, "replica_set_member_count", count($rs_status['members']) ) ; 438 | 439 | $repl_set_member_names = '' ; 440 | foreach ($rs_status['members'] as $repl_set_member) { 441 | $repl_set_member_names .= 'host#' . $repl_set_member['_id'] . ' = ' . $repl_set_member['name'] . ' || ' ; 442 | } 443 | write_to_data_lines($zabbix_name, "replica_set_hosts", $repl_set_member_names) ; 444 | 445 | $local_mongo_db_handle = $mongo_connection->selectDB('local') ; 446 | $col_name = 'oplog.rs' ; 447 | $mongo_collection = $local_mongo_db_handle->$col_name ; 448 | $oplog_rs_count = $mongo_collection->count() ; 449 | write_to_data_lines($zabbix_name, "oplog.rs_count", $oplog_rs_count) ; 450 | 451 | //$rs_status = $mongo_db_handle->execute("$command") ; 452 | $repl_member_attention_state_count = 0 ; 453 | $repl_member_attenntion_state_info = '' ; 454 | 455 | foreach($rs_status['members'] as $member) { 456 | $member_state = $member['state'] ; 457 | 458 | $host = explode(':', $member['name']); 459 | $hostname = $host[0]; 460 | 461 | if ($member_state == 1) { 462 | $master_optime = $member['optime']; 463 | } 464 | 465 | $fqdn = explode('.', $mongodb_host); 466 | $mongodb_host_simple = $fqdn[0]; 467 | 468 | if (!in_array($hostname, array($mongodb_host_simple, $mongodb_host))) { 469 | continue; 470 | } 471 | 472 | $mongo_host_optime = $member['optime']; 473 | $seconds = $master_optime->sec - $mongo_host_optime->sec; 474 | 475 | if ($seconds < 0) { 476 | $seconds = 0; 477 | } 478 | 479 | write_to_data_lines($zabbix_name, "repl_member_replication_lag_sec", $seconds) ; 480 | 481 | if($member_state == 0 or $member_state == 3 or $member_state == 4 or $member_state == 5 or $member_state == 6 or $member_state == 8) { 482 | // 0 = Starting up, phase 1 483 | // 1 = primary 484 | // 2 = secondary 485 | // 3 = recovering 486 | // 4 = fatal error 487 | // 5 = starting up, phase 2 488 | // 6 = unknown state 489 | // 7 = arbiter 490 | echo "aaa\n" ; 491 | // 8 = down 492 | $repl_member_attention_state_count++ ; 493 | switch ($member_state) { 494 | case 0: $member_state = 'starting up, phase 1' ; 495 | break ; 496 | case 3: $member_state = 'recovering' ; 497 | break ; 498 | case 4: $member_state = 'fatal error' ; 499 | break ; 500 | case 5: $member_state = 'starting up, phase 2' ; 501 | break ; 502 | case 6: $member_state = 'unknown' ; 503 | break ; 504 | case 8: $member_state = 'down' ; 505 | break ; 506 | default: $member_state = 'unknown' ; 507 | break ; 508 | } 509 | $repl_member_attention_state_info .= $member['name'] . ' is in state ' . $member_state . ' ||' ; 510 | } 511 | } 512 | write_to_data_lines($zabbix_name, "repl_member_attention_state_count", $repl_member_attention_state_count) ; 513 | write_to_data_lines($zabbix_name, "repl_member_attention_state_info", ($repl_member_attention_state_count > 0 ? $repl_member_attention_state_info : 'empty') ) ; 514 | } 515 | 516 | } 517 | 518 | //----------------------------- 519 | // Check for sharding 520 | //----------------------------- 521 | if ($is_sharded == 'Yes') { 522 | $mongo_db_handle = $mongo_connection->selectDB('config') ; 523 | 524 | $mongo_collection = $mongo_db_handle->chunks ; 525 | $shard_info = $mongo_collection->count() ; 526 | write_to_data_lines($zabbix_name, "shard_chunk_count", $shard_info) ; 527 | 528 | $mongo_collection = $mongo_db_handle->collections ; 529 | $shard_info = $mongo_collection->count() ; 530 | write_to_data_lines($zabbix_name, "sharded_collections_count", $shard_info) ; 531 | 532 | $collection = $mongo_connection->selectDB('config')->selectCollection('collections') ; 533 | $cursor = $collection->find() ; 534 | $collection_array = iterator_to_array($cursor) ; 535 | $collection_info = '' ; 536 | foreach ($collection_array as $shard) { 537 | $collection_info .= $shard['_id'] . ' || ' ; 538 | } 539 | write_to_data_lines($zabbix_name, "sharded_collection_info", $collection_info) ; 540 | 541 | 542 | $command = "db.shards.count" ; 543 | $mongo_collection = $mongo_db_handle->shards ; 544 | $shard_info = $mongo_collection->count() ; 545 | write_to_data_lines($zabbix_name, "shard_count", $shard_info) ; 546 | 547 | $collection = $mongo_connection->selectDB('config')->selectCollection('shards') ; 548 | $cursor = $collection->find() ; 549 | $shards_array = iterator_to_array($cursor) ; 550 | $shard_info = '' ; 551 | foreach ($shards_array as $shard) { 552 | $shard_info .= $shard['_id'] . ' = ' . $shard['host'] . ' || ' ; 553 | } 554 | write_to_data_lines($zabbix_name, "shard_info", $shard_info) ; 555 | 556 | $collection = $mongo_connection->selectDB('config')->selectCollection('databases') ; 557 | $cursor = $collection->find() ; 558 | $db_array = iterator_to_array($cursor) ; 559 | $db_info = '' ; 560 | foreach ($db_array as $db) { 561 | if( $db['partitioned'] ) { 562 | $partitioned = 'yes' ; 563 | } 564 | else { 565 | $partitioned = 'no' ; 566 | } 567 | $db_info .= $db['_id'] . ' : ' . 'partitioned = ' . $partitioned . ', primary = ' . $db['primary'] . ' || ' ; 568 | } 569 | write_to_data_lines($zabbix_name, "db_info", $db_info) ; 570 | 571 | 572 | } 573 | 574 | //-------------------------------------------------------------------------// 575 | 576 | 577 | // Get data collection end time (we will use this to compute the total data collection time) 578 | $end_time = time() ; 579 | $data_collection_time = $end_time - $start_time ; 580 | write_to_data_lines($zabbix_name, "plugin.data_collection_time", $data_collection_time) ; 581 | 582 | write_to_data_lines($zabbix_name, "plugin.version", $command_version) ; 583 | write_to_data_lines($zabbix_name, "plugin.checksum", $md5_checksum_string) ; 584 | 585 | // For DEBUG 586 | if ($debug_mode) { 587 | $data_file_name = "/tmp/${command_name}_${file_base_name}.data" ; 588 | file_put_contents($data_file_name, implode("\n", $data_lines) . "\n") ; 589 | } 590 | 591 | $descriptorspec = array( 592 | 0 => array("pipe", "r"), // stdin 593 | 1 => array("pipe", "w"), // stdout 594 | 2 => array("pipe", "w") // stderr 595 | ) ; 596 | $process = proc_open("zabbix_sender -vv -z $zabbix_server -p $zabbix_server_port -i - 2>&1", $descriptorspec, $pipes) ; 597 | 598 | if (is_resource($process)) { 599 | fwrite($pipes[0], implode("\n", $data_lines)) ; 600 | fclose($pipes[0]) ; 601 | 602 | while($s = fgets($pipes[1], 1024)) { 603 | write_to_log("O: " . trim($s)) ; 604 | } 605 | fclose($pipes[1]); 606 | 607 | while($s= fgets($pipes[2], 1024)) { 608 | write_to_log("E: " . trim($s)) ; 609 | } 610 | fclose($pipes[2]) ; 611 | } 612 | 613 | exit ; 614 | 615 | ?> 616 | -------------------------------------------------------------------------------- /mongodb-2.4/mikoomi-mongodb-plugin-24.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=$PATH:/etc/zabbix/externalscripts:/opt/zabbix/externalscripts:/opt/zabbix/bin:/home/zabbix/bin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin 3 | export PATH 4 | BASE_DIR="`dirname $0`" 5 | /usr/bin/php $BASE_DIR/mikoomi-mongodb-plugin-24.php $* 6 | echo 0 7 | -------------------------------------------------------------------------------- /mongodb-3.2/mikoomi-mongodb-plugin-32.php: -------------------------------------------------------------------------------- 1 | ] [-p ] [--ssl] [-u ] [-x ] [-H ] [-P ] -z 45 | where 46 | -D = Run in detail/debug mode 47 | -h = Hostname or IP address of server running MongoDB 48 | -p = Port number on which to connect to the mongod or mongos process 49 | -z = Name (hostname) of MongoDB instance or cluster in the Zabbix UI 50 | -u = User name for database authentication 51 | -x = Password for database authentication 52 | -H = Zabbix server IP or hostname 53 | -P = Zabbix server Port or hostname 54 | --ssl = Use SSL when connecting to MongoDB 55 | " ; 56 | 57 | exit ; 58 | } 59 | 60 | //-------------------------------------------------------------------------// 61 | // Setup log file, data file and zabbix hostname. 62 | //-------------------------------------------------------------------------// 63 | $zabbix_name = $options['z'] ; 64 | 65 | // Remove spaces from zabbix name for file data and log file creation 66 | $file_base_name = str_replace(' ', '_', $zabbix_name); 67 | 68 | $zabbix_server = ($options['H'] ? $options['H'] : '127.0.0.1'); 69 | $zabbix_server_port = ($options['P'] ? $options['P'] : '10051'); 70 | 71 | $debug_mode = isset($options['D']) ; 72 | 73 | $ssl = isset($options['ssl']) ; 74 | 75 | if ($ssl && !MONGO_SUPPORTS_SSL) { 76 | echo "WARNING: --ssl option is specified, but we will not use it, because the PHP Mongo extension does not support SSL!\n" ; 77 | $ssl = false ; 78 | } 79 | 80 | $data_lines = array() ; 81 | 82 | $md5_checksum_string = md5_file($argv[0]) ; 83 | 84 | if ($debug_mode) { 85 | write_to_log("version $command_version") ; 86 | } 87 | //-------------------------------------------------------------------------// 88 | 89 | //-------------------------------------------------------------------------// 90 | function write_to_log($output_line) 91 | //-------------------------------------------------------------------------// 92 | { 93 | global $command_name ; 94 | fprintf(STDERR, "%s: %s\n", $command_name, $output_line) ; 95 | } 96 | //-------------------------------------------------------------------------// 97 | 98 | 99 | 100 | //-------------------------------------------------------------------------// 101 | function write_to_data_lines($zabbix_name, $key, $value) 102 | //-------------------------------------------------------------------------// 103 | { 104 | global $data_lines ; 105 | 106 | // Only if we have a value do we want to record this metric 107 | if(isset($value) && $value !== '') 108 | { 109 | $data_line = sprintf("\"%s\" \"mongodb.%s\" \"%s\"", $zabbix_name, $key, $value) ; 110 | $data_lines[] = $data_line ; 111 | } 112 | } 113 | //-------------------------------------------------------------------------// 114 | 115 | 116 | //-------------------------------------------------------------------------// 117 | // Now starts the heart of mongoDB monitoring !! 118 | //-------------------------------------------------------------------------// 119 | 120 | //----------------------------- 121 | // Setup connection to mongoDB 122 | //----------------------------- 123 | //print ("Here in mikoomi mongo plugin ... before connecting mongo"); 124 | 125 | $mongodb_host = empty($options['h']) ? Mongo::DEFAULT_HOST : $options['h'] ; 126 | $mongodb_port = empty($options['p']) ? Mongo::DEFAULT_PORT : $options['p'] ; 127 | 128 | if ((!empty($options['u'])) && (!empty($options['x']))) { 129 | $connect_string = $options['u'] . ':' . $options['x'] . '@' . $mongodb_host . ':' . $mongodb_port ; 130 | } 131 | else { 132 | $connect_string = $mongodb_host . ':' . $mongodb_port ; 133 | } 134 | 135 | if ($ssl) { 136 | $connect_string .= "/?ssl=true" ; 137 | } 138 | //print ("Mongo connect string - " . $connect_string); 139 | #$mongo_connection = new Mongo("mongodb://$connect_string") ; 140 | $mongo_connection = new MongoClient("mongodb://$connect_string") ; 141 | 142 | if (is_null($mongo_connection)) { 143 | write_to_log("Error in connection to mongoDB using connect string $connect_string") ; 144 | exit ; 145 | } 146 | else { 147 | write_to_log("Successfully connected to mongoDB using connect string $connect_string") ; 148 | } 149 | 150 | 151 | //----------------------------- 152 | // Get server statistics 153 | //----------------------------- 154 | $mongo_db_handle = $mongo_connection->selectDB("admin") ; 155 | 156 | $server_status = $mongo_db_handle->command(array('serverStatus'=>1)) ; 157 | 158 | if (!isset($server_status['ok'])) { 159 | write_to_log("Error in executing $command.") ; 160 | exit ; 161 | } 162 | 163 | //print ("************ "); 164 | //print_r( $server_status ) ; 165 | 166 | $mongo_version = $server_status['version'] ; 167 | write_to_data_lines($zabbix_name, "version", $mongo_version) ; 168 | 169 | $uptime = $server_status['uptime'] ; 170 | write_to_data_lines($zabbix_name, "uptime", $uptime) ; 171 | 172 | /* 173 | if ($server_status['globalLock']['totalTime'] != null) { 174 | $globalLock_lockTime = $server_status['globalLock']['totalTime'] ; 175 | write_to_data_lines($zabbix_name, "globalLock.totalTime", $globalLock_totalTime) ; 176 | } 177 | */ 178 | 179 | if ($server_status['globalLock']['totalTime'] != null) { 180 | $globalLock_totalTime = $server_status['globalLock']['totalTime'] ; 181 | write_to_data_lines($zabbix_name, "globalLock.totalTime", $globalLock_totalTime) ; 182 | } 183 | 184 | $globalLock_currentQueue_total = $server_status['globalLock']['currentQueue']['total'] ; 185 | write_to_data_lines($zabbix_name, "globalLock.currentQueue.total", $globalLock_currentQueue_total) ; 186 | 187 | $globalLock_currentQueue_readers = $server_status['globalLock']['currentQueue']['readers'] ; 188 | write_to_data_lines($zabbix_name, "globalLock.currentQueue.readers", $globalLock_currentQueue_readers) ; 189 | 190 | $globalLock_currentQueue_writers = $server_status['globalLock']['currentQueue']['writers'] ; 191 | write_to_data_lines($zabbix_name, "globalLock.currentQueue.writers", $globalLock_currentQueue_writers) ; 192 | 193 | $mem_bits = $server_status['mem']['bits'] ; 194 | write_to_data_lines($zabbix_name, "mem.bits", $mem_bits) ; 195 | 196 | $mem_resident = $server_status['mem']['resident'] ; 197 | write_to_data_lines($zabbix_name, "mem.resident", $mem_resident) ; 198 | 199 | $mem_virtual = $server_status['mem']['virtual'] ; 200 | write_to_data_lines($zabbix_name, "mem.virtual", $mem_virtual) ; 201 | 202 | $connections_current = $server_status['connections']['current'] ; 203 | write_to_data_lines($zabbix_name, "connections.current", $connections_current) ; 204 | 205 | $connections_available = $server_status['connections']['available'] ; 206 | write_to_data_lines($zabbix_name, "connections.available", $connections_available) ; 207 | 208 | $extra_info_heap_usage = round(($server_status['extra_info']['heap_usage_bytes'])/(1024*124), 2) ; 209 | write_to_data_lines($zabbix_name, "extra_info.heap_usage", $extra_info_heap_usage) ; 210 | 211 | $extra_info_page_faults = $server_status['extra_info']['page_faults']; 212 | write_to_data_lines($zabbix_name, "extra_info.page_faults", $extra_info_page_faults) ; 213 | 214 | /*if ($server_status['indexCounters']['btree']['accesses'] != null) { 215 | $indexCounters_btree_accesses = $server_status['indexCounters']['btree']['accesses'] ; 216 | } else { 217 | $indexCounters_btree_accesses = $server_status['indexCounters']['accesses'] ; 218 | } 219 | write_to_data_lines($zabbix_name, "indexCounters.btree.accesses", $indexCounters_btree_accesses) ; 220 | 221 | if ($server_status['indexCounters']['btree']['hits'] != null) { 222 | $indexCounters_btree_hits = $server_status['indexCounters']['btree']['hits'] ; 223 | } else { 224 | $indexCounters_btree_hits = $server_status['indexCounters']['hits'] ; 225 | } 226 | write_to_data_lines($zabbix_name, "indexCounters.btree.hits", $indexCounters_btree_hits) ; 227 | 228 | if ($server_status['indexCounters']['btree']['misses'] != null) { 229 | $indexCounters_btree_misses = $server_status['indexCounters']['btree']['misses'] ; 230 | } else { 231 | $indexCounters_btree_misses = $server_status['indexCounters']['misses'] ; 232 | } 233 | write_to_data_lines($zabbix_name, "indexCounters.btree.misses", $indexCounters_btree_misses) ; 234 | 235 | if ($server_status['indexCounters']['btree']['resets'] != null) { 236 | $indexCounters_btree_resets = $server_status['indexCounters']['btree']['resets'] ; 237 | } else { 238 | $indexCounters_btree_resets = $server_status['indexCounters']['resets'] ; 239 | } 240 | write_to_data_lines($zabbix_name, "indexCounters.btree.resets", $indexCounters_btree_resets) ; 241 | 242 | if ($server_status['indexCounters']['btree']['missRatio'] != null) { 243 | $indexCounters_btree_missRatio = $server_status['indexCounters']['btree']['missRatio'] ; 244 | } else { 245 | $indexCounters_btree_missRatio = $server_status['indexCounters']['missRatio'] ; 246 | } 247 | write_to_data_lines($zabbix_name, "indexCounters.btree.missRatio", $indexCounters_btree_missRatio) ; 248 | */ 249 | 250 | /*$backgroundFlushing_flushes = $server_status['backgroundFlushing']['flushes'] ; 251 | write_to_data_lines($zabbix_name, "backgroundFlushing.flushes", $backgroundFlushing_flushes) ; 252 | 253 | $backgroundFlushing_total_ms = $server_status['backgroundFlushing']['total_ms'] ; 254 | write_to_data_lines($zabbix_name, "backgroundFlushing.total_ms", $backgroundFlushing_total_ms) ; 255 | 256 | $backgroundFlushing_average_ms = $server_status['backgroundFlushing']['average_ms'] ; 257 | write_to_data_lines($zabbix_name, "backgroundFlushing.average_ms", $backgroundFlushing_average_ms) ; 258 | 259 | $backgroundFlushing_last_ms = $server_status['backgroundFlushing']['last_ms'] ; 260 | write_to_data_lines($zabbix_name, "backgroundFlushing.last_ms", $backgroundFlushing_last_ms) ; 261 | */ 262 | /* 263 | $cursors_totalOpen = $server_status['cursors']['totalOpen'] ; 264 | write_to_data_lines($zabbix_name, "cursors.totalOpen", $cursors_totalOpen) ; 265 | 266 | $cursors_clientCursors_size = $server_status['cursors']['clientCursors_size'] ; 267 | write_to_data_lines($zabbix_name, "cursors.clientCursors_size", $cursors_clientCursors_size) ; 268 | 269 | $cursors_timedOut = $server_status['cursors']['timedOut'] ; 270 | write_to_data_lines($zabbix_name, "cursors.timedOut", $cursors_timedOut) ; 271 | */ 272 | $opcounters_insert = $server_status['opcounters']['insert'] ; 273 | write_to_data_lines($zabbix_name, "opcounters.insert", $opcounters_insert) ; 274 | 275 | $opcounters_query = $server_status['opcounters']['query'] ; 276 | write_to_data_lines($zabbix_name, "opcounters.query", $opcounters_query) ; 277 | 278 | $opcounters_update = $server_status['opcounters']['update'] ; 279 | write_to_data_lines($zabbix_name, "opcounters.update", $opcounters_update) ; 280 | 281 | $opcounters_delete = $server_status['opcounters']['delete'] ; 282 | write_to_data_lines($zabbix_name, "opcounters.delete", $opcounters_delete) ; 283 | 284 | $opcounters_getmore = $server_status['opcounters']['getmore'] ; 285 | write_to_data_lines($zabbix_name, "opcounters.getmore", $opcounters_getmore) ; 286 | 287 | $opcounters_command = $server_status['opcounters']['command'] ; 288 | write_to_data_lines($zabbix_name, "opcounters.command", $opcounters_command) ; 289 | 290 | $asserts_regular = $server_status['asserts']['regular'] ; 291 | write_to_data_lines($zabbix_name, "asserts.regular", $asserts_regular) ; 292 | 293 | $asserts_warning = $server_status['asserts']['warning'] ; 294 | write_to_data_lines($zabbix_name, "asserts.warning", $asserts_warning) ; 295 | 296 | $asserts_msg = $server_status['asserts']['msg'] ; 297 | write_to_data_lines($zabbix_name, "asserts.msg", $asserts_msg) ; 298 | 299 | $asserts_user = $server_status['asserts']['user'] ; 300 | write_to_data_lines($zabbix_name, "asserts.user", $asserts_user) ; 301 | 302 | $asserts_rollovers = $server_status['asserts']['rollovers'] ; 303 | write_to_data_lines($zabbix_name, "asserts.rollovers", $asserts_rollovers) ; 304 | 305 | $network_inbound_traffic_mb = ($server_status['network']['bytesIn'])/(1024*1024) ; 306 | write_to_data_lines($zabbix_name, "network.inbound.traffic_mb", $network_inbound_traffic_mb) ; 307 | 308 | $network_outbound_traffic_mb = ($server_status['network']['bytesOut'])/(1024*1024) ; 309 | write_to_data_lines($zabbix_name, "network.outbound.traffic_mb", $network_outbound_traffic_mb) ; 310 | 311 | $network_requests = $server_status['network']['numRequests'] ; 312 | write_to_data_lines($zabbix_name, "network.requests", $network_requests) ; 313 | 314 | $write_backs_queued = $server_status['writeBacksQueued'] ; 315 | if ($write_backs_queued) { 316 | write_to_data_lines($zabbix_name, "write_backs_queued", "Yes") ; 317 | } else { 318 | write_to_data_lines($zabbix_name, "write_backs_queued", "No") ; 319 | } 320 | /* 321 | $logging_commits = $server_status['dur']['commits'] ; 322 | write_to_data_lines($zabbix_name, "logging.commits", $logging_commits) ; 323 | 324 | $logging_journal_writes_mb = $server_status['dur']['journaledMB'] ; 325 | write_to_data_lines($zabbix_name, "logging.journal_writes_mb", $logging_journal_writes_mb) ; 326 | 327 | $logging_datafile_writes_mb = $server_status['dur']['writeToDataFilesMB'] ; 328 | write_to_data_lines($zabbix_name, "logging.datafile_writes_mb", $logging_datafile_writes_mb) ; 329 | 330 | $logging_commits_in_writelock = $server_status['dur']['commitsInWriteLock'] ; 331 | write_to_data_lines($zabbix_name, "logging.commits_in_writelock", $logging_commits_in_writelock) ; 332 | 333 | $logging_early_commits = $server_status['dur']['earlyCommits'] ; 334 | write_to_data_lines($zabbix_name, "logging.early_commits", $logging_early_commits) ; 335 | 336 | $logging_log_buffer_prep_time_ms = $server_status['dur']['timeMs']['prepLogBuffer'] ; 337 | write_to_data_lines($zabbix_name, "logging.log_buffer_prep_time_ms", $logging_log_buffer_prep_time_ms) ; 338 | 339 | $logging_journal_write_time_ms = $server_status['dur']['timeMs']['writeToJournal'] ; 340 | write_to_data_lines($zabbix_name, "logging.journal_write_time_ms", $logging_journal_write_time_ms) ; 341 | 342 | $logging_datafile_write_time_ms = $server_status['dur']['timeMs']['writeToDataFiles'] ; 343 | write_to_data_lines($zabbix_name, "logging.datafile_write_time_ms", $logging_datafile_write_time_ms) ; 344 | */ 345 | //----------------------------- 346 | // Get DB list and cumulative DB info 347 | //----------------------------- 348 | $db_list = $mongo_connection->listDBs() ; 349 | 350 | $db_count = count($db_list) ; 351 | write_to_data_lines($zabbix_name, "db.count", $db_count) ; 352 | 353 | $totalSize = round(($db_list['totalSize'])/(1024*1024), 2) ; 354 | write_to_data_lines($zabbix_name, "total.size", $totalSize) ; 355 | 356 | $sharded_db_count = 0 ; 357 | $total_collection_count = 0 ; 358 | $total_object_count = 0 ; 359 | $total_index_count = 0 ; 360 | $total_index_size = 0.0 ; 361 | 362 | $is_sharded = 'No' ; 363 | 364 | $db_info_array = array() ; 365 | $db_info_collections = array() ; 366 | $db_info_objects = array() ; 367 | $db_info_indexes = array() ; 368 | $db_info_avgObjSize = array() ; 369 | $db_info_dataSize = array() ; 370 | $db_info_indexSize = array() ; 371 | $db_info_storageSize = array() ; 372 | $db_info_numExtents_array = array() ; 373 | $db_info_fileSize = array() ; 374 | 375 | 376 | foreach($db_list['databases'] as $db) { 377 | if(isset($db['shards'])) { 378 | $is_sharded = 'Yes' ; 379 | } 380 | else { 381 | // Do nothing ! 382 | } 383 | 384 | $mongo_db_handle = $mongo_connection->selectDB($db['name']) ; 385 | $db_stats = $mongo_db_handle->command(array('dbStats'=>1)) ; 386 | 387 | $execute_status = $db_stats['ok'] ; 388 | 389 | if ($execute_status == 0) { 390 | write_to_log("Error in executing $command for database ".$db['name']) ; 391 | exit ; 392 | } 393 | 394 | $total_collection_count += $db_stats['collections'] ; 395 | $total_object_count += $db_stats['objects'] ; 396 | $total_index_count += $db_stats['indexes'] ; 397 | $total_index_size += $db_stats['indexSize'] ; 398 | 399 | $db_info_array[] = array("{#DBNAME}" => $db['name']) ; 400 | $db_info_collections[$db['name']] = $db_stats['collections'] ; 401 | $db_info_objects[$db['name']] = $db_stats['objects'] ; 402 | $db_info_indexes[$db['name']] = $db_stats['indexes'] ; 403 | $db_info_avgObjSize[$db['name']] = $db_stats['avgObjSize'] ; 404 | $db_info_dataSize[$db['name']] = $db_stats['dataSize'] ; 405 | $db_info_indexSize[$db['name']] = $db_stats['indexSize'] ; 406 | $db_info_storageSize[$db['name']] = $db_stats['storageSize'] ; 407 | $db_info_numExtents_array[$db['name']] = $db_stats['numExtents'] ; 408 | //$db_info_fileSize[$db['name']] = $db_stats['fileSize'] ; 409 | } 410 | 411 | write_to_data_lines($zabbix_name, "db.discovery", str_replace("\"", "\\\"", json_encode(array("data" => $db_info_array)))) ; 412 | 413 | write_to_data_lines($zabbix_name, "is_sharded", $is_sharded) ; 414 | 415 | write_to_data_lines($zabbix_name, "total.collection.count", $total_collection_count) ; 416 | 417 | write_to_data_lines($zabbix_name, "total.object.count", $total_object_count) ; 418 | 419 | write_to_data_lines($zabbix_name, "total.index.count", $total_index_count) ; 420 | 421 | $total_index_size = round($total_index_size/(1024*1024), 2) ; 422 | write_to_data_lines($zabbix_name, "total.index.size", $total_index_size) ; 423 | 424 | foreach($db_info_collections as $name => $dummy) { 425 | write_to_data_lines($zabbix_name, "db.collections[" . $name . "]", $db_info_collections[$name]) ; 426 | write_to_data_lines($zabbix_name, "db.objects[" . $name . "]", $db_info_objects[$name]) ; 427 | write_to_data_lines($zabbix_name, "db.indexes[" . $name . "]", $db_info_indexes[$name]) ; 428 | write_to_data_lines($zabbix_name, "db.avgObjSize[" . $name . "]", $db_info_avgObjSize[$name]) ; 429 | write_to_data_lines($zabbix_name, "db.dataSize[" . $name . "]", $db_info_dataSize[$name]) ; 430 | write_to_data_lines($zabbix_name, "db.indexSize[" . $name . "]", $db_info_indexSize[$name]) ; 431 | write_to_data_lines($zabbix_name, "db.storageSize[" . $name . "]", $db_info_storageSize[$name]) ; 432 | write_to_data_lines($zabbix_name, "db.numExtents[" . $name . "]", $db_info_numExtents_array[$name]) ; 433 | // write_to_data_lines($zabbix_name, "db.fileSize[" . $name . "]", $db_info_fileSize[$name]) ; 434 | } 435 | 436 | 437 | //----------------------------- 438 | // Check for replication / replicaSets 439 | //----------------------------- 440 | if ($is_sharded == 'No') { 441 | $mongo_db_handle = $mongo_connection->selectDB('admin') ; 442 | $rs_status = $mongo_db_handle->command(array('replSetGetStatus'=>1)) ; 443 | 444 | if (!($rs_status['ok'])) { 445 | write_to_data_lines($zabbix_name, "is_replica_set", "No") ; 446 | } 447 | else { 448 | write_to_data_lines($zabbix_name, "is_replica_set", "Yes") ; 449 | write_to_data_lines($zabbix_name, "replica_set_name", $rs_status['set']) ; 450 | write_to_data_lines($zabbix_name, "replica_set_member_count", count($rs_status['members']) ) ; 451 | 452 | $repl_set_member_names = '' ; 453 | foreach ($rs_status['members'] as $repl_set_member) { 454 | $repl_set_member_names .= 'host#' . $repl_set_member['_id'] . ' = ' . $repl_set_member['name'] . ' || ' ; 455 | } 456 | write_to_data_lines($zabbix_name, "replica_set_hosts", $repl_set_member_names) ; 457 | 458 | $local_mongo_db_handle = $mongo_connection->selectDB('local') ; 459 | $col_name = 'oplog.rs' ; 460 | $mongo_collection = $local_mongo_db_handle->$col_name ; 461 | $oplog_rs_count = $mongo_collection->count() ; 462 | write_to_data_lines($zabbix_name, "oplog.rs_count", $oplog_rs_count) ; 463 | 464 | //$rs_status = $mongo_db_handle->execute("$command") ; 465 | $repl_member_attention_state_count = 0 ; 466 | $repl_member_attenntion_state_info = '' ; 467 | 468 | foreach($rs_status['members'] as $member) { 469 | $member_state = $member['state'] ; 470 | 471 | $host = explode(':', $member['name']); 472 | $hostname = $host[0]; 473 | 474 | if ($member_state == 1) { 475 | $master_optime = $member['optime']; 476 | } 477 | 478 | $fqdn = explode('.', $mongodb_host); 479 | $mongodb_host_simple = $fqdn[0]; 480 | 481 | if (!in_array($hostname, array($mongodb_host_simple, $mongodb_host))) { 482 | continue; 483 | } 484 | 485 | $mongo_host_optime = $member['optime']; 486 | $seconds = $master_optime->sec - $mongo_host_optime->sec; 487 | 488 | if ($seconds < 0) { 489 | $seconds = 0; 490 | } 491 | 492 | write_to_data_lines($zabbix_name, "repl_member_replication_lag_sec", $seconds) ; 493 | 494 | if($member_state == 0 or $member_state == 3 or $member_state == 4 or $member_state == 5 or $member_state == 6 or $member_state == 8) { 495 | // 0 = Starting up, phase 1 496 | // 1 = primary 497 | // 2 = secondary 498 | // 3 = recovering 499 | // 4 = fatal error 500 | // 5 = starting up, phase 2 501 | // 6 = unknown state 502 | // 7 = arbiter 503 | echo "aaa\n" ; 504 | // 8 = down 505 | $repl_member_attention_state_count++ ; 506 | switch ($member_state) { 507 | case 0: $member_state = 'starting up, phase 1' ; 508 | break ; 509 | case 3: $member_state = 'recovering' ; 510 | break ; 511 | case 4: $member_state = 'fatal error' ; 512 | break ; 513 | case 5: $member_state = 'starting up, phase 2' ; 514 | break ; 515 | case 6: $member_state = 'unknown' ; 516 | break ; 517 | case 8: $member_state = 'down' ; 518 | break ; 519 | default: $member_state = 'unknown' ; 520 | break ; 521 | } 522 | $repl_member_attention_state_info .= $member['name'] . ' is in state ' . $member_state . ' ||' ; 523 | } 524 | } 525 | write_to_data_lines($zabbix_name, "repl_member_attention_state_count", $repl_member_attention_state_count) ; 526 | write_to_data_lines($zabbix_name, "repl_member_attention_state_info", ($repl_member_attention_state_count > 0 ? $repl_member_attention_state_info : 'empty') ) ; 527 | } 528 | 529 | } 530 | 531 | //----------------------------- 532 | // Check for sharding 533 | //----------------------------- 534 | if ($is_sharded == 'Yes') { 535 | $mongo_db_handle = $mongo_connection->selectDB('config') ; 536 | 537 | $mongo_collection = $mongo_db_handle->chunks ; 538 | $shard_info = $mongo_collection->count() ; 539 | write_to_data_lines($zabbix_name, "shard_chunk_count", $shard_info) ; 540 | 541 | $mongo_collection = $mongo_db_handle->collections ; 542 | $shard_info = $mongo_collection->count() ; 543 | write_to_data_lines($zabbix_name, "sharded_collections_count", $shard_info) ; 544 | 545 | $collection = $mongo_connection->selectDB('config')->selectCollection('collections') ; 546 | $cursor = $collection->find() ; 547 | $collection_array = iterator_to_array($cursor) ; 548 | $collection_info = '' ; 549 | foreach ($collection_array as $shard) { 550 | $collection_info .= $shard['_id'] . ' || ' ; 551 | } 552 | write_to_data_lines($zabbix_name, "sharded_collection_info", $collection_info) ; 553 | 554 | 555 | $command = "db.shards.count" ; 556 | $mongo_collection = $mongo_db_handle->shards ; 557 | $shard_info = $mongo_collection->count() ; 558 | write_to_data_lines($zabbix_name, "shard_count", $shard_info) ; 559 | 560 | $collection = $mongo_connection->selectDB('config')->selectCollection('shards') ; 561 | $cursor = $collection->find() ; 562 | $shards_array = iterator_to_array($cursor) ; 563 | $shard_info = '' ; 564 | foreach ($shards_array as $shard) { 565 | $shard_info .= $shard['_id'] . ' = ' . $shard['host'] . ' || ' ; 566 | } 567 | write_to_data_lines($zabbix_name, "shard_info", $shard_info) ; 568 | 569 | $collection = $mongo_connection->selectDB('config')->selectCollection('databases') ; 570 | $cursor = $collection->find() ; 571 | $db_array = iterator_to_array($cursor) ; 572 | $db_info = '' ; 573 | foreach ($db_array as $db) { 574 | if( $db['partitioned'] ) { 575 | $partitioned = 'yes' ; 576 | } 577 | else { 578 | $partitioned = 'no' ; 579 | } 580 | $db_info .= $db['_id'] . ' : ' . 'partitioned = ' . $partitioned . ', primary = ' . $db['primary'] . ' || ' ; 581 | } 582 | write_to_data_lines($zabbix_name, "db_info", $db_info) ; 583 | 584 | 585 | } 586 | 587 | //-------------------------------------------------------------------------// 588 | 589 | 590 | // Get data collection end time (we will use this to compute the total data collection time) 591 | $end_time = time() ; 592 | $data_collection_time = $end_time - $start_time ; 593 | write_to_data_lines($zabbix_name, "plugin.data_collection_time", $data_collection_time) ; 594 | 595 | write_to_data_lines($zabbix_name, "plugin.version", $command_version) ; 596 | write_to_data_lines($zabbix_name, "plugin.checksum", $md5_checksum_string) ; 597 | 598 | // For DEBUG 599 | if ($debug_mode) { 600 | $data_file_name = "/tmp/${command_name}_${file_base_name}.data" ; 601 | file_put_contents($data_file_name, implode("\n", $data_lines) . "\n") ; 602 | } 603 | 604 | $descriptorspec = array( 605 | 0 => array("pipe", "r"), // stdin 606 | 1 => array("pipe", "w"), // stdout 607 | 2 => array("pipe", "w") // stderr 608 | ) ; 609 | $process = proc_open("zabbix_sender -vv -z $zabbix_server -p $zabbix_server_port -i - 2>&1", $descriptorspec, $pipes) ; 610 | 611 | if (is_resource($process)) { 612 | fwrite($pipes[0], implode("\n", $data_lines)) ; 613 | fclose($pipes[0]) ; 614 | 615 | while($s = fgets($pipes[1], 1024)) { 616 | write_to_log("O: " . trim($s)) ; 617 | } 618 | fclose($pipes[1]); 619 | 620 | while($s= fgets($pipes[2], 1024)) { 621 | write_to_log("E: " . trim($s)) ; 622 | } 623 | fclose($pipes[2]) ; 624 | } 625 | 626 | exit ; 627 | 628 | ?> 629 | 630 | -------------------------------------------------------------------------------- /mongodb-3.2/mikoomi-mongodb-plugin-32.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PATH=$PATH:/etc/zabbix/externalscripts:/opt/zabbix/externalscripts:/opt/zabbix/bin:/home/zabbix/bin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin 3 | export PATH 4 | BASE_DIR="`dirname $0`" 5 | /usr/bin/php $BASE_DIR/mikoomi-mongodb-plugin-32.php $* 6 | echo 0 7 | --------------------------------------------------------------------------------