blob: 698396f5578756932c0abfdda90c595c8ef54d20 [file] [log] [blame]
Scott Baker771819b2014-03-19 22:10:17 -07001// ----------------------------------------------------------------------------
2// node count and average cpu utilization
3
Scott Bakerf13a0cf2015-01-13 09:46:52 -08004function updateMiniDashStatistic(meter, buttonSelector) {
5 var url="/stats/?model_name=" + admin_object_name + "&pk=" + admin_object_id + "&meter=" + meter + "&controller_name=" + admin_object_controller;
Scott Baker0e36f5d2015-01-13 01:06:34 -08006 console.log("fetching stats url " + url);
Scott Baker771819b2014-03-19 22:10:17 -07007 $.ajax({
Scott Baker61aefcf2014-04-25 15:21:18 -07008 url: url,
Scott Baker771819b2014-03-19 22:10:17 -07009 dataType : 'json',
10 type : 'GET',
Scott Bakerb23dd1d2014-06-09 16:03:35 -070011 success: function(newData) {
Scott Baker0e36f5d2015-01-13 01:06:34 -080012 console.log(newData);
Scott Bakere2dfb102015-02-13 21:40:51 -080013 if (newData.error) {
14 $(buttonSelector).text(newData.error);
15 } else if (newData.stat_list.length > 0) {
Scott Bakerf13a0cf2015-01-13 09:46:52 -080016 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 Bakerb23dd1d2014-06-09 16:03:35 -070023 },
24 error: function() {
Scott Baker771819b2014-03-19 22:10:17 -070025 }
26});
Scott Baker771819b2014-03-19 22:10:17 -070027}
28
Scott Bakerca2e22d2014-05-23 18:26:06 -070029$( document ).ready(function() {
Scott Baker0e36f5d2015-01-13 01:06:34 -080030 if (admin_object_name == "Sliver" && admin_object_id != undefined) {
Scott Bakerf13a0cf2015-01-13 09:46:52 -080031 updateMiniDashStatistic("cpu", "#miniDashCPU");
32 updateMiniDashStatistic("network.outgoing.bytes", "#miniDashBandwidthIn");
33 updateMiniDashStatistic("network.incoming.bytes", "#miniDashBandwidthOut");
Scott Baker0e36f5d2015-01-13 01:06:34 -080034 }
35});
Scott Baker771819b2014-03-19 22:10:17 -070036