uptime.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!-- css override -->
  2. <style>
  3. #utm{
  4. background-color: white;
  5. border-radius: 1em;
  6. }
  7. .domain{
  8. margin-bottom: 1em;
  9. position: relative;
  10. }
  11. .statusDot{
  12. height: 1.8em;
  13. border-radius: 0.4em;
  14. width: 0.4em;
  15. background-color: #e8e8e8;
  16. display:inline-block;
  17. cursor: pointer;
  18. margin-left: 0.1em;
  19. }
  20. .online.statusDot{
  21. background-color: #3bd671;
  22. }
  23. .error.statusDot{
  24. background-color: #f29030;
  25. }
  26. .offline.statusDot{
  27. background-color: #df484a;
  28. }
  29. .padding.statusDot{
  30. cursor: auto;
  31. }
  32. </style>
  33. <div id="utm" class="ui basic segment">
  34. <div class="ui basic segment">
  35. <h4 class="ui header">
  36. <i class="red remove icon"></i>
  37. <div class="content">
  38. Uptime Monitoring service is currently unavailable
  39. <div class="sub header">This might cause by an error in cluster communication within the host servers. Please wait for administrator to resolve the issue.</div>
  40. </div>
  41. </h4>
  42. </div>
  43. </div>
  44. <script>
  45. AOS.init();
  46. function initUptimeTable(){
  47. }
  48. let records = JSON.parse(`<?php echo file_get_contents("http://localhost:8089/")?>`);
  49. renderRecords(records);
  50. //For every 5 minutes
  51. setInterval(function(){
  52. $.get("api.php?token=fbda065b-3662-415b-af4d-41cb998e619d", function(data){
  53. console.log("Status Updated");
  54. records = data;
  55. renderRecords();
  56. });
  57. }, (300 * 1000));
  58. function renderRecords(){
  59. $("#utm").html("");
  60. for (let [key, value] of Object.entries(records)) {
  61. renderUptimeData(key, value);
  62. }
  63. }
  64. function format_time(s) {
  65. const date = new Date(s * 1e3);
  66. return(date.toLocaleString());
  67. }
  68. function renderUptimeData(key, value){
  69. if (value.length == 0){
  70. return
  71. }
  72. let id = value[0].ID;
  73. let name = value[0].Name;
  74. let url = value[0].URL;
  75. let protocol = value[0].Protocol;
  76. //Generate the status dot
  77. let statusDotList = ``;
  78. for(var i = 0; i < (288 - value.length); i++){
  79. //Padding
  80. statusDotList += `<div class="padding statusDot"></div>`
  81. }
  82. let ontimeRate = 0;
  83. for (var i = 0; i < value.length; i++){
  84. //Render status to html
  85. let thisStatus = value[i];
  86. let dotType = "";
  87. if (thisStatus.Online){
  88. if (thisStatus.StatusCode < 200 || thisStatus.StatusCode >= 300){
  89. dotType = "error";
  90. }else{
  91. dotType = "online";
  92. }
  93. ontimeRate++;
  94. }else{
  95. dotType = "offline";
  96. }
  97. let datetime = format_time(thisStatus.Timestamp);
  98. statusDotList += `<div title="${datetime}" class="${dotType} statusDot"></div>`
  99. }
  100. ontimeRate = ontimeRate / value.length * 100;
  101. let ontimeColor = "#df484a"
  102. if (ontimeRate > 0.8){
  103. ontimeColor = "#3bd671";
  104. }else if(ontimeRate > 0.5) {
  105. ontimeColor = "#f29030";
  106. }
  107. //Check of online status now
  108. let currentOnlineStatus = "Unknown";
  109. let onlineStatusCss = ``;
  110. if (value[value.length - 1].Online){
  111. currentOnlineStatus = `<i class="circle icon"></i> Online`;
  112. onlineStatusCss = `color: #3bd671;`;
  113. }else{
  114. currentOnlineStatus = `<i class="circle icon"></i> Offline`;
  115. onlineStatusCss = `color: #df484a;`;
  116. }
  117. //Generate the html
  118. $("#utm").append(`<div class="ui basic segment statusbar">
  119. <div class="domain">
  120. <div style="position: absolute; top: 0; right: 0.4em;">
  121. <p class="onlineStatus" style="display: inline-block; font-size: 1.3em; padding-right: 0.5em; padding-left: 0.3em; ${onlineStatusCss}">${currentOnlineStatus}</p>
  122. </div>
  123. <div>
  124. <h3 class="ui header" style="margin-bottom: 0.2em;">${name}</h3>
  125. <a href="${url}" target="_blank">${url}</a> | <span style="color: ${ontimeColor};">${(ontimeRate).toFixed(2)}%<span>
  126. </div>
  127. <div class="ui basic label protocol" style="position: absolute; bottom: 0; right: 0.2em; margin-bottom: -0.6em;">
  128. proto: ${protocol}
  129. </div>
  130. </div>
  131. <div class="status" style="marign-top: 1em;">
  132. ${statusDotList}
  133. </div>
  134. <div class="ui divider"></div>
  135. </div>`);
  136. }
  137. </script>