Pankaj Berde | c4ae4b8 | 2013-01-12 09:56:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2012 IBM |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | window.Status = Backbone.Model.extend({ |
| 18 | defaults: { |
| 19 | host: 'localhost', |
| 20 | ofport: 6633, |
| 21 | uptime: 'unknown', |
| 22 | free: 0, |
| 23 | total: 0, |
| 24 | healthy: 'unknown', |
| 25 | modules: [], |
| 26 | moduleText: '' |
| 27 | }, |
| 28 | |
| 29 | initialize:function () { |
| 30 | var self = this; |
| 31 | console.log("fetching controller status"); |
| 32 | $.ajax({ |
| 33 | url:hackBase + "/wm/core/health/json", |
| 34 | dataType:"json", |
| 35 | success:function (data) { |
| 36 | console.log("fetched controller status: health"); |
| 37 | self.set(data); |
| 38 | // console.log(self.toJSON()); |
| 39 | } |
| 40 | }); |
| 41 | $.ajax({ |
| 42 | url:hackBase + "/wm/core/system/uptime/json", |
| 43 | dataType:"json", |
| 44 | success:function (data) { |
| 45 | console.log("fetched controller status: uptime"); |
| 46 | self.set({uptime:(Math.round(data.systemUptimeMsec / 1000) + ' s')}); |
| 47 | // console.log(self.toJSON()); |
| 48 | } |
| 49 | }); |
| 50 | $.ajax({ |
| 51 | url:hackBase + "/wm/core/memory/json", |
| 52 | dataType:"json", |
| 53 | success:function (data) { |
| 54 | console.log("fetched controller status: memory"); |
| 55 | self.set(data); |
| 56 | // console.log(self.toJSON()); |
| 57 | } |
| 58 | }); |
| 59 | $.ajax({ |
| 60 | url:hackBase + "/wm/core/module/loaded/json", |
| 61 | dataType:"json", |
| 62 | success:function (data) { |
| 63 | console.log("fetched controller status: modules loaded"); |
| 64 | // console.log(data); |
| 65 | self.set({modules:_.keys(data)}); |
| 66 | self.set({moduleText:_.reduce(_.keys(data), function(s, m) |
| 67 | {return s+m.replace("net.floodlightcontroller", "n.f")+", "}, '')}); |
| 68 | } |
| 69 | }); |
| 70 | |
| 71 | } |
| 72 | |
| 73 | }); |