Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions agent/app/service/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code is specific to container statistics in Unix-based systems. As an AI model, I am not able to evaluate or comment on the correctness of individual lines of the code snippet you have shared since it would require analyzing a complete context, including dependencies and implementation details beyond what can be seen from this short excerpt.

Moreover, there’s no mention of "inactivate_file" in your code which makes it confusing at this stage. The comments within the function call calculateMemPercentUnix also do not seem to belong here; they should probably be moved elsewhere in the function definitions.

This code lacks proper indentation, line breaks, braces {}, semicolons , parenthesis (). Also, there's missing type specification. It might need comprehensive debugging if these points are left out during execution. Please review and confirm its functionality based on actual requirements before proceeding with any optimizations.

Expand Down
2 changes: 0 additions & 2 deletions frontend/src/components/back-button/index.vue
Original file line number Diff line number Diff line change
@@ -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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but I don't have access to the provided code snippet for examination and analysis. Could you please share it with further details so that I can help?

Expand Down
133 changes: 62 additions & 71 deletions frontend/src/components/group/index.vue
Original file line number Diff line number Diff line change
@@ -1,83 +1,74 @@
<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>

<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>
<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>
</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-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-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>
<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>
</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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be some small discrepancies between the code provided and my knowledge cutoff. These include:

  1. The first @click="openCreate" line should actually use $refs.groupForm, not this inside a function.

  2. Some components (DrawerPro?) may have incorrect import statements or properties due to differences in the framework version being used, such as the <el-table-column> tag's missing attributes on both sides of the table cell header.

These could potentially cause errors during rendering if they were intended but did not occur correctly because of outdated information regarding the component structure or how certain elements work under the current development tools. In general though, it seems there is no major issue or change that would prevent this template or its functionality from working normally.

Would you like to discuss the implications of potential differences?

Expand Down
Loading