Statistics.vue 7.5 KB

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