1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-28 11:04:14 +08:00

fix: Fix the monitoring data exception (#8028)

This commit is contained in:
ssongliu 2025-02-27 17:51:09 +08:00 committed by GitHub
parent 3de37a7cba
commit 36c5e648e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 131 additions and 27 deletions

View File

@ -1,7 +1,6 @@
package dto
type SettingInfo struct {
SystemIP string `json:"systemIP"`
DockerSockPath string `json:"dockerSockPath"`
SystemVersion string `json:"systemVersion"`

View File

@ -28,7 +28,7 @@ func NewIMonitorRepo() IMonitorRepo {
func (u *MonitorRepo) GetBase(opts ...DBOption) ([]model.MonitorBase, error) {
var data []model.MonitorBase
db := global.DB
db := global.MonitorDB
for _, opt := range opts {
db = opt(db)
}
@ -37,7 +37,7 @@ func (u *MonitorRepo) GetBase(opts ...DBOption) ([]model.MonitorBase, error) {
}
func (u *MonitorRepo) GetIO(opts ...DBOption) ([]model.MonitorIO, error) {
var data []model.MonitorIO
db := global.DB
db := global.MonitorDB
for _, opt := range opts {
db = opt(db)
}
@ -46,7 +46,7 @@ func (u *MonitorRepo) GetIO(opts ...DBOption) ([]model.MonitorIO, error) {
}
func (u *MonitorRepo) GetNetwork(opts ...DBOption) ([]model.MonitorNetwork, error) {
var data []model.MonitorNetwork
db := global.DB
db := global.MonitorDB
for _, opt := range opts {
db = opt(db)
}

View File

@ -9,6 +9,7 @@ import (
"github.com/1Panel-dev/1Panel/agent/app/repo"
"github.com/1Panel-dev/1Panel/agent/buserr"
"github.com/1Panel-dev/1Panel/agent/constant"
"github.com/1Panel-dev/1Panel/agent/app/dto"
"github.com/1Panel-dev/1Panel/agent/app/model"
@ -82,7 +83,7 @@ func (m *MonitorService) LoadMonitorData(req dto.MonitorSearch) ([]dto.MonitorDa
data = append(data, itemData)
}
if req.Param == "all" || req.Param == "network" {
bases, err := monitorRepo.GetIO(repo.WithByName(req.Info), repo.WithByCreatedAt(req.StartTime, req.EndTime))
bases, err := monitorRepo.GetNetwork(repo.WithByName(req.Info), repo.WithByCreatedAt(req.StartTime, req.EndTime))
if err != nil {
return nil, err
}
@ -119,6 +120,33 @@ func (m *MonitorService) LoadSetting() (*dto.MonitorSetting, error) {
}
func (m *MonitorService) UpdateSetting(key, value string) error {
switch key {
case "MonitorStatus":
if value == constant.StatusEnable && global.MonitorCronID == 0 {
interval, err := settingRepo.Get(settingRepo.WithByKey("MonitorInterval"))
if err != nil {
return err
}
if err := StartMonitor(false, interval.Value); err != nil {
return err
}
}
if value == constant.StatusDisable && global.MonitorCronID != 0 {
monitorCancel()
global.Cron.Remove(cron.EntryID(global.MonitorCronID))
global.MonitorCronID = 0
}
case "MonitorInterval":
status, err := settingRepo.Get(settingRepo.WithByKey("MonitorStatus"))
if err != nil {
return err
}
if status.Value == constant.StatusEnable && global.MonitorCronID != 0 {
if err := StartMonitor(true, value); err != nil {
return err
}
}
}
return settingRepo.Update(key, value)
}

View File

@ -247,7 +247,6 @@ func loadDbConn(snap *snapHelper, targetDir string, req dto.SnapshotCreate) erro
}
}
_ = snap.snapAgentDB.Model(&model.Setting{}).Where("key = ?", "SystemIP").Updates(map[string]interface{}{"value": ""}).Error
_ = snap.snapAgentDB.Where("id = ?", snap.SnapID).Delete(&model.Snapshot{}).Error
return nil

View File

@ -28,7 +28,7 @@ func Run() {
if err := global.DB.Where("key = ?", "MonitorStatus").Find(&status).Error; err != nil {
global.LOG.Errorf("load monitor status from db failed, err: %v", err)
}
if status.Value == "enable" {
if status.Value == "Enable" {
if err := global.DB.Where("key = ?", "MonitorInterval").Find(&interval).Error; err != nil {
global.LOG.Errorf("load monitor interval from db failed, err: %v", err)
}

View File

@ -25,6 +25,7 @@ func InitAgentDB() {
migrations.UpdateAppTag,
migrations.UpdateApp,
migrations.AddOllamaModel,
migrations.UpdateSettingStatus,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)

View File

@ -104,9 +104,6 @@ var InitSetting = &gormigrate.Migration{
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: global.CONF.Base.EncryptKey}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "DockerSockPath", Value: "unix:///var/run/docker.sock"}).Error; err != nil {
return err
}
@ -275,3 +272,16 @@ var AddOllamaModel = &gormigrate.Migration{
return nil
},
}
var UpdateSettingStatus = &gormigrate.Migration{
ID: "20250227-update-setting-status",
Migrate: func(tx *gorm.DB) error {
if err := tx.Model(model.Setting{}).Where("value = ?", "enable").Update("value", constant.StatusEnable).Error; err != nil {
return err
}
if err := tx.Model(model.Setting{}).Where("value = ?", "disable").Update("value", constant.StatusDisable).Error; err != nil {
return err
}
return nil
},
}

View File

@ -15,6 +15,7 @@ type SettingInfo struct {
Theme string `json:"theme"`
MenuTabs string `json:"menuTabs"`
Language string `json:"language"`
SystemIP string `json:"systemIP"`
ServerPort string `json:"serverPort"`
SSL string `json:"ssl"`

View File

@ -22,6 +22,7 @@ func Init() {
migrations.RemoveLocalBackup,
migrations.AddMFAInterval,
migrations.UpdateXpackHideMemu,
migrations.AddSystemIP,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)

View File

@ -318,3 +318,13 @@ var UpdateXpackHideMemu = &gormigrate.Migration{
return nil
},
}
var AddSystemIP = &gormigrate.Migration{
ID: "20250227-add-system-ip",
Migrate: func(tx *gorm.DB) error {
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
return err
}
return nil
},
}

View File

@ -70,6 +70,8 @@ import i18n from '@/lang';
import { ElForm } from 'element-plus';
import { getSettingInfo } from '@/api/modules/setting';
import { getBindDomain } from '@/api/modules/ai';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();
const loading = ref(false);
@ -104,6 +106,10 @@ const handleClose = () => {
};
const loadSystemIP = async () => {
if (globalStore.currentNode !== 'local') {
form.systemIP = globalStore.currentNode || i18n.global.t('database.localIP');
return;
}
const res = await getSettingInfo();
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
};

View File

@ -113,6 +113,8 @@ import { getAppConnInfo } from '@/api/modules/app';
import { MsgSuccess } from '@/utils/message';
import { getRandomStr } from '@/utils/util';
import { getSettingInfo } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();
const loading = ref(false);
@ -179,6 +181,10 @@ const loadAccess = async () => {
};
const loadSystemIP = async () => {
if (globalStore.currentNode !== 'local') {
form.systemIP = globalStore.currentNode || i18n.global.t('database.localIP');
return;
}
const res = await getSettingInfo();
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
};

View File

@ -115,6 +115,8 @@ import { getAppConnInfo } from '@/api/modules/app';
import { MsgSuccess } from '@/utils/message';
import { getRandomStr } from '@/utils/util';
import { getSettingInfo } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();
const loading = ref(false);
@ -179,6 +181,10 @@ const loadAccess = async () => {
};
const loadSystemIP = async () => {
if (globalStore.currentNode !== 'local') {
form.systemIP = globalStore.currentNode || i18n.global.t('database.localIP');
return;
}
const res = await getSettingInfo();
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
};

View File

@ -104,6 +104,8 @@ import { getAppConnInfo } from '@/api/modules/app';
import { MsgSuccess } from '@/utils/message';
import { getRandomStr } from '@/utils/util';
import { getSettingInfo } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();
const loading = ref(false);
@ -181,6 +183,10 @@ const loadPassword = async () => {
};
const loadSystemIP = async () => {
if (globalStore.currentNode !== 'local') {
form.systemIP = globalStore.currentNode || i18n.global.t('database.localIP');
return;
}
const res = await getSettingInfo();
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
};

View File

@ -4,7 +4,7 @@
<template #header-r>
<el-popover placement="left" :width="226" trigger="click">
<el-input size="small" v-model="filter" clearable @input="loadOption()" />
<el-table :show-header="false" :data="options" max-height="500px">
<el-table :show-header="false" :data="options" max-height="150px">
<el-table-column prop="key" width="120" show-overflow-tooltip />
<el-table-column prop="name">
<template #default="{ row }">

View File

@ -12,7 +12,7 @@
{{ $t('file.reduce') }}
</el-button>
<el-form-item :label="$t('file.fileRecycleBin')">
<el-switch v-model="status" active-value="enable" inactive-value="disable" @change="changeStatus" />
<el-switch v-model="status" active-value="Enable" inactive-value="Disable" @change="changeStatus" />
</el-form-item>
</div>
<ComplexTable
@ -78,7 +78,7 @@ const em = defineEmits(['close']);
const selects = ref([]);
const loading = ref(false);
const files = ref([]);
const status = ref('enable');
const status = ref('Enable');
const paginationConfig = reactive({
cacheSizeKey: 'recycle-page-size',

View File

@ -26,7 +26,7 @@
size="small"
class="ml-2"
inactive-value="Disable"
active-value="enable"
active-value="Enable"
@change="onPingOperate"
v-model="onPing"
/>

View File

@ -12,8 +12,8 @@
<el-switch
@change="onSaveStatus"
v-model="form.monitorStatus"
active-value="enable"
inactive-value="disable"
active-value="Enable"
inactive-value="Disable"
/>
</el-form-item>
<el-form-item :label="$t('monitor.storeDays')" prop="monitorStoreDays">
@ -72,7 +72,7 @@ import { MsgSuccess } from '@/utils/message';
const loading = ref();
const form = reactive({
monitorStatus: 'disable',
monitorStatus: 'Disable',
monitorStoreDays: 30,
monitorInterval: 1,
defaultNetwork: '',
@ -88,7 +88,8 @@ const search = async () => {
form.monitorStatus = res.data.monitorStatus;
form.monitorInterval = Number(res.data.monitorInterval);
form.monitorStoreDays = Number(res.data.monitorStoreDays);
form.defaultNetwork = res.data.defaultNetwork;
form.defaultNetwork =
res.data.defaultNetwork === 'all' ? i18n.global.t('commons.table.all') : res.data.defaultNetwork;
};
const onSaveStatus = async () => {

View File

@ -81,6 +81,7 @@
<el-form-item prop="password" class="w-full">
<el-input
type="password"
show-password
v-model.trim="loginForm.password"
class="w-full"
size="large"

View File

@ -118,6 +118,27 @@
</span>
</el-form-item>
<el-form-item
v-if="globalStore.currentNode === 'local'"
:label="$t('setting.systemIP')"
prop="systemIP"
>
<el-input disabled v-if="form.systemIP" v-model="form.systemIP">
<template #append>
<el-button @click="onChangeSystemIP" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
<el-input disabled v-if="!form.systemIP" v-model="unset">
<template #append>
<el-button @click="onChangeSystemIP" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
</el-form-item>
<el-form-item :label="$t('setting.proxy')" prop="proxyShow">
<el-input disabled v-model="form.proxyShow">
<template #append>
@ -174,6 +195,7 @@
<Password ref="passwordRef" />
<UserName ref="userNameRef" />
<PanelName ref="panelNameRef" @search="search()" />
<SystemIP ref="systemIPRef" @search="search()" />
<Proxy ref="proxyRef" @search="search()" />
<ApiInterface ref="apiInterfaceRef" @search="search()" />
<Timeout ref="timeoutRef" @search="search()" />
@ -196,6 +218,7 @@ import Password from '@/views/setting/panel/password/index.vue';
import UserName from '@/views/setting/panel/username/index.vue';
import Timeout from '@/views/setting/panel/timeout/index.vue';
import PanelName from '@/views/setting/panel/name/index.vue';
import SystemIP from '@/views/setting/panel/systemip/index.vue';
import Proxy from '@/views/setting/panel/proxy/index.vue';
import HideMenu from '@/views/setting/panel/hidemenu/index.vue';
import { storeToRefs } from 'pinia';
@ -233,6 +256,7 @@ const form = reactive({
language: '',
complexityVerification: '',
developerMode: '',
systemIP: '',
proxyShow: '',
proxyUrl: '',
@ -256,6 +280,7 @@ const show = ref();
const userNameRef = ref();
const passwordRef = ref();
const panelNameRef = ref();
const systemIPRef = ref();
const proxyRef = ref();
const timeoutRef = ref();
const hideMenuRef = ref();
@ -299,6 +324,7 @@ const search = async () => {
form.ipWhiteList = res.data.ipWhiteList;
form.apiKeyValidityTime = res.data.apiKeyValidityTime;
form.hideMenu = res.data.hideMenu;
form.systemIP = res.data.systemIP;
if (isMasterProductPro.value) {
const xpackRes = await getXpackSetting();
@ -328,6 +354,9 @@ const onChangeTitle = () => {
const onChangeTimeout = () => {
timeoutRef.value.acceptParams({ sessionTimeout: form.sessionTimeout });
};
const onChangeSystemIP = () => {
systemIPRef.value.acceptParams({ systemIP: form.systemIP });
};
const onChangeProxy = () => {
proxyRef.value.acceptParams({
url: form.proxyUrl,

View File

@ -3,12 +3,12 @@
<el-form ref="formRef" label-position="top" :model="form" @submit.prevent v-loading="loading">
<el-form-item :label="$t('setting.ipv6')" prop="ipv6" :rules="Rules.requiredSelect">
<el-radio-group style="width: 100%" v-model="form.ipv6" @change="onChangeMode()">
<el-radio value="enable">{{ $t('commons.button.enable') }}</el-radio>
<el-radio value="disable">{{ $t('commons.button.disable') }}</el-radio>
<el-radio value="Enable">{{ $t('commons.button.enable') }}</el-radio>
<el-radio value="Disable">{{ $t('commons.button.disable') }}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item
v-if="form.ipv6 === 'disable'"
v-if="form.ipv6 === 'Disable'"
:label="$t('setting.bindAddress')"
prop="bindAddress"
:rules="Rules.ip"
@ -82,7 +82,7 @@ const loadInterface = async () => {
};
const onChangeMode = () => {
form.bindAddress = form.ipv6 === 'enable' ? '::' : '0.0.0.0';
form.bindAddress = form.ipv6 === 'Enable' ? '::' : '0.0.0.0';
};
const onSavePort = async (formEl: FormInstance | undefined) => {

View File

@ -46,8 +46,8 @@
<el-form-item :label="$t('terminal.cursorBlink')">
<el-switch
v-model="form.cursorBlink"
active-value="enable"
inactive-value="disable"
active-value="Enable"
inactive-value="Disable"
@change="changeItem()"
/>
</el-form-item>
@ -115,7 +115,7 @@ const form = reactive({
lineHeight: 1.2,
letterSpacing: 1.2,
fontSize: 12,
cursorBlink: 'enable',
cursorBlink: 'Enable',
cursorStyle: 'underline',
scrollback: 1000,
scrollSensitivity: 10,
@ -171,7 +171,7 @@ const changeItem = () => {
term.value.options.lineHeight = form.lineHeight;
term.value.options.letterSpacing = form.letterSpacing;
term.value.options.fontSize = form.fontSize;
term.value.options.cursorBlink = form.cursorBlink === 'enable';
term.value.options.cursorBlink = form.cursorBlink === 'Enable';
term.value.options.cursorStyle = form.cursorStyle;
term.value.options.scrollback = form.scrollback;
term.value.options.scrollSensitivity = form.scrollSensitivity;
@ -183,7 +183,7 @@ const onSetDefault = () => {
form.lineHeight = 1.2;
form.letterSpacing = 0;
form.fontSize = 12;
form.cursorBlink = 'enable';
form.cursorBlink = 'Enable';
form.cursorStyle = 'block';
form.scrollback = 1000;
form.scrollSensitivity = 6;