stats.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <link rel="stylesheet" href="./style.css">
  6. </head>
  7. <body>
  8. <style>
  9. body {
  10. font-family: helvetica;
  11. background-color: rgb(25,25,25);
  12. color: rgb(80,135,25) !important;
  13. text-shadow: 1px 1px 20px rgb(80,150,25);
  14. }
  15. .label {
  16. position: absolute;
  17. left: 0.5em;
  18. top: 1.75em;
  19. }
  20. .input {
  21. height: 30px;
  22. padding:10px;
  23. background-color: rgb(50,50,50);
  24. color: rgb(250,50,50);
  25. }
  26. .tall { height: 5em; }
  27. </style>
  28. <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 <span class="shout" id="block">0</span> block</div>
  29. <input id="url" class="center input crack" placeholder="enter peer stats source url">
  30. <div class="center row charts">
  31. </div>
  32. <div class="model none">
  33. <div class="chart"><span class="label"></span><canvas class="tall row"></canvas></div>
  34. </div>
  35. <script src="./jquery.js"></script>
  36. <script src="./smoothie.js" charset="utf-8"></script>
  37. <script>
  38. var up, br = 0, bt = 0;
  39. var fetchData = async function(){
  40. // fetch the data from server
  41. var S = +new Date;
  42. var data = await (await fetch(url.value||(location.origin+'/gun/stats.radata'), {method: 'GET',mode: 'cors'})).json();
  43. $('#block').text(((br += (+new Date - S)/1000) / ++bt).toFixed(1));
  44. data.over = (data.over/1000) || 15;
  45. $('#peers').text(data.peers.count);
  46. $('#time').text((data.peers.time / 1000 / 60).toFixed(0));
  47. $('#nodes').text(data.node.count);
  48. $('#hours').text((data.up.time / 60 / 60).toFixed(1));
  49. if(data.up.time === up){ console.log("up same as before") } up = data.up.time;
  50. Stats('memory').line.append(+new Date, data.memory.heapTotal / 1024 / 1024);
  51. try{ Stats('dam # in/s').line.append(+new Date, Math.round(data.dam.in.count / data.over)); }catch(e){}
  52. try{ Stats('dam in MB/s').line.append(+new Date, data.dam.in.done / 1024 / 1024 / data.over); }catch(e){}
  53. try{ Stats('dam # out/s').line.append(+new Date, Math.round(data.dam.out.count / data.over)); }catch(e){}
  54. try{ Stats('dam out MB/s').line.append(+new Date, data.dam.out.done / 1024 / 1024 / data.over); }catch(e){}
  55. console.log('data',data);
  56. //fetch keys in all, these may be dynamically changing
  57. //for each key, check if we already have created a time series, if not, create it and add it
  58. // to the chart corredsponding to the unit of measure
  59. $.each(data.all, function(key, arr){
  60. var chart = Stats(key);
  61. // get data and append to line
  62. // get the arrays inside the key
  63. //for each array append the data to the line
  64. for(var i in arr) {
  65. // append data [timestamp], [data]
  66. chart.line.append(arr[i][0], arr[i][1]);
  67. }
  68. })
  69. }
  70. setInterval(fetchData, 15 * 1000);
  71. fetchData();
  72. function Stats(key, chart){
  73. // if we have already created, get data to append to it.
  74. if(chart = Stats[key]){
  75. return chart;
  76. }
  77. // create a new Series for this key
  78. // add it into the map
  79. chart = Stats[key] = new SmoothieChart({millisPerPixel:500, limitFPS: 16, responsive: true, minValue: 0, grid:{strokeStyle:'rgba(100%,100%,100%,0.2)'},labels:{fontSize:20}, grid: {verticalSections: 0, millisPerLine: 15000 * 4 /*, strokeStyle:'rgb(125, 0, 0)'*/}});
  80. chart.line = new TimeSeries();
  81. chart.addTimeSeries(chart.line,{ strokeStyle:'rgb('+Math.random()*255+', '+Math.random()*255+','+Math.random()*255+')', lineWidth:5 });
  82. chart.canvas = $('.model').find('.chart').clone(true).appendTo('.charts');
  83. chart.canvas.find('span').text(key);
  84. chart.streamTo(chart.canvas.find('canvas').get(0), 15 * 1000);
  85. chart.line.append(0, 0);
  86. // check first two characters of key to determine other charts to add this in
  87. // tbd later
  88. return chart;
  89. }
  90. /*
  91. Notes to Self about Debugging:
  92. 1. Read Disks can spike up to 1min, I suspect other operations are blocking it from resolving as fast as it otherwise would.
  93. 2. JSON parsing/stringifying sometimes way slower than other times, why?
  94. 3. Looks like RAD lex read is not optimized.
  95. 4. got prep + got emit = non-RAD problems, compare against read disk & got differentials (should be same).
  96. 5. Radix map/place ops could be slow?
  97. 6. SINGLE MESSAGE PROCESS TIME occasionally is huge, should get emailed.
  98. 7. Watch out for get/put loops times, maybe indicating (5) issues?
  99. */
  100. </script>
  101. </body>
  102. </html>