Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 1 | // ---------------------------------------------------------------------------- |
| 2 | // node count and average cpu utilization |
| 3 | |
Scott Baker | 9b1f2a0 | 2015-01-13 09:46:52 -0800 | [diff] [blame] | 4 | function updateMiniDashStatistic(meter, buttonSelector) { |
| 5 | var url="/stats/?model_name=" + admin_object_name + "&pk=" + admin_object_id + "&meter=" + meter + "&controller_name=" + admin_object_controller; |
Scott Baker | a0ffec5 | 2015-01-13 01:06:34 -0800 | [diff] [blame] | 6 | console.log("fetching stats url " + url); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 7 | $.ajax({ |
Scott Baker | 61aefcf | 2014-04-25 15:21:18 -0700 | [diff] [blame] | 8 | url: url, |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 9 | dataType : 'json', |
| 10 | type : 'GET', |
Scott Baker | b23dd1d | 2014-06-09 16:03:35 -0700 | [diff] [blame] | 11 | success: function(newData) { |
Scott Baker | a0ffec5 | 2015-01-13 01:06:34 -0800 | [diff] [blame] | 12 | console.log(newData); |
Scott Baker | 57a044c | 2015-02-13 21:40:51 -0800 | [diff] [blame] | 13 | if (newData.error) { |
| 14 | $(buttonSelector).text(newData.error); |
| 15 | } else if (newData.stat_list.length > 0) { |
Scott Baker | 9b1f2a0 | 2015-01-13 09:46:52 -0800 | [diff] [blame] | 16 | value = newData.stat_list.slice(-1)[0].value; |
| 17 | console.log(value); |
| 18 | $(buttonSelector).text(Math.round(value)).show(); |
| 19 | } else { |
| 20 | $(buttonSelector).text("no data").show(); |
| 21 | } |
| 22 | setTimeout(function() { updateMiniDashStatistic(meter, buttonSelector); }, 30000); |
Scott Baker | b23dd1d | 2014-06-09 16:03:35 -0700 | [diff] [blame] | 23 | }, |
| 24 | error: function() { |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 25 | } |
| 26 | }); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Scott Baker | ca2e22d | 2014-05-23 18:26:06 -0700 | [diff] [blame] | 29 | $( document ).ready(function() { |
Scott Baker | a0ffec5 | 2015-01-13 01:06:34 -0800 | [diff] [blame] | 30 | if (admin_object_name == "Sliver" && admin_object_id != undefined) { |
Scott Baker | 9b1f2a0 | 2015-01-13 09:46:52 -0800 | [diff] [blame] | 31 | updateMiniDashStatistic("cpu", "#miniDashCPU"); |
| 32 | updateMiniDashStatistic("network.outgoing.bytes", "#miniDashBandwidthIn"); |
| 33 | updateMiniDashStatistic("network.incoming.bytes", "#miniDashBandwidthOut"); |
Scott Baker | a0ffec5 | 2015-01-13 01:06:34 -0800 | [diff] [blame] | 34 | } |
| 35 | }); |
Scott Baker | 771819b | 2014-03-19 22:10:17 -0700 | [diff] [blame] | 36 | |