1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

feat(container): Align Container Memory Usage Display with Docker Stats (#7435)

This commit is contained in:
zhengkunwang 2024-12-19 14:24:29 +08:00 committed by GitHub
parent 07e4f34913
commit 7cb987434e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 69 additions and 77 deletions

View File

@ -1052,6 +1052,9 @@ func calculateCPUPercentUnix(stats *container.StatsResponse) float64 {
func calculateMemPercentUnix(memStats container.MemoryStats) float64 {
memPercent := 0.0
memUsage := float64(memStats.Usage)
if memStats.Stats["inactive_file"] > 0 {
memUsage = memUsage - float64(memStats.Stats["inactive_file"])
}
memLimit := float64(memStats.Limit)
if memUsage > 0.0 && memLimit > 0.0 {
memPercent = (memUsage / memLimit) * 100.0
@ -1162,8 +1165,8 @@ func loadCpuAndMem(client *client.Client, containerItem string) dto.ContainerLis
data.CPUPercent = calculateCPUPercentUnix(stats)
data.PercpuUsage = len(stats.CPUStats.CPUUsage.PercpuUsage)
data.MemoryCache = stats.MemoryStats.Stats["cache"]
data.MemoryUsage = stats.MemoryStats.Usage
data.MemoryCache = stats.MemoryStats.Stats["inactive_file"]
data.MemoryUsage = stats.MemoryStats.Usage - data.MemoryCache
data.MemoryLimit = stats.MemoryStats.Limit
data.MemoryPercent = calculateMemPercentUnix(stats.MemoryStats)

View File

@ -1,8 +1,6 @@
<template>
<el-page-header :content="header" @back="jump">
<template v-if="slots.buttons" #content>
<!-- <span>{{ header }}</span> -->
<!-- <el-divider direction="vertical" /> -->
<slot name="buttons"></slot>
</template>
</el-page-header>

View File

@ -1,15 +1,6 @@
<template>
<el-drawer
:close-on-click-modal="false"
v-model="open"
size="50%"
:close-on-press-escape="false"
:before-close="handleClose"
>
<template #header>
<Header :header="$t('website.group')" :back="handleClose"></Header>
</template>
<DrawerPro v-model="open" :header="$t('website.group')" size="large" :back="handleClose">
<template #content>
<ComplexTable :data="data" @search="search()">
<template #leftToolBar>
<el-button type="primary" @click="openCreate">{{ $t('website.createGroup') }}</el-button>
@ -71,13 +62,13 @@
</template>
</el-table-column>
</ComplexTable>
</el-drawer>
</template>
</DrawerPro>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import i18n from '@/lang';
import { CreateGroup, DeleteGroup, GetGroupList, UpdateGroup } from '@/api/modules/group';
import Header from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message';
import { Group } from '@/api/interface/group';
import { Rules } from '@/global/form-rules';