Commits

lunaticas committed ba59c28

Check if sum of llc_loads is above a threshold and display the alarm.

  • Participants
  • Parent commits 4692eea

Comments (0)

Files changed (4)

File web/graph/urls.py

     # url(r'^$', 'web.views.home', name='home'),
     # url(r'^web/', include('web.foo.urls')),
     url(r'^graph.png$', 'graph.views.image'),
+    url(r'^threat_llc_loads$', 'graph.views.threat_llc_loads'),
     url(r'^measures$', 'graph.views.measures'),
     url(r'^guests$', 'graph.views.guests'),
     url(r'', 'graph.views.index'),

File web/graph/views.py

 
 from django.http import HttpResponse
 from django.shortcuts import render_to_response
+from django.db.models import F
+from django.db.models.aggregates import Max
 
 from graph.models import Measurement
 
 
 def measures(request):
     result = set()
-    measurements = Measurement.objects.all()
+    measurements = Measurement.objects.values('measure').distinct()
     for measurement in measurements:
-        result.add(measurement.measure)
+        print measurement
+        result.add(measurement['measure'])
     return HttpResponse(json.dumps(list(result)), mimetype='application/json')
 
 
     for guest in guests:
         result.add(guest.get_name())
     return HttpResponse(json.dumps(list(result)), mimetype='application/json')
+
+
+def threat_llc_loads(request):
+    measure = 'CPU_MEM/LLC-loads'
+    max_time = Measurement.objects.aggregate(Max('time'))['time__max']
+    measurements = Measurement.objects.filter(measure='CPU_MEM/LLC-loads', time=max_time)
+    total_value = 0
+    max_value = 0
+    guest = None
+    for measurement in measurements:
+        total_value += measurement.value
+        if max_value < measurement.value:
+            max_value = measurement.value
+            guest = measurement.guest
+    return HttpResponse(json.dumps({'value': total_value, 'max_guest': guest}), mimetype='application/json')

File web/public/js/index.js

 $(function() {
+      var THREAT_LLC_LOADS = 100000;
+
       window.ImageView = Backbone.View.extend(
           {
               tagName: 'div',
           {
               tagName: 'fieldset',
 
-              template: _.template('<input type="checkbox" name="guest" value="<%= name %>" /><%= name %><br />'),
+              template: _.template('<input type="checkbox" name="guest" value="<%= name %>" /><span id="span_<%= name %>"><%= name %></span><br />'),
 
               initialize: function() {
                   this.el = $(this.el);
                           result.push($(this).val());
                       });
                   return result;
+              },
+
+              setRed: function(guest)
+              {
+                  this.el.find('span[id="span_' + guest + '"]').addClass('red');
+
+              },
+
+              unsetRed: function()
+              {
+                  this.el.find('input').removeClass('red');
               }
           });
 
           var measure = measureView.getValue();
           measure = measure ? measure : '';
           imageView.setSrc('/graph/graph.png?count=' + (++count) + '&duration=100&guests=' + guests + '&measure=' + measure);
+
+          $.get('/graph/threat_llc_loads', function(threat)
+                {
+                    if (threat.value > THREAT_LLC_LOADS)
+                    {
+                        guestView.unsetRed();
+                        guestView.setRed(threat.max_guest);
+                    }
+                    else
+                    {
+                        guestView.unsetRed();
+                    }
+                });
       };
 
       setInterval(refresh, 1000);

File web/templates/index.html

 <html>
   <head>
     <title>KVM Profiler</title>
+    <style type="text/css">
+      span.red {
+        color: red
+      }
+    </style>    
   </head>
   <body>
     <script src="/public/js/vendor/jquery-1.7.js"></script>