Project

General

Profile

Download (1.61 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
$(document).ready(function(){
3

    
4
  function updateMemoryStatus() {
5
     $.getJSON(
6
        "MemoryService.jsp",
7
        function(data){
8
          $("#status").html(''); // make empty
9
          $("#status").html('<div>CPU Cores: ' + data.availableProcessors + '</div>'); // make empty
10
          $("#status").append(memoryUsageEntry(data.heapMemoryUsage, data.recommendedMinimumHeap, "HeapUsage", "100%", "#F48B65", "#65B1F4"));
11
          if(data.permGenSpaceUsage){
12
              $("#status").append(memoryUsageEntry(data.permGenSpaceUsage, data.recommendedMinimumPermGenSpace, "PermGenSpaceUsage", "100%","#F48B65", "#65B1F4"));              
13
          }
14
     }); // end JSON
15

    
16

    
17
    setTimeout(function(){
18
        updateMemoryStatus()
19
        }, 1000);
20

    
21
  } // end updateMemory
22

    
23
  function memoryUsageEntry(memoryUsage, recommended, label, barWidth, cssColorUsed, cssColorMax){
24
    var mb = 1024 * 1024;
25
    var gb = mb * 1024;
26
    
27
    var max = memoryUsage.max ? memoryUsage.max / mb : -1;
28
    var used = memoryUsage.used / mb;
29
    var percent = used * 100 / max;
30
    var recommendedMB = recommended / mb;
31
    var html = '';
32

    
33
    html += '<span class="memory-usage">';
34
    html += label + '(' + used 
35
    if(recommendedMB > 0){
36
        html += ' of '  + max+ ' MB, recommended: '  + recommendedMB 
37
    }
38
    html += ' MB)&nbsp;';
39
    html += '<div style="height: 100%; width:' + barWidth + ';background-color:' + cssColorMax + '">';
40
    html += '<div style="background-color:' + cssColorUsed + '; width:' + percent + '%">&nbsp;</div></div></span>';
41

    
42
    return html;
43
  }
44

    
45
  updateMemoryStatus()
46

    
47
});
(4-4/6)