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

View File

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

View File

@ -1,83 +1,74 @@
<template> <template>
<el-drawer <DrawerPro v-model="open" :header="$t('website.group')" size="large" :back="handleClose">
:close-on-click-modal="false" <template #content>
v-model="open" <ComplexTable :data="data" @search="search()">
size="50%" <template #leftToolBar>
:close-on-press-escape="false" <el-button type="primary" @click="openCreate">{{ $t('website.createGroup') }}</el-button>
:before-close="handleClose" </template>
> <el-table-column :label="$t('commons.table.name')" prop="name">
<template #header> <template #default="{ row }">
<Header :header="$t('website.group')" :back="handleClose"></Header> <div v-if="!row.edit">
<span v-if="row.name === 'default'">
{{ $t('commons.table.default') }}
</span>
<span v-if="row.name !== 'default'">{{ row.name }}</span>
<el-tag v-if="row.isDefault" type="success" class="ml-2" size="small">
({{ $t('commons.table.default') }})
</el-tag>
<el-tag type="warning" size="small" class="ml-4" v-if="row.isDelete">
{{ $t('app.takeDown') }}
</el-tag>
</div>
<el-form @submit.prevent ref="groupForm" v-if="row.edit" :model="row">
<el-form-item prop="name" v-if="row.edit" :rules="Rules.name">
<div style="margin-top: 20px; width: 100%"><el-input v-model="row.name" /></div>
</el-form-item>
</el-form>
</template>
</el-table-column>
<el-table-column :label="$t('commons.table.operate')">
<template #default="{ row, $index }">
<div>
<el-button link v-if="row.edit" type="primary" @click="saveGroup(groupForm, row)">
{{ $t('commons.button.save') }}
</el-button>
<el-button link v-if="!row.edit" type="primary" @click="editGroup($index)">
{{ $t('commons.button.edit') }}
</el-button>
<el-button
link
v-if="!row.edit"
:disabled="row.isDefault"
type="primary"
@click="deleteGroup($index)"
>
{{ $t('commons.button.delete') }}
</el-button>
<el-button link v-if="row.edit" type="primary" @click="search()">
{{ $t('commons.button.cancel') }}
</el-button>
<el-button
link
v-if="!row.edit && !row.isDefault && !row.isDelete"
type="primary"
@click="setDefault(row)"
>
{{ $t('website.setDefault') }}
</el-button>
</div>
</template>
</el-table-column>
</ComplexTable>
</template> </template>
</DrawerPro>
<ComplexTable :data="data" @search="search()">
<template #leftToolBar>
<el-button type="primary" @click="openCreate">{{ $t('website.createGroup') }}</el-button>
</template>
<el-table-column :label="$t('commons.table.name')" prop="name">
<template #default="{ row }">
<div v-if="!row.edit">
<span v-if="row.name === 'default'">
{{ $t('commons.table.default') }}
</span>
<span v-if="row.name !== 'default'">{{ row.name }}</span>
<el-tag v-if="row.isDefault" type="success" class="ml-2" size="small">
({{ $t('commons.table.default') }})
</el-tag>
<el-tag type="warning" size="small" class="ml-4" v-if="row.isDelete">
{{ $t('app.takeDown') }}
</el-tag>
</div>
<el-form @submit.prevent ref="groupForm" v-if="row.edit" :model="row">
<el-form-item prop="name" v-if="row.edit" :rules="Rules.name">
<div style="margin-top: 20px; width: 100%"><el-input v-model="row.name" /></div>
</el-form-item>
</el-form>
</template>
</el-table-column>
<el-table-column :label="$t('commons.table.operate')">
<template #default="{ row, $index }">
<div>
<el-button link v-if="row.edit" type="primary" @click="saveGroup(groupForm, row)">
{{ $t('commons.button.save') }}
</el-button>
<el-button link v-if="!row.edit" type="primary" @click="editGroup($index)">
{{ $t('commons.button.edit') }}
</el-button>
<el-button
link
v-if="!row.edit"
:disabled="row.isDefault"
type="primary"
@click="deleteGroup($index)"
>
{{ $t('commons.button.delete') }}
</el-button>
<el-button link v-if="row.edit" type="primary" @click="search()">
{{ $t('commons.button.cancel') }}
</el-button>
<el-button
link
v-if="!row.edit && !row.isDefault && !row.isDelete"
type="primary"
@click="setDefault(row)"
>
{{ $t('website.setDefault') }}
</el-button>
</div>
</template>
</el-table-column>
</ComplexTable>
</el-drawer>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from 'vue'; import { ref } from 'vue';
import i18n from '@/lang'; import i18n from '@/lang';
import { CreateGroup, DeleteGroup, GetGroupList, UpdateGroup } from '@/api/modules/group'; import { CreateGroup, DeleteGroup, GetGroupList, UpdateGroup } from '@/api/modules/group';
import Header from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message'; import { MsgSuccess } from '@/utils/message';
import { Group } from '@/api/interface/group'; import { Group } from '@/api/interface/group';
import { Rules } from '@/global/form-rules'; import { Rules } from '@/global/form-rules';