Skip to content

Commit

Permalink
feat: 支持查看go内存占用
Browse files Browse the repository at this point in the history
  • Loading branch information
若海 committed Dec 5, 2023
1 parent 73dd795 commit 3752035
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 35 deletions.
11 changes: 10 additions & 1 deletion src/api/native/typings/psutil.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
export interface GoMemoryStat {
Alloc: number;
Sys: number;
HeapAlloc: number;
HeapSys: number;
LastGC: number;
NumGC: number;
}

export interface SummaryStat {
CreateAt: number
HostId: string
Expand All @@ -14,7 +23,7 @@ export interface SummaryStat {
PublicIpv4: string
PublicIpv6: string
}

export interface DetailStat extends SummaryStat {
CpuModel: string[]
NetInterface: NetInterface[]
Expand Down
4 changes: 3 additions & 1 deletion src/api/native/workhub.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient } from '@/api/basic/http';

import { SummaryStat, DetailStat, IpSets, FilerRequest, FilerResponse, ScriptPayload } from './typings';
import { GoMemoryStat, SummaryStat, DetailStat, IpSets, FilerRequest, FilerResponse, ScriptPayload } from './typings';

export class WorkhubModel extends HttpClient {
public host(): Promise<NodeDetail> {
Expand Down Expand Up @@ -37,6 +37,8 @@ export class WorkhubModel extends HttpClient {

export interface NodeDetail {
Stat: DetailStat
MemStat: GoMemoryStat
NumGoroutine: number
}

export interface WorkerOrig {
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/worker/sys_info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class WorkerSysInfo extends Vue {
</script>

<template>
<t-card v-if="session.Level == 1" title="系统信息" hover-shadow header-bordered>
<t-card title="系统信息" hover-shadow header-bordered>
<template #actions>
<t-loading v-if="loading" size="small" />
</template>
Expand Down
106 changes: 74 additions & 32 deletions src/cloud/worker/sys_load.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
import { Prop, Component, Vue } from '@/apps/basic';
import { NaApi } from '@/api';
import { DetailStat } from '@/api/native/typings';
import { NodeDetail } from '@/api/native/workhub';
import { bytesToSize, dateFormat } from '@/helper/format';
@Component
export default class WorkerSysLoad extends Vue {
public bytesToSize = bytesToSize;
public dateFormat = dateFormat;
public timer = 0;
@Prop
Expand All @@ -26,16 +31,16 @@ export default class WorkerSysLoad extends Vue {
// 获取系统信息
public stat!: DetailStat;
public data!: NodeDetail;
async getDetailStat() {
this.loading = true;
if (this.id == 'host') {
const res = await NaApi.workhub.host();
this.stat = res.Stat;
this.data = res || {};
} else if (this.id) {
const res = await NaApi.workhub.detail(this.id);
this.stat = res.Stat;
this.data = res || {};
}
this.updateConfig();
this.loading = false;
Expand All @@ -55,7 +60,7 @@ export default class WorkerSysLoad extends Vue {
};
public updateConfig() {
const stat = this.stat;
const stat = this.data.Stat;
if (stat.CpuPercent) {
this.chart.cpuPercent = Math.round(
stat.CpuPercent.reduce((a, b) => a + b, 0) / stat.CpuPercent.length
Expand Down Expand Up @@ -95,31 +100,68 @@ export default class WorkerSysLoad extends Vue {
</script>

<template>
<t-card v-if="session.Level == 1" title="系统负载" hover-shadow header-bordered>
<template #actions>
<t-loading v-if="loading" size="small" />
</template>
<t-space v-if="chart.memoryPercent" fixed break-line>
<t-progress theme="circle" size="135" :percentage="chart.cpuPercent" :color="chart.cpuColor">
<template #label>
<small>{{ chart.cpuPercent }}%<br>CPU</small>
</template>
</t-progress>
<t-progress theme="circle" size="135" :percentage="chart.memoryPercent" :color="chart.memoryColor">
<template #label>
<small>{{ chart.memoryPercent }}%<br>内存</small>
</template>
</t-progress>
<t-progress theme="circle" size="135" :percentage="chart.swapPercent" :color="chart.swapColor">
<template #label>
<small>{{ chart.swapPercent }}%<br>Swap</small>
</template>
</t-progress>
<t-progress theme="circle" size="135" :percentage="chart.diskPercent" :color="chart.diskColor">
<template #label>
<small>{{ chart.diskPercent }}%<br>硬盘</small>
</template>
</t-progress>
</t-space>
</t-card>
<t-space fixed direction="vertical">
<t-card title="系统负载" hover-shadow header-bordered>
<template #actions>
<t-loading v-if="loading" size="small" />
</template>
<t-space v-if="chart.memoryPercent" fixed break-line>
<t-progress theme="circle" size="135" :percentage="chart.cpuPercent" :color="chart.cpuColor">
<template #label>
<small>{{ chart.cpuPercent }}%<br>CPU</small>
</template>
</t-progress>
<t-progress theme="circle" size="135" :percentage="chart.memoryPercent" :color="chart.memoryColor">
<template #label>
<small>{{ chart.memoryPercent }}%<br>内存</small>
</template>
</t-progress>
<t-progress theme="circle" size="135" :percentage="chart.swapPercent" :color="chart.swapColor">
<template #label>
<small>{{ chart.swapPercent }}%<br>Swap</small>
</template>
</t-progress>
<t-progress theme="circle" size="135" :percentage="chart.diskPercent" :color="chart.diskColor">
<template #label>
<small>{{ chart.diskPercent }}%<br>硬盘</small>
</template>
</t-progress>
</t-space>
</t-card>
<t-card title="Go 内存" hover-shadow header-bordered>
<template #actions>
<t-loading v-if="loading" size="small" />
</template>
<t-list v-if="data?.MemStat" :split="true">
<t-list-item>
<b>已分配内存</b>
<span>{{ bytesToSize(data.MemStat.Alloc) }}</span>
</t-list-item>
<t-list-item>
<b>已申请内存</b>
<span>{{ bytesToSize(data.MemStat.Sys) }}</span>
</t-list-item>
<t-list-item>
<b>堆内存</b>
<span>{{ bytesToSize(data.MemStat.HeapAlloc) }}</span>
</t-list-item>
<t-list-item>
<b>堆申请内存</b>
<span>{{ bytesToSize(data.MemStat.HeapSys) }}</span>
</t-list-item>
<t-list-item>
<b>GC 总次数</b>
<span>{{ data.MemStat.NumGC }}</span>
</t-list-item>
<t-list-item>
<b>上次 GC 时间</b>
<span>{{ dateFormat(data.MemStat.LastGC * 1000, "yyyy-MM-dd hh:mm:ss") }}</span>
</t-list-item>
<t-list-item>
<b>Goroutine 数量</b>
<span>{{ data.NumGoroutine }}</span>
</t-list-item>
</t-list>
</t-card>
</t-space>
</template>

0 comments on commit 3752035

Please sign in to comment.