Statistics.vue 7.9 KB

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