├── LICENSE.txt
├── README.md
├── TODO
├── background.html
├── icon_128.png
├── icon_16.png
├── icon_48.png
├── images
├── back-header.png
├── favicon.ico
└── logo-mongoDB.png
├── js
├── app.js
├── datatables-1.7.5
│ ├── css
│ │ └── hosts_table.css
│ ├── images
│ │ ├── back_disabled.jpg
│ │ ├── back_enabled.jpg
│ │ ├── forward_disabled.jpg
│ │ ├── forward_enabled.jpg
│ │ ├── sort_asc.png
│ │ ├── sort_asc_disabled.png
│ │ ├── sort_both.png
│ │ ├── sort_desc.png
│ │ └── sort_desc_disabled.png
│ └── js
│ │ └── jquery.dataTables.min.js
├── jquery-1.4.4.min.js
├── jquery-ui-1.8.8.custom.min.js
├── jquery.base64-1.0.min.js
└── smoothie.js
├── main.html
├── manifest.json
├── options.html
├── screenshot.png
├── test
└── dance.js
└── themes
├── dark.css
└── pepper-grinder
├── images
├── ui-bg_diagonal-maze_20_6e4f1c_10x10.png
├── ui-bg_diagonal-maze_40_000000_10x10.png
├── ui-bg_fine-grain_10_eceadf_60x60.png
├── ui-bg_fine-grain_10_f8f7f6_60x60.png
├── ui-bg_fine-grain_15_eceadf_60x60.png
├── ui-bg_fine-grain_15_f7f3de_60x60.png
├── ui-bg_fine-grain_15_ffffff_60x60.png
├── ui-bg_fine-grain_65_654b24_60x60.png
├── ui-bg_fine-grain_68_b83400_60x60.png
├── ui-icons_222222_256x240.png
├── ui-icons_3572ac_256x240.png
├── ui-icons_8c291d_256x240.png
├── ui-icons_b83400_256x240.png
├── ui-icons_fbdb93_256x240.png
└── ui-icons_ffffff_256x240.png
└── jquery-ui-1.8.8.custom.css
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | About
3 | =============
4 |
5 | Mongo Live is a Chrome extension for real-time monitoring of MongoDB.
6 |
7 | You can install the extension from the Chrome Web Store:
8 |
9 | * [https://chrome.google.com/webstore/detail/apgglicbkgjcfnohdcgbcobengnkcjef](https://chrome.google.com/webstore/detail/apgglicbkgjcfnohdcgbcobengnkcjef)
10 |
11 | Thie product is not affiliated with MongoDB.
12 |
13 | This product uses/includes the following open source projects:
14 |
15 | * [Smoothie Charts](http://smoothiecharts.org/) - MIT License - Copyright (c) 2010, Joe Walnes
16 |
17 | * [jQuery](http://jquery.org) - MIT License or GPL v2
18 |
19 | * [DataTables](http://www.datatables.net/) - GPL v2 - Copyright (c) 2007-2011, Allan Jardine
20 |
21 | * Images are from [MongoDB](http://www.mongodb.org) - Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
22 |
23 | * [jQuery Base64 Plugin](http://plugins.jquery.com/project/base64-encode-and-decode) - MIT License or GPL v2
24 |
25 | Thanks to the members of 10gen who provided feedback/suggestions.
26 |
27 | License
28 | =============
29 |
30 | Copyright 2011, [Deft Labs](http://deftlabs.com).
31 |
32 | Licensed under the Apache License, Version 2.0 (the "License");
33 | you may not use this file except in compliance with the License.
34 | You may obtain a copy of the License at:
35 |
36 | [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
37 |
38 | Unless required by applicable law or agreed to in writing, software
39 | distributed under the License is distributed on an "AS IS" BASIS,
40 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41 | See the License for the specific language governing permissions and
42 | limitations under the License.
43 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 |
2 | Add options page to allow for adding remote hosts.
3 |
4 | Add drop down to allow for different host display.
5 | * Make sure to disable all interval polls when changing hosts
6 |
7 | Add a brag feature for charts.
8 |
9 |
--------------------------------------------------------------------------------
/background.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mongo Live
5 |
6 |
7 |
8 |
9 |
10 |
22 |
23 |
24 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deftlabs/mongo-live/e2c3eec4e8d191ad4a92919422662263dc9b3433/icon_128.png
--------------------------------------------------------------------------------
/icon_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deftlabs/mongo-live/e2c3eec4e8d191ad4a92919422662263dc9b3433/icon_16.png
--------------------------------------------------------------------------------
/icon_48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deftlabs/mongo-live/e2c3eec4e8d191ad4a92919422662263dc9b3433/icon_48.png
--------------------------------------------------------------------------------
/images/back-header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deftlabs/mongo-live/e2c3eec4e8d191ad4a92919422662263dc9b3433/images/back-header.png
--------------------------------------------------------------------------------
/images/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deftlabs/mongo-live/e2c3eec4e8d191ad4a92919422662263dc9b3433/images/favicon.ico
--------------------------------------------------------------------------------
/images/logo-mongoDB.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deftlabs/mongo-live/e2c3eec4e8d191ad4a92919422662263dc9b3433/images/logo-mongoDB.png
--------------------------------------------------------------------------------
/js/app.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Copyright 2011, Deft Labs.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at:
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | var currentServerStatus = [];
19 | var previousServerStatus = [];
20 | var selectedHostId = null;
21 | var serverStatusInterval = null;
22 |
23 | $.base64.is_unicode = true;
24 |
25 | /**
26 | * Start the app/main.
27 | */
28 | function runApp() {
29 |
30 | var hosts = loadHosts();
31 | selectedHostId = getPersistedItem('selectedHost');
32 |
33 | if (hosts.length > 1) {
34 |
35 | var hostOptions = $('#hostSelect').attr('options');
36 | var foundSelected = false;
37 | for (var idx in hosts) {
38 | var host = hosts[idx];
39 | var hostId = assembleHostId(host);
40 | if (selectedHostId == hostId) foundSelected = true;
41 | hostOptions[idx] = new Option(hostId, hostId);
42 | }
43 |
44 | if (foundSelected) $('#hostSelect').val(selectedHostId);
45 |
46 | $('#hostSelect').change(function() {
47 | var hostId = $('#hostSelect option:selected').val();
48 | selectedHostId = hostId;
49 | persistItem("selectedHost", selectedHostId);
50 | startServerStatusPoll();
51 | });
52 |
53 | $('#hostSelectContainer').show();
54 |
55 | } else {
56 |
57 | if (hosts.length == 1) {
58 | // Set the current to first record.
59 | selectedHostId = hosts[0][0] + ':' + hosts[0][1];
60 | persistItem("selectedHost", selectedHostId);
61 | } else {
62 | // No hosts in the system.
63 | $('#statusMsgContainer').html('No servers configured. Add a server in options.');
64 | $('#statusMsgContainer').show();
65 | }
66 | }
67 |
68 | startServerStatusPoll();
69 |
70 | createChart('opcounters', 'query', 'opcountersQueryChart', 'rgba(57, 20, 175, 1)', 'rgba(57, 20, 175, 0)', true);
71 | createChart('opcounters', 'insert', 'opcountersInsertChart', 'rgba(135, 110, 215, 1)', 'rgba(135, 110, 215, 0)', true);
72 | createChart('opcounters', 'update', 'opcountersUpdateChart', 'rgba 64, 171, 1)', 'rgba(18, 64, 171, 0)', true);
73 | createChart('opcounters', 'delete', 'opcountersDeleteChart', 'rgba(255, 231, 115, 1)', 'rgba(255, 231, 115, 0)', true);
74 | createChart('opcounters', 'command', 'opcountersCommandChart', 'rgba(255, 128, 64, 1)', 'rgba(255, 128, 64, 0)', true);
75 | createChart('opcounters', 'getmore', 'opcountersGetmoreChart', 'rgba(191, 96, 48, 1)', 'rgba(191, 96, 48, 0)', true);
76 | createChart('connections', 'current', 'connectionsCurrentChart', 'rgba(255, 255, 0, 1)', 'rgba(255, 255, 0, 0)', false);
77 | createChart('extra_info', 'page_faults', 'pageFaultsChart', 'rgba(185, 247, 62, 1)', 'rgba(185, 247, 62, 0)', true);
78 | createChart('backgroundFlushing', 'flushes', 'flushesChart', 'rgba(166, 137, 0, 1)', 'rgba(166, 137, 0, 0)', true);
79 | createPercentChart('lockedPercentChart', 'rgba(191, 191, 48, 1)', 'rgba(191, 191, 48, 0)', 'globalLock', 'totalTime', 'globalLock', 'lockTime');
80 | createPercentChart('idxMissPercentChart', 'rgba(166, 75, 0, 1)', 'rgba(166, 75, 0, 0)', 'indexCounters', 'btree.accesses', 'indexCounters', 'btree.misses');
81 | createChart('mem', 'mapped', 'memMappedChart', 'rgba(255, 116, 0, 1)', 'rgba(255, 116, 0, 0)', false);
82 | createChart('network', 'bytesIn', 'netInChart', 'rgba(255, 128, 64, 1)', 'rgba(255, 128, 64, 0)', true);
83 | createChart('network', 'bytesOut', 'netOutChart', 'rgba(191, 96, 48, 1)', 'rgba(191, 96, 48, 0)', true);
84 |
85 | };
86 |
87 | /**
88 | * Setup the options page.
89 | */
90 | function runOptions() {
91 |
92 | $("#addHost").button();
93 |
94 | $("#addHostSubmit").button();
95 |
96 | $('#addHostSubmit').click(function(event) {
97 | event.preventDefault();
98 |
99 | //$('#addHostSubmit').attr('disabled', 'disabled');
100 | $('#addHostInvalidHostnameMsg').hide();
101 | $('#addHostInvalidHostPortMsg').hide();
102 | $('#addHostDuplicateHostMsg').hide();
103 |
104 | var hostname = $('#hostname').val();
105 | var port = $('#port').val();
106 | var username = $('#u').val();
107 | var password = $('#p').val();
108 | var hostId = $('#hostId').val();
109 |
110 | var isAdd = $('#isAdd').val();
111 |
112 | if (!hostname || hostname == '') {
113 | $('#addHostInvalidHostnameMsg').show('fast');
114 | return;
115 | };
116 |
117 | if (!isInt(port)) {
118 | $('#addHostInvalidHostPortMsg').show('fast');
119 | return;
120 | }
121 |
122 | if (!username || username == null) username = '';
123 |
124 | if (!password || password == null) password = '';
125 | else password = $.base64.encode(password);
126 |
127 | port = parseInt(port, 10);
128 |
129 | // We are either editing or adding.
130 | if (isAdd && isAdd == 'true') {
131 |
132 | var newHost = [];
133 | newHost.push(hostname);
134 | newHost.push(port);
135 | newHost.push(username);
136 | newHost.push(password);
137 |
138 | var hosts = loadHosts();
139 |
140 | // Look for a duplicate.
141 | for (var idx in hosts) {
142 | var host = hosts[idx];
143 | if (host[0] == hostname && host[1] == port) {
144 | $('#addHostDuplicateHostMsg').show('fast');
145 | return;
146 | }
147 | }
148 |
149 | hosts.push(newHost);
150 | persistItem('hosts', hosts);
151 |
152 | if (!password || password == null) newHost[3] = '';
153 | else newHost[3] = '';
154 |
155 | addTableEditControls(newHost);
156 |
157 | // Add the row to the table.
158 | $('#hostsTable').dataTable().fnAddData(newHost);
159 |
160 | } else {
161 | // We are dealing with an edit.
162 | var hosts = loadHosts();
163 |
164 | for (var idx in hosts) {
165 | var host = hosts[idx];
166 | var hid = assembleHostId(host);
167 | if (hostId == hid) {
168 | host[0] = hostname;
169 | host[1] = port;
170 | host[2] = username;
171 | host[3] = password;
172 |
173 | // Make sure the old host is not the selected value.
174 | var storedSelectedId = getPersistedItem('selectedHost');
175 | if (storedSelectedId == hostId) {
176 | var newSelectedHostId = assembleHostId(host);
177 | persistItem("selectedHost", newSelectedHostId);
178 | selectedHostId = newSelectedHostId;
179 | startServerStatusPoll();
180 | }
181 |
182 | break;
183 | }
184 | }
185 |
186 | persistItem('hosts', hosts);
187 |
188 | window.location.reload(false);
189 | }
190 |
191 | $("#addHostContainer").dialog("close");
192 | });
193 |
194 | $('#addHost').click(function() { launchEditHostContainer('127.0.0.1', 28017, '', '', 'Add Host', true, null); });
195 |
196 | var hosts = loadHosts();
197 |
198 | for (var idx in hosts) {
199 | var host = hosts[idx];
200 | if (host[3] && host[3] != null && host[3] != '') {
201 | host[3] = '';
202 | }
203 |
204 | var hostId = assembleHostId(host);
205 |
206 | addTableEditControls(host);
207 | }
208 |
209 | $('#hostsTable').dataTable( {
210 | 'bProcessing': false,
211 | 'bJQueryUI': true,
212 | "aaData": hosts,
213 | 'sPaginationType': 'full_numbers',
214 | 'iDisplayLength': 50,
215 | 'bLengthChange': false,
216 | "aoColumns": [
217 | { "bSortable": true, "sWidth": "50%" },
218 | { "bSortable": true, "sWidth": "10%" },
219 | { "bSortable": true, "sWidth": "20%" },
220 | { "bSortable": false, "sWidth": "10%" },
221 | { "bSortable": false, "sWidth": "10%" }
222 | ]
223 | });
224 | };
225 |
226 | /**
227 | * Edit the host.
228 | */
229 | function editHost(hostId) {
230 | var host = findHost(hostId);
231 | // Get out of here if the host is missing.
232 | if (host == null) { window.location.reload(false); return; }
233 | launchEditHostContainer(host[0], host[1], host[2], host[3], 'Edit Host', false, hostId);
234 | };
235 |
236 | /**
237 | * Delete the host.
238 | */
239 | function deleteHost(hostId) {
240 | var hosts = loadHosts();
241 | var newHosts = [];
242 |
243 | for (var idx in hosts) {
244 | var host = hosts[idx];
245 | var hid = assembleHostId(host);
246 | if (hostId == hid) {
247 | // Make sure the old host is not the selected value.
248 | var storedSelectedId = getPersistedItem('selectedHost');
249 | if (storedSelectedId == hostId) {
250 | stopServerStatusPoll();
251 | removeItem('selectedHost');
252 | }
253 | } else { newHosts.push(host); }
254 | }
255 |
256 | persistItem('hosts', newHosts);
257 |
258 | window.location.reload(false);
259 | };
260 |
261 | function launchEditHostContainer(hostname, port, username, password, title, isAdd, hostId) {
262 | $('#addHostInvalidHostnameMsg').hide();
263 | $('#addHostInvalidHostPortMsg').hide();
264 | $('#addHostDuplicateHostMsg').hide();
265 |
266 | $('#hostname').val(hostname);
267 | $('#port').val(port);
268 | $('#u').val(username);
269 | $('#p').val(password);
270 | $('#isAdd').val(isAdd);
271 |
272 | if (hostId && hostId != null) $('#hostId').val(hostId);
273 |
274 | $("#addHostContainer").dialog({ height: 390, width: 410, modal: true, title: title, resizable: false, stack: true, show: 'fade', hide: 'fade' });
275 | };
276 |
277 | /**
278 | * Stop the server status poll.
279 | */
280 | function stopServerStatusPoll() { if (serverStatusInterval) clearInterval(serverStatusInterval); };
281 |
282 | /**
283 | * Start the interval lookup for server status.
284 | */
285 | function startServerStatusPoll() {
286 |
287 | stopServerStatusPoll();
288 |
289 | var hosts = loadHosts();
290 |
291 | if (!selectedHostId) {
292 | for (var idx in hosts) {
293 | selectedHostId = assembleHostId(hosts[idx]);
294 | persistItem("selectedHost", selectedHostId);
295 | break;
296 | }
297 | }
298 |
299 | if (!selectedHostId) return;
300 |
301 | var selectedHost = parseHostId(selectedHostId);
302 |
303 | var host = null;
304 |
305 | for (var idx in hosts) {
306 | host = hosts[idx];
307 | if (host[0] == selectedHost[0] && host[1] == selectedHost[1]) break;
308 | }
309 |
310 | if (host == null) return;
311 |
312 | serverStatusInterval = setInterval(function() {
313 | queryServerStatus(host, function(response) {
314 | previousServerStatus = currentServerStatus;
315 | currentServerStatus = response;
316 | });
317 | }, 1000);
318 | };
319 |
320 | /**
321 | * Returns the value or undefined if not found.
322 | */
323 | function extractServerStatusValue(serverStatus, group, identity) {
324 | var groupObj = serverStatus[group];
325 |
326 | if (!groupObj) return undefined;
327 | if (identity.indexOf('.') == -1) return groupObj[identity];
328 |
329 | // We are dealing with a nested object.
330 | var nestedGroupName = identity.substring(0, identity.indexOf('.'));
331 | var nestedIdentityName = identity.substring(identity.indexOf('.')+1, identity.length);
332 |
333 | var nestedGroupObj = groupObj[nestedGroupName];
334 | if (!nestedGroupObj) return undefined;
335 |
336 | return nestedGroupObj[nestedIdentityName];
337 | };
338 |
339 | /**
340 | * Add a server status value to a series for a group/identity.
341 | */
342 | function addServerStatusValueToSeries(series, group, identity, isCounter) {
343 | var x = (new Date()).getTime();
344 |
345 | var currentValue = extractServerStatusValue(currentServerStatus, group, identity);
346 |
347 | var y = 0;
348 | if (isCounter) {
349 | var previousValue = extractServerStatusValue(previousServerStatus, group, identity);
350 |
351 | if (currentValue && previousValue && (currentValue > previousValue)) {
352 | y = currentValue - previousValue;
353 | }
354 | } else { y = currentValue; }
355 | series.append(x, y);
356 | };
357 |
358 | /**
359 | * Add a server status value to a series for a group/identity.
360 | */
361 | function addPercentToTimeSeries(series, group1, identity1, group2, identity2) {
362 | var x = (new Date()).getTime();
363 |
364 | var current1 = extractServerStatusValue(currentServerStatus, group1, identity1);
365 | var current2 = extractServerStatusValue(currentServerStatus, group2, identity2);
366 |
367 | var previous1 = extractServerStatusValue(previousServerStatus, group1, identity1);
368 | var previous2 = extractServerStatusValue(previousServerStatus, group2, identity2);
369 |
370 | var y = 0;
371 |
372 | var x1 = previous2 - current2;
373 | var y1 = previous1 - current1;
374 |
375 | if (y1 != 0) { y = (((x1 / y1) * 1000) / 10); }
376 |
377 | series.append(x, y);
378 | };
379 |
380 | /**
381 | * Create the lock percentage chart.
382 | */
383 | function createPercentChart(divId, lineColor, fillColor, group1, identity1, group2, identity2) {
384 | var series = new TimeSeries();
385 | setInterval(function() { addPercentToTimeSeries(series, group1, identity1, group2, identity2); }, 1000);
386 |
387 | var chart = new SmoothieChart({ millisPerPixel: 20, grid: { strokeStyle: '#555555', fillStyle: '#402817', lineWidth: 1, millisPerLine: 1000, verticalSections: 4 }});
388 | chart.addTimeSeries(series, { strokeStyle: lineColor, fillStyle: fillColor, lineWidth: 3 });
389 | chart.streamTo(document.getElementById(divId), 1000);
390 | };
391 |
392 | /**
393 | * Create a chart with a single time series.
394 | */
395 | function createChart(group, identity, divId, lineColor, fillColor, isCounter) {
396 | var series = new TimeSeries();
397 |
398 | setInterval(function() { addServerStatusValueToSeries(series, group, identity, isCounter); }, 1000);
399 |
400 | var chart = new SmoothieChart({ millisPerPixel: 20, grid: { strokeStyle: '#555555', fillStyle: '#402817', lineWidth: 1, millisPerLine: 1000, verticalSections: 4 }});
401 | chart.addTimeSeries(series, { strokeStyle: lineColor, fillStyle: fillColor, lineWidth: 3 });
402 | chart.streamTo(document.getElementById(divId), 1000);
403 | };
404 |
405 | function queryServerStatus(host, success, failure, cmdError, notFound, serverError) {
406 | queryDb(('http://' + host[0] + ':' + host[1] + '/serverStatus'), host[2], host[3], success, failure, cmdError, notFound, serverError);
407 | };
408 |
409 | function queryDb(commandUrl, username, password, success, failure, cmdError, notFound, serverError) {
410 |
411 | var xhr = new XMLHttpRequest();
412 | if (username && username != null && username != '') {
413 | xhr.open("GET", commandUrl, true, username, $.base64.decode(password));
414 | } else { xhr.open("GET", commandUrl, true); }
415 |
416 | xhr.onreadystatechange = function() {
417 |
418 | if (xhr.readyState == 4 && xhr.status == 200) {
419 | authProblem = false;
420 | $('#statusMsgContainer').hide();
421 |
422 | var resp = JSON.parse(fixDateFields(xhr.responseText));
423 |
424 | // TODO: Check for mongo error state in response json
425 |
426 | success(resp);
427 | } else if (xhr.readyState == 4 && xhr.status == 404) {
428 | if (notFound) notFound();
429 |
430 | } else if (xhr.readyState == 4 && xhr.status == 0) {
431 | // The client is not able to connect to the server. Display error message.
432 | $('#statusMsgContainer').html('Unable to connect to server: ' + commandUrl);
433 | $('#statusMsgContainer').show();
434 |
435 | } else if (xhr.readyState == 4 && xhr.status != 200) {
436 | if (serverError) serverError(xhr.readyState, xhr.status);
437 | if (failure) failure(xhr.readyState, xhr.status);
438 | }
439 | }
440 | xhr.send();
441 | };
442 |
443 | /**
444 | * There is a date format bug in some older versions of Mongo. Thanks to Lucas for
445 | * submitting part of the regex solution :-)
446 | *
447 | * The regex below replaces the date fields with 0 (since they are not used).
448 | *
449 | * http://jira.mongodb.org/browse/SERVER-2378
450 | *
451 | * The old format is:
452 | * "last_finished" : Date( 1295450058854 )
453 | * The date format in newer releases is:
454 | * "localTime" : { "$date" : 1295452287356 }
455 | */
456 | function fixDateFields(resp) { return resp.replace(/Date\( (\d+) \)/g, "0"); };
457 |
458 | function isInt(v) {
459 | var regex = /(^-?\d\d*$)/;
460 | return regex.test(v);
461 | };
462 |
463 | /**
464 | * Parse the host id.
465 | */
466 | function parseHostId(hostId) { return hostId.split(":"); };
467 |
468 | /**
469 | * Assemble the host id.
470 | */
471 | function assembleHostId(host) { return baseAssembleHostId(host[0], host[1]); };
472 |
473 | /**
474 | * Assemble the host based on hostname and port.
475 | */
476 | function baseAssembleHostId(hostname, port) { return hostname + ':' + port; };
477 |
478 | /**
479 | * Add the host edit controls (in the table).
480 | */
481 | function addTableEditControls(host) {
482 | var hostId = assembleHostId(host);
483 |
484 | host.push('