From c5f096b66ae0e3f3498b0dcd61652ce3f86415cb Mon Sep 17 00:00:00 2001 From: zyxkad Date: Mon, 18 Dec 2023 10:40:20 -0700 Subject: [PATCH] add UA stat --- dashboard/src/api/v0.ts | 1 + dashboard/src/assets/lang/en-US.json | 3 +- dashboard/src/assets/lang/zh-CN.json | 3 +- dashboard/src/components/HitsChart.vue | 6 +- dashboard/src/components/UAChart.vue | 123 ++++++++++++++++++ dashboard/src/views/HomeView.vue | 168 ++++++++++++++++--------- handler.go | 40 +++++- stat.go | 38 +++--- 8 files changed, 293 insertions(+), 89 deletions(-) create mode 100644 dashboard/src/components/UAChart.vue diff --git a/dashboard/src/api/v0.ts b/dashboard/src/api/v0.ts index 1d4ffec3..9e2ff7b7 100644 --- a/dashboard/src/api/v0.ts +++ b/dashboard/src/api/v0.ts @@ -26,4 +26,5 @@ export interface APIStatus { startAt: string stats: Stats enabled: boolean + accesses: { [ua: string]: number } } diff --git a/dashboard/src/assets/lang/en-US.json b/dashboard/src/assets/lang/en-US.json index 24d21a7c..1f825be5 100644 --- a/dashboard/src/assets/lang/en-US.json +++ b/dashboard/src/assets/lang/en-US.json @@ -7,7 +7,8 @@ "year": "Year requests", "total": "Total requests", "hits": "Hits", - "bytes": "Bytes" + "bytes": "Bytes", + "user_agents": "Common User Agents" }, "message": { "server": { diff --git a/dashboard/src/assets/lang/zh-CN.json b/dashboard/src/assets/lang/zh-CN.json index 8b08710c..660f097f 100644 --- a/dashboard/src/assets/lang/zh-CN.json +++ b/dashboard/src/assets/lang/zh-CN.json @@ -7,7 +7,8 @@ "year": "当年请求", "total": "全部请求", "hits": "请求数", - "bytes": "流量" + "bytes": "流量", + "user_agents": "常见用户代理" }, "message": { "server": { diff --git a/dashboard/src/components/HitsChart.vue b/dashboard/src/components/HitsChart.vue index 1f883c90..4cc7c055 100644 --- a/dashboard/src/components/HitsChart.vue +++ b/dashboard/src/components/HitsChart.vue @@ -6,8 +6,6 @@ import type { StatInstData } from '@/api/v0' import { tr } from '@/lang' const props = defineProps<{ - width?: number | string - height?: number | string max: number offset: number data: StatInstData[] @@ -93,7 +91,6 @@ const getChartOptions = () => { return { stacked: false, maintainAspectRatio: false, - aspectRatio: 0.4, interaction: { mode: 'index', intersect: false, @@ -138,6 +135,7 @@ const getChartOptions = () => { y: { type: 'linear', display: true, + beginAtZero: true, position: 'left', ticks: { color: textColorSecondary, @@ -150,6 +148,7 @@ const getChartOptions = () => { y1: { type: 'linear', display: true, + beginAtZero: true, position: 'right', ticks: { color: textColorSecondary, @@ -176,6 +175,5 @@ onMounted(() => { type="line" :data="chartData" :options="chartOptions" - :style="{ height: height, width: width }" /> diff --git a/dashboard/src/components/UAChart.vue b/dashboard/src/components/UAChart.vue new file mode 100644 index 00000000..64f3c0be --- /dev/null +++ b/dashboard/src/components/UAChart.vue @@ -0,0 +1,123 @@ + + + \ No newline at end of file diff --git a/dashboard/src/views/HomeView.vue b/dashboard/src/views/HomeView.vue index 95f3eff4..ddb2d710 100644 --- a/dashboard/src/views/HomeView.vue +++ b/dashboard/src/views/HomeView.vue @@ -2,11 +2,13 @@ import { onMounted, ref, computed } from 'vue' import { useRequest } from 'vue-request' import axios from 'axios' +import Button from 'primevue/button' +import Chart from 'primevue/chart' import ProgressSpinner from 'primevue/progressspinner' import Skeleton from 'primevue/skeleton' -import Button from 'primevue/button' import { formatNumber, formatBytes, formatTime } from '@/utils' import HitsChart from '@/components/HitsChart.vue' +import UAChart from '@/components/UAChart.vue' import type { StatInstData, APIStatus } from '@/api/v0' import { tr } from '@/lang' @@ -95,72 +97,97 @@ function getDaysInMonth(): number {