Statistics.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <div class='container'>
  3. <div class="columns">
  4. <div class='card column is-10-desktop is-offset-1-desktop is-12-mobile'>
  5. <header class='card-header'>
  6. <p class='card-header-title'>
  7. Average Logs
  8. </p>
  9. </header>
  10. <div class='card-content'>
  11. <div class='content'>
  12. <table class="table">
  13. <thead>
  14. <tr>
  15. <th> </th>
  16. <th>Success</th>
  17. <th>Error</th>
  18. <th>Info</th>
  19. </tr>
  20. </thead>
  21. <tbody>
  22. <tr>
  23. <th><strong>Average per second</strong></th>
  24. <th v-bind:title="logs.second.success">{{round(logs.second.success)}}</th>
  25. <th v-bind:title="logs.second.error">{{round(logs.second.error)}}</th>
  26. <th v-bind:title="logs.second.info">{{round(logs.second.info)}}</th>
  27. </tr>
  28. <tr>
  29. <th><strong>Average per minute</strong></th>
  30. <th v-bind:title="logs.minute.success">{{round(logs.minute.success)}}</th>
  31. <th v-bind:title="logs.minute.error">{{round(logs.minute.error)}}</th>
  32. <th v-bind:title="logs.minute.info">{{round(logs.minute.info)}}</th>
  33. </tr>
  34. <tr>
  35. <th><strong>Average per hour</strong></th>
  36. <th v-bind:title="logs.hour.success">{{round(logs.hour.success)}}</th>
  37. <th v-bind:title="logs.hour.error">{{round(logs.hour.error)}}</th>
  38. <th v-bind:title="logs.hour.info">{{round(logs.hour.info)}}</th>
  39. </tr>
  40. <tr>
  41. <th><strong>Average per day</strong></th>
  42. <th v-bind:title="logs.day.success">{{round(logs.day.success)}}</th>
  43. <th v-bind:title="logs.day.error">{{round(logs.day.error)}}</th>
  44. <th v-bind:title="logs.day.info">{{round(logs.day.info)}}</th>
  45. </tr>
  46. </tbody>
  47. </table>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. <br>
  53. <div class="columns">
  54. <div class='card column is-10-desktop is-offset-1-desktop is-12-mobile'>
  55. <div class='card-content'>
  56. <div class='content'>
  57. <canvas id="minuteChart" height="400"></canvas>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. <br>
  63. <div class="columns">
  64. <div class='card column is-10-desktop is-offset-1-desktop is-12-mobile'>
  65. <div class='card-content'>
  66. <div class='content'>
  67. <canvas id="hourChart" height="400"></canvas>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import EditUser from '../Modals/EditUser.vue';
  76. import io from '../../io';
  77. import Chart from 'chart.js'
  78. export default {
  79. components: {},
  80. data() {
  81. return {
  82. successUnitsPerMinute: [0,0,0,0,0,0,0,0,0,0],
  83. errorUnitsPerMinute: [0,0,0,0,0,0,0,0,0,0],
  84. infoUnitsPerMinute: [0,0,0,0,0,0,0,0,0,0],
  85. successUnitsPerHour: [0,0,0,0,0,0,0,0,0,0],
  86. errorUnitsPerHour: [0,0,0,0,0,0,0,0,0,0],
  87. infoUnitsPerHour: [0,0,0,0,0,0,0,0,0,0],
  88. minuteChart: null,
  89. hourChart: null,
  90. logs: {
  91. second: {
  92. success: 0,
  93. error: 0,
  94. info: 0
  95. },
  96. minute: {
  97. success: 0,
  98. error: 0,
  99. info: 0
  100. },
  101. hour: {
  102. success: 0,
  103. error: 0,
  104. info: 0
  105. },
  106. day: {
  107. success: 0,
  108. error: 0,
  109. info: 0
  110. }
  111. }
  112. }
  113. },
  114. methods: {
  115. init: function () {
  116. this.socket.emit('apis.joinAdminRoom', 'statistics', () => {});
  117. this.socket.on('event:admin.statistics.success.units.minute', units => {
  118. this.successUnitsPerMinute = units;
  119. this.minuteChart.data.datasets[0].data = units;
  120. this.minuteChart.update();
  121. });
  122. this.socket.on('event:admin.statistics.error.units.minute', units => {
  123. this.errorUnitsPerMinute = units;
  124. this.minuteChart.data.datasets[1].data = units;
  125. this.minuteChart.update();
  126. });
  127. this.socket.on('event:admin.statistics.info.units.minute', units => {
  128. this.infoUnitsPerMinute = units;
  129. this.minuteChart.data.datasets[2].data = units;
  130. this.minuteChart.update();
  131. });
  132. this.socket.on('event:admin.statistics.success.units.hour', units => {
  133. this.successUnitsPerHour = units;
  134. this.hourChart.data.datasets[0].data = units;
  135. this.hourChart.update();
  136. });
  137. this.socket.on('event:admin.statistics.error.units.hour', units => {
  138. this.errorUnitsPerHour = units;
  139. this.hourChart.data.datasets[1].data = units;
  140. this.hourChart.update();
  141. });
  142. this.socket.on('event:admin.statistics.info.units.hour', units => {
  143. this.infoUnitsPerHour = units;
  144. this.hourChart.data.datasets[2].data = units;
  145. this.hourChart.update();
  146. });
  147. this.socket.on('event:admin.statistics.logs', logs => {
  148. this.logs = logs;
  149. });
  150. },
  151. round: function(number) {
  152. return Math.round(number);
  153. }
  154. },
  155. ready: function () {
  156. let _this = this;
  157. var minuteCtx = document.getElementById("minuteChart");
  158. var hourCtx = document.getElementById("hourChart");
  159. _this.minuteChart = new Chart(minuteCtx, {
  160. type: 'line',
  161. data: {
  162. labels: ["-10", "-9", "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1"],
  163. datasets: [
  164. {
  165. label: 'Success',
  166. data: [0,0,0,0,0,0,0,0,0,0],
  167. backgroundColor: [
  168. 'rgba(75, 192, 192, 0.2)'
  169. ],
  170. borderColor: [
  171. 'rgba(75, 192, 192, 1)'
  172. ],
  173. borderWidth: 1
  174. },
  175. {
  176. label: 'Error',
  177. data: [0,0,0,0,0,0,0,0,0,0],
  178. backgroundColor: [
  179. 'rgba(255, 99, 132, 0.2)'
  180. ],
  181. borderColor: [
  182. 'rgba(255,99,132,1)'
  183. ],
  184. borderWidth: 1
  185. },
  186. {
  187. label: 'Info',
  188. data: [0,0,0,0,0,0,0,0,0,0],
  189. backgroundColor: [
  190. 'rgba(54, 162, 235, 0.2)'
  191. ],
  192. borderColor: [
  193. 'rgba(54, 162, 235, 1)'
  194. ],
  195. borderWidth: 1
  196. }
  197. ]
  198. },
  199. options: {
  200. title: {
  201. display: true,
  202. text: 'Logs per minute'
  203. },
  204. scales: {
  205. yAxes: [{
  206. ticks: {
  207. beginAtZero: true,
  208. stepSize: 1
  209. }
  210. }]
  211. },
  212. responsive: true,
  213. maintainAspectRatio: false
  214. }
  215. });
  216. _this.hourChart = new Chart(hourCtx, {
  217. type: 'line',
  218. data: {
  219. labels: ["-10", "-9", "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1"],
  220. datasets: [
  221. {
  222. label: 'Success',
  223. data: [0,0,0,0,0,0,0,0,0,0],
  224. backgroundColor: [
  225. 'rgba(75, 192, 192, 0.2)'
  226. ],
  227. borderColor: [
  228. 'rgba(75, 192, 192, 1)'
  229. ],
  230. borderWidth: 1
  231. },
  232. {
  233. label: 'Error',
  234. data: [0,0,0,0,0,0,0,0,0,0],
  235. backgroundColor: [
  236. 'rgba(255, 99, 132, 0.2)'
  237. ],
  238. borderColor: [
  239. 'rgba(255,99,132,1)'
  240. ],
  241. borderWidth: 1
  242. },
  243. {
  244. label: 'Info',
  245. data: [0,0,0,0,0,0,0,0,0,0],
  246. backgroundColor: [
  247. 'rgba(54, 162, 235, 0.2)'
  248. ],
  249. borderColor: [
  250. 'rgba(54, 162, 235, 1)'
  251. ],
  252. borderWidth: 1
  253. }
  254. ]
  255. },
  256. options: {
  257. title: {
  258. display: true,
  259. text: 'Logs per hour'
  260. },
  261. scales: {
  262. yAxes: [{
  263. ticks: {
  264. beginAtZero: true,
  265. stepSize: 1
  266. }
  267. }]
  268. },
  269. responsive: true,
  270. maintainAspectRatio: false
  271. }
  272. });
  273. io.getSocket(socket => {
  274. _this.socket = socket;
  275. if (_this.socket.connected) _this.init();
  276. io.onConnect(() => _this.init());
  277. });
  278. }
  279. }
  280. </script>
  281. <style lang='scss' scoped>
  282. body { font-family: 'Roboto', sans-serif; }
  283. .user-avatar {
  284. display: block;
  285. max-width: 50px;
  286. margin: 0 auto;
  287. }
  288. td { vertical-align: middle; }
  289. .is-primary:focus { background-color: #029ce3 !important; }
  290. </style>