summaryrefslogtreecommitdiff
path: root/src/viz/stats.html
blob: e60e9549954f158a2444e1202db03dab0a50f229 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="/viz/jquery-2.1.1.min.js"></script>
<style>
.updateError {
  background-color: #e30;
}
</style>
</head>
<body>
<table id="statstable">
<tr><td>LastUpdate</td><td id="LastUpdate"></td></tr>
<tr><td>ClientCount</td><td id="ClientCount"></td></tr>
<tr><td>HubCount</td><td id="HubCount"></td></tr>
<tr><td>SourcesCount</td><td id="SourcesCount"></td></tr>
<tr><td>UpdateCount</td><td id="UpdateCount"></td></tr>
<tr><td>BytesSent</td><td id="BytesSent"></td></tr>
<tr><td>BytesReceived</td><td id="BytesReceived"></td></tr>
<tr><td>StartTime</td><td id="StartTime"></td></tr>
<tr><td>LastStartTime</td><td id="LastStartTime"></td></tr>
<tr><td>Message</td><td id="message"></td></tr>
</table>
<script type="text/javascript">
var s5stats = {
  lastUpdate: ""
}

s5stats.pad = function (number) {
  if ( number < 10 ) {
    return '0' + number;
  }
  return number;
}

s5stats.toQueryIsoData = function(dateStr) {
  ts = new Date(dateStr)
  ts.setTime(ts.getTime() + 1 * 1000) // add a second, lowest resolution step for s5
  return ts.toISOString();
}

s5stats.updateStats = function() {
  var queryStr = "";
  if (s5stats.lastUpdate == "" && $("#LastStartTime").text() != "") {
      s5stats.lastUpdate = $("#LastStartTime").text()
  }
  if (s5stats.lastUpdate != "") {
    queryStr = "?from=" + s5stats.toQueryIsoData(s5stats.lastUpdate);
  }

  $.getJSON("/stats" + queryStr, function(data) {
      $("#ClientCount").text(data.ClientCount);
      $("#HubCount").text(data.HubCount);
      $("#SourcesCount").text(data.SourcesCount);
      $("#UpdateCount").text(data.UpdateCount);
      $("#BytesSent").text(data.BytesSent);
      $("#BytesReceived").text(data.BytesReceived);
      $("#StartTime").text(data.StartTime);
      $("#LastStartTime").text(data.LastStartTime);
      if (data.UpdateCount > 0) {
        s5stats.lastUpdate = data.LastStartTime;
        $("#LastUpdate").text(s5stats.lastUpdate)
      }
      $("#statstable").removeClass("updateError");
      $("#message").text("");
      })
  .fail(function() {
     $("#statstable").addClass("updateError");
     $("#message").text("No connection to Hub!");
  });

  setTimeout("s5stats.updateStats()", 5000)
}

$(document).ready(function()
    {
      s5stats.updateStats();
    });
</script>
</body>
</html>