stats.html 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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</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 fetchData = async function(){
  39. // fetch the data from server
  40. var data = await (await fetch(url.value||(location.origin+'/gun/stats.radata'), {method: 'GET',mode: 'cors'})).json();
  41. $('#peers').text(data.peers.count);
  42. $('#time').text((data.peers.time / 1000 / 60).toFixed(0));
  43. $('#nodes').text(data.node.count);
  44. $('#hours').text((data.up.time / 60 / 60).toFixed(0));
  45. Stats('memory').line.append(+new Date, data.memory.heapTotal / 1024 / 1024);
  46. try{ Stats('dam # in').line.append(+new Date, data.dam.in.count); }catch(e){}
  47. try{ Stats('dam in MB').line.append(+new Date, data.dam.in.done / 1024 / 1024); }catch(e){}
  48. try{ Stats('dam # out').line.append(+new Date, data.dam.out.count); }catch(e){}
  49. try{ Stats('dam out MB').line.append(+new Date, data.dam.out.done / 1024 / 1024); }catch(e){}
  50. console.log('data',data);
  51. //fetch keys in all, these may be dynamically changing
  52. //for each key, check if we already have created a time series, if not, create it and add it
  53. // to the chart corredsponding to the unit of measure
  54. $.each(data.all, function(key, arr){
  55. var chart = Stats(key);
  56. // get data and append to line
  57. // get the arrays inside the key
  58. //for each array append the data to the line
  59. for(var i in arr) {
  60. // append data [timestamp], [data]
  61. chart.line.append(arr[i][0], arr[i][1]);
  62. }
  63. })
  64. }
  65. setInterval(fetchData, 15 * 1000);
  66. fetchData();
  67. function Stats(key, chart){
  68. // if we have already created, get data to append to it.
  69. if(chart = Stats[key]){
  70. return chart;
  71. }
  72. // create a new Series for this key
  73. // add it into the map
  74. chart = Stats[key] = new SmoothieChart({responsive: true, minValue: 0, grid:{strokeStyle:'rgba(100%,100%,100%,0.2)'},labels:{fontSize:20}});
  75. chart.line = new TimeSeries();
  76. chart.addTimeSeries(chart.line,{ strokeStyle:'rgb('+Math.random()*255+', '+Math.random()*255+','+Math.random()*255+')', lineWidth:5 });
  77. chart.canvas = $('.model').find('.chart').clone(true).appendTo('.charts');
  78. chart.canvas.find('span').text(key);
  79. chart.streamTo(chart.canvas.find('canvas').get(0), 15 * 1000);
  80. // check first two characters of key to determine other charts to add this in
  81. // tbd later
  82. return chart;
  83. }
  84. </script>
  85. </body>
  86. </html>