latest minidashboard code
Scott Baker [Tue, 13 Jan 2015 17:46:52 +0000 (09:46 -0800)]
planetstack/core/static/page_analytics.js
planetstack/templates/admin/newminidashboard.html

index 3491eda..9cdd7ed 100644 (file)
@@ -1,8 +1,8 @@
 // ----------------------------------------------------------------------------
 // node count and average cpu utilization
 
-function updatePageCPU() {
-    var url="/stats/?model_name=" + admin_object_name + "&pk=" + admin_object_id + "&meter=cpu" + "&controller_name=" + admin_object_controller;
+function updateMiniDashStatistic(meter, buttonSelector) {
+    var url="/stats/?model_name=" + admin_object_name + "&pk=" + admin_object_id + "&meter=" + meter + "&controller_name=" + admin_object_controller;
     console.log("fetching stats url " + url);
     $.ajax({
     url: url,
@@ -10,7 +10,14 @@ function updatePageCPU() {
     type : 'GET',
     success: function(newData) {
         console.log(newData);
-        setTimeout(updatePageAnalytics, 30000);
+        if (newData.stat_list.length > 0) {
+            value = newData.stat_list.slice(-1)[0].value;
+            console.log(value);
+            $(buttonSelector).text(Math.round(value)).show();
+        } else {
+            $(buttonSelector).text("no data").show();
+        }
+        setTimeout(function() { updateMiniDashStatistic(meter, buttonSelector); }, 30000);
     },
     error: function() {
     }
@@ -19,7 +26,9 @@ function updatePageCPU() {
 
 $( document ).ready(function() {
     if (admin_object_name == "Sliver" && admin_object_id != undefined) {
-        updatePageCPU();
+        updateMiniDashStatistic("cpu", "#miniDashCPU");
+        updateMiniDashStatistic("network.outgoing.bytes", "#miniDashBandwidthIn");
+        updateMiniDashStatistic("network.incoming.bytes", "#miniDashBandwidthOut");
     }
 });
 
index cef5b94..5c08401 100644 (file)
@@ -3,7 +3,7 @@
 <script>
     admin_object_name = "{{ opts.object_name }}";
     admin_object_id = "{{ original.id }}";
-    admin_object_controller = "princeton"; // XXX fix this
+    admin_object_controller = "princeton-beta"; // XXX fix this
     if (admin_object_id == "") {
         admin_object_id = undefined;
     } else {
     <div class="hide" id="selectedMainNav">{{ opts.verbose_name_plural|capfirst }}</div>
     <div class="hide" id="currentOriginalNode">{{ original|truncatewords:"18" }}</div>
     <div class="hide" id="minidashStatus"></div>
-    <div class="miniDashPair">
+    <!-- <div class="miniDashPair">
         <button type="button" name="nodeCount" id="miniDashNodeCount" class="minidashbutton">--</button>
         <label for="nodeCount" id="miniDashNodeCountLabel">Active Nodes</label>
+    </div> -->
+    <div class="miniDashPair">
+        <button type="button" name="CPU" id="miniDashCPU" class="minidashbutton">--</button>
+        <label for="CPU" id="miniDashAvgLoadLabel">CPU</label>
     </div>
     <div class="miniDashPair">
-        <button type="button" name="avgLoad" id="miniDashAvgLoad" class="minidashbutton">--</button>
-        <label for="avgLoad" id="miniDashAvgLoadLabel">Average Load</label>
+        <button type="button" name="bandwidthIn" id="miniDashBandwidthIn" class="minidashbutton">--</button>
+        <label for="bandwidthIn" id="miniDashBandwidthLabel">Bandwidth In</label>
     </div>
     <div class="miniDashPair">
-        <button type="button" name="bandwidth" id="miniDashBandwidth" class="minidashbutton">--</button>
-        <label for="bandwidth" id="miniDashBandwidthLabel">Bandwidth</label>
+        <button type="button" name="bandwidthOut" id="miniDashBandwidthOut" class="minidashbutton">--</button>
+        <label for="bandwidthOut" id="miniDashBandwidthLabel">Bandwidth Out</label>
     </div>
     <div class="endDashPair">
     </div>