Skip to content

Commit d6b68b8

Browse files
committed
enhance: analytic init and reactive style
1 parent 38aa1d8 commit d6b68b8

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed

frontend/src/layouts/BaseLayout.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function getClientWidth() {
2323
}
2424
2525
function collapse() {
26-
return getClientWidth() < 768
26+
return getClientWidth() < 1280
2727
}
2828
2929
const lang = computed(() => {

frontend/src/views/dashboard/DashBoard.vue

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ onMounted(() => {
4444
Object.assign(memory, r.memory)
4545
Object.assign(disk, r.disk)
4646
47+
// uptime
48+
handle_uptime(r.host?.uptime)
49+
// load_avg
50+
Object.assign(loadavg, r.loadavg)
51+
4752
net.last_recv = r.network.init.bytesRecv
4853
net.last_sent = r.network.init.bytesSent
4954
r.cpu.user.forEach((u: Usage) => {
@@ -71,6 +76,16 @@ onUnmounted(() => {
7176
websocket.close()
7277
})
7378
79+
function handle_uptime(t: number) {
80+
// uptime
81+
let _uptime = Math.floor(t)
82+
let uptime_days = Math.floor(_uptime / 86400)
83+
_uptime -= uptime_days * 86400
84+
let uptime_hours = Math.floor(_uptime / 3600)
85+
_uptime -= uptime_hours * 3600
86+
uptime.value = uptime_days + 'd ' + uptime_hours + 'h ' + Math.floor(_uptime / 60) + 'm'
87+
}
88+
7489
function wsOnMessage(m: { data: any }) {
7590
const r = JSON.parse(m.data)
7691
@@ -96,12 +111,7 @@ function wsOnMessage(m: { data: any }) {
96111
disk_io.reads = r.disk.reads.y
97112
98113
// uptime
99-
let _uptime = Math.floor(r.uptime)
100-
let uptime_days = Math.floor(_uptime / 86400)
101-
_uptime -= uptime_days * 86400
102-
let uptime_hours = Math.floor(_uptime / 3600)
103-
_uptime -= uptime_hours * 3600
104-
uptime.value = uptime_days + 'd ' + uptime_hours + 'h ' + Math.floor(_uptime / 60) + 'm'
114+
handle_uptime(r.uptime)
105115
106116
// loadavg
107117
Object.assign(loadavg, r.loadavg)
@@ -142,19 +152,21 @@ function wsOnMessage(m: { data: any }) {
142152
</p>
143153
<p>
144154
<translate>Load Averages:</translate>
145-
1min:{{ loadavg?.load1?.toFixed(2) }} |
146-
5min:{{ loadavg?.load5?.toFixed(2) }} |
147-
15min:{{ loadavg?.load15?.toFixed(2) }}
155+
<span class="load-avg-describe"> 1min:</span>{{ ' ' + loadavg?.load1?.toFixed(2) }}
156+
<span class="load-avg-describe"> | 5min:</span>{{ loadavg?.load5?.toFixed(2) }}
157+
<span class="load-avg-describe"> | 15min:</span>{{ loadavg?.load15?.toFixed(2) }}
148158
</p>
149159
<p>
150160
<translate>OS:</translate>
151-
{{ host.platform }} ({{ host.platformVersion }}
152-
{{ host.os }} {{ host.kernelVersion }}
153-
{{ host.kernelArch }})
161+
<span class="os-platform">{{ ' ' + host.platform }}</span> {{ host.platformVersion }}
162+
<span class="os-info">({{ host.os }} {{ host.kernelVersion }}
163+
{{ host.kernelArch }})</span>
154164
</p>
155165
<p v-if="cpu_info">
156-
<translate>CPU:</translate>
157-
{{ cpu_info[0]?.modelName }} * {{ cpu_info.length }}
166+
{{ $gettext('CPU:') + ' ' }}
167+
<span class="cpu-model">{{ cpu_info[0]?.modelName }}</span>
168+
<span class="cpu-mhz">{{ (cpu_info[0]?.mhz / 1000).toFixed(2) + 'GHz' }}</span>
169+
* {{ cpu_info.length }}
158170
</p>
159171
</a-card>
160172
</a-col>
@@ -177,7 +189,7 @@ function wsOnMessage(m: { data: any }) {
177189
</a-row>
178190
</a-card>
179191
</a-col>
180-
<a-col :xl="7" :lg="8" :sm="24" :xs="24" class="chart_dashboard">
192+
<a-col :xl="7" :lg="8" :sm="24" :xs="24" class="chart_dashboard network-total">
181193
<a-card :title="$gettext('Network Statistics')" :bordered="false">
182194
<a-row :gutter="16">
183195
<a-col :span="12">
@@ -266,7 +278,7 @@ function wsOnMessage(m: { data: any }) {
266278
267279
.ant-card {
268280
.ant-statistic {
269-
margin: 0 50px 10px 10px
281+
margin: 0 0 10px 10px
270282
}
271283
272284
.chart {
@@ -290,5 +302,33 @@ function wsOnMessage(m: { data: any }) {
290302
}
291303
}
292304
}
305+
306+
.os-platform {
307+
text-transform: capitalize;
308+
}
309+
310+
.load-avg-describe {
311+
@media (max-width: 1600px) and (min-width: 1200px) {
312+
display: none;
313+
}
314+
}
315+
316+
.os-info {
317+
@media (max-width: 1600px) and (min-width: 1200px) {
318+
display: none;
319+
}
320+
}
321+
322+
.cpu-model {
323+
@media (max-width: 1790px) and (min-width: 1200px) {
324+
display: none;
325+
}
326+
}
327+
328+
.cpu-mhz {
329+
@media (min-width: 1790px) or (max-width: 1200px) {
330+
display: none;
331+
}
332+
}
293333
</style>
294334

server/api/analytic.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ func GetAnalyticInit(c *gin.Context) {
183183
}
184184
hostInfo, _ := host.Info()
185185

186+
loadAvg, _ := load.Avg()
187+
186188
c.JSON(http.StatusOK, gin.H{
187189
"host": hostInfo,
188190
"cpu": gin.H{
@@ -199,7 +201,8 @@ func GetAnalyticInit(c *gin.Context) {
199201
"writes": analytic.DiskWriteRecord,
200202
"reads": analytic.DiskReadRecord,
201203
},
202-
"memory": memory,
203-
"disk": diskStat,
204+
"memory": memory,
205+
"disk": diskStat,
206+
"loadavg": loadAvg,
204207
})
205208
}

0 commit comments

Comments
 (0)