stats.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <link rel="stylesheet" type="text/css" href="./style.css">
  6. </head>
  7. <body>
  8. <style>
  9. @import url('https://fonts.googleapis.com/css?family=Oxygen');
  10. html, body {
  11. font-family: "Oxygen", sans-serif;
  12. }
  13. svg, .ct-chart * {
  14. overflow: visible;
  15. }
  16. .ct-series-a .ct-line,
  17. .ct-series-a .ct-point {
  18. stroke: blue !important;
  19. }
  20. .ct-series-b .ct-line,
  21. .ct-series-b .ct-point {
  22. stroke: green !important;
  23. }
  24. .tall { height: 10em; }
  25. </style>
  26. <input id="url" class="center none" placeholder="enter peer stats source url">
  27. <div class="center"><span class="shout" id="peers">0</span> peers <span class="shout" id="time">0</span> min <span class="shout" id="nodes">0</span> nodes <span class="shout" id="hours">0</span> hours</div>
  28. <div class="leak" style="padding: 0 2em;">
  29. <div class="leak ct-mem ct-chart ct-perfect-fourth tall"></div>
  30. </div>
  31. <div class="center leak" style="padding: 0 2em;">
  32. <div class="unit col leak ct-damc ct-chart tall" style="width: 49%;"></div>
  33. <div class="unit col leak ct-damd ct-chart tall" style="width: 49%;"></div>
  34. </div>
  35. <div class="center leak" style="padding: 0 2em;">
  36. <div class="unit col leak ct-radc ct-chart tall" style="width: 49%;"></div>
  37. <div class="unit col leak ct-radt ct-chart tall" style="width: 49%;"></div>
  38. </div>
  39. <div class="center"><span id="rerr"></span></div>
  40. <div class="center leak" style="padding: 0 2em;">
  41. <div class="leak ct-cpu ct-chart ct-perfect-fourth tall"></div>
  42. </div>
  43. <script src="./jquery.js"></script>
  44. <link rel="stylesheet" href="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
  45. <script src="https://cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
  46. <script>
  47. var stats = {slide: [0,0,0,0,0], din: [0,0,0,0,0], dout: [0,0,0,0,0], dind: [0,0,0,0,0], doutd: [0,0,0,0,0], rgetc: [0,0,0,0,0], rputc: [0,0,0,0,0]};
  48. setInterval(function(){
  49. stats.show();
  50. }, 1000 * 15);
  51. stats.show = async function(data){ //$.getJSON(url.value||(location.origin+'/gun/stats.radata'), function(data){ console.log(data);
  52. data = await (await fetch(url.value||(location.origin+'/gun/stats.radata'), {method: 'GET',mode: 'cors'})).json();
  53. console.log(data);
  54. $('#peers').text(data.peers.count);
  55. $('#time').text((data.peers.time / 1000 / 60).toFixed(0));
  56. $('#nodes').text(data.node.count);
  57. $('#hours').text((data.up.time / 60 / 60).toFixed(0));
  58. $('#dinc').text(data.dam.in.count);
  59. $('#dind').text((data.dam.in.done / 1024 / 1024).toFixed(1));
  60. $('#doutc').text(data.dam.out.count);
  61. $('#doutd').text((data.dam.out.done / 1024 / 1024).toFixed(1));
  62. stats.slide.push(data.memory.heapTotal / 1024 / 1024); stats.slide = stats.slide.slice(1);
  63. new Chartist.Line('.ct-mem', {
  64. // A labels array that can contain any sort of values
  65. labels: ['-1min', '-45s', '-30s', '-15s', '0'],
  66. // Our series array that contains series objects or in this case series data arrays
  67. series: [stats.slide]
  68. }, {fullWidth: true, low: 0, axisY: {
  69. labelInterpolationFnc: function(v) { return v+'MB' }
  70. }});
  71. stats.din.push(data.dam['in'].count); stats.din = stats.din.slice(1);
  72. stats.dout.push(data.dam.out.count); stats.dout = stats.dout.slice(1);
  73. new Chartist.Line('.ct-damc', {
  74. // A labels array that can contain any sort of values
  75. labels: ['-1min', '-45s', '-30s', '-15s', '0'],
  76. // Our series array that contains series objects or in this case series data arrays
  77. series: [stats.dout, stats.din]
  78. }, {fullWidth: true, axisY: {
  79. labelInterpolationFnc: function(v) { return v+'msgs' }
  80. }});
  81. stats.dind.push(data.dam['in'].done / 1024 / 1024); stats.dind = stats.dind.slice(1);
  82. stats.doutd.push(data.dam.out.done / 1024 / 1024); stats.doutd = stats.doutd.slice(1);
  83. new Chartist.Line('.ct-damd', {
  84. // A labels array that can contain any sort of values
  85. labels: ['-1min', '-45s', '-30s', '-15s', '0'],
  86. // Our series array that contains series objects or in this case series data arrays
  87. series: [stats.doutd, stats.dind]
  88. }, {fullWidth: true, axisY: {
  89. labelInterpolationFnc: function(v) { return v+'MB' }
  90. }});
  91. try{ $('#rerr').text(data.rad.put.err || data.rad.get.err) }catch(e){}
  92. try{
  93. stats.rgetc.push(data.rad.get.count); stats.rgetc = stats.rgetc.slice(1);
  94. stats.rputc.push(data.rad.put.count); stats.rputc = stats.rputc.slice(1);
  95. new Chartist.Line('.ct-radc', {
  96. // A labels array that can contain any sort of values
  97. labels: ['-1min', '-45s', '-30s', '-15s', '0'],
  98. // Our series array that contains series objects or in this case series data arrays
  99. series: [stats.rputc, stats.rgetc]
  100. }, {fullWidth: true, axisY: {
  101. labelInterpolationFnc: function(v) { return v+'io' }
  102. }});
  103. }catch(e){}
  104. try{
  105. stats.radgt = Object.values(data.rad.get.time).map(function(n){ return n/1000 });
  106. stats.radpt = Object.values(data.rad.put.time).map(function(n){ return n/1000 });
  107. new Chartist.Line('.ct-radt', {
  108. // A labels array that can contain any sort of values
  109. //labels: ['-1min', '-45s', '-30s', '-15s', '0'],
  110. // Our series array that contains series objects or in this case series data arrays
  111. series: [stats.radpt, stats.radgt]
  112. }, {fullWidth: true, axisY: {
  113. labelInterpolationFnc: function(v) { return v+'sec' }
  114. }});
  115. }catch(e){}
  116. new Chartist.Line('.ct-cpu', {
  117. // A labels array that can contain any sort of values
  118. labels: ['-15min', '-5min', '1min'],
  119. // Our series array that contains series objects or in this case series data arrays
  120. series: [data.cpu.loadavg.reverse()]
  121. }, {fullWidth: true, low: 0, axisY: {
  122. labelInterpolationFnc: function(v) { return v+'cpu' }
  123. }});
  124. //})
  125. }
  126. stats.show();
  127. </script>
  128. </body>
  129. </html>