Statistics.vue 7.5 KB

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