mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-21 12:56:13 +08:00
feat: 完成 mysql 慢日志功能
This commit is contained in:
parent
a111e04c65
commit
85419b6dd4
4 changed files with 306 additions and 199 deletions
|
@ -220,6 +220,9 @@ export default {
|
||||||
maxConnectionsHelper: '最大连接数',
|
maxConnectionsHelper: '最大连接数',
|
||||||
restart: '重启数据库',
|
restart: '重启数据库',
|
||||||
|
|
||||||
|
isOn: '是否开启',
|
||||||
|
longQueryTime: '慢查询阈值',
|
||||||
|
|
||||||
status: '当前状态',
|
status: '当前状态',
|
||||||
terminal: '终端模式',
|
terminal: '终端模式',
|
||||||
key: '键',
|
key: '键',
|
||||||
|
@ -260,6 +263,7 @@ export default {
|
||||||
allConf: '全部配置',
|
allConf: '全部配置',
|
||||||
restartNow: '立即重启',
|
restartNow: '立即重启',
|
||||||
restartNowHelper1: '修改配置后需要重启生效,若您的数据需要持久化请先执行 save 操作。',
|
restartNowHelper1: '修改配置后需要重启生效,若您的数据需要持久化请先执行 save 操作。',
|
||||||
|
restartNowHelper: '修改配置后需要重启生效。',
|
||||||
|
|
||||||
persistence: '持久化',
|
persistence: '持久化',
|
||||||
rdbHelper1: '秒內,插入',
|
rdbHelper1: '秒內,插入',
|
||||||
|
|
|
@ -98,7 +98,12 @@ import { Codemirror } from 'vue-codemirror';
|
||||||
import { javascript } from '@codemirror/lang-javascript';
|
import { javascript } from '@codemirror/lang-javascript';
|
||||||
import { oneDark } from '@codemirror/theme-one-dark';
|
import { oneDark } from '@codemirror/theme-one-dark';
|
||||||
import { LoadFile } from '@/api/modules/files';
|
import { LoadFile } from '@/api/modules/files';
|
||||||
import { loadMysqlBaseInfo, updateMysqlConfByFile, updateMysqlDBInfo } from '@/api/modules/database';
|
import {
|
||||||
|
loadMysqlBaseInfo,
|
||||||
|
loadMysqlVariables,
|
||||||
|
updateMysqlConfByFile,
|
||||||
|
updateMysqlDBInfo,
|
||||||
|
} from '@/api/modules/database';
|
||||||
import { Rules } from '@/global/form-rules';
|
import { Rules } from '@/global/form-rules';
|
||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
|
|
||||||
|
@ -122,6 +127,7 @@ const slowLogRef = ref();
|
||||||
|
|
||||||
const onSetting = ref<boolean>(false);
|
const onSetting = ref<boolean>(false);
|
||||||
const mysqlName = ref();
|
const mysqlName = ref();
|
||||||
|
const variables = ref();
|
||||||
|
|
||||||
interface DialogProps {
|
interface DialogProps {
|
||||||
mysqlName: string;
|
mysqlName: string;
|
||||||
|
@ -131,9 +137,10 @@ const dialogContainerLogRef = ref();
|
||||||
const acceptParams = (params: DialogProps): void => {
|
const acceptParams = (params: DialogProps): void => {
|
||||||
onSetting.value = true;
|
onSetting.value = true;
|
||||||
mysqlName.value = params.mysqlName;
|
mysqlName.value = params.mysqlName;
|
||||||
variablesRef.value!.acceptParams({ mysqlName: params.mysqlName });
|
|
||||||
statusRef.value!.acceptParams({ mysqlName: params.mysqlName });
|
|
||||||
loadBaseInfo();
|
loadBaseInfo();
|
||||||
|
loadVariables();
|
||||||
|
loadSlowLogs();
|
||||||
|
statusRef.value!.acceptParams({ mysqlName: params.mysqlName });
|
||||||
};
|
};
|
||||||
const onClose = (): void => {
|
const onClose = (): void => {
|
||||||
onSetting.value = false;
|
onSetting.value = false;
|
||||||
|
@ -190,6 +197,22 @@ const loadBaseInfo = async () => {
|
||||||
loadContainerLog(baseInfo.containerID);
|
loadContainerLog(baseInfo.containerID);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadVariables = async () => {
|
||||||
|
const res = await loadMysqlVariables(mysqlName.value);
|
||||||
|
variables.value = res.data;
|
||||||
|
variablesRef.value!.acceptParams({ mysqlName: mysqlName.value, variables: res.data });
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadSlowLogs = async () => {
|
||||||
|
await Promise.all([loadBaseInfo(), loadVariables()]);
|
||||||
|
let param = {
|
||||||
|
mysqlName: mysqlName.value,
|
||||||
|
mysqlKey: baseInfo.mysqlKey,
|
||||||
|
variables: variables.value,
|
||||||
|
};
|
||||||
|
slowLogRef.value!.acceptParams(param);
|
||||||
|
};
|
||||||
|
|
||||||
const loadMysqlConf = async (path: string) => {
|
const loadMysqlConf = async (path: string) => {
|
||||||
const res = await LoadFile({ path: path });
|
const res = await LoadFile({ path: path });
|
||||||
mysqlConf.value = res.data;
|
mysqlConf.value = res.data;
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<span style="float: left">是否开启</span>
|
<span style="float: left">{{ $t('database.isOn') }}</span>
|
||||||
<el-switch style="margin-left: 20px; float: left" v-model="form.slow_query_log" />
|
<el-switch
|
||||||
<span style="margin-left: 30px; float: left">慢查询阈值</span>
|
style="margin-left: 20px; float: left"
|
||||||
|
v-model="variables.slow_query_log"
|
||||||
|
active-value="ON"
|
||||||
|
inactive-value="OFF"
|
||||||
|
/>
|
||||||
|
<span style="margin-left: 30px; float: left">{{ $t('database.longQueryTime') }}</span>
|
||||||
<div style="margin-left: 5px; float: left">
|
<div style="margin-left: 5px; float: left">
|
||||||
<el-input v-model="form.long_query_time"></el-input>
|
<el-input type="number" v-model.number="variables.long_query_time">
|
||||||
|
<template #append>{{ $t('database.second') }}</template>
|
||||||
|
</el-input>
|
||||||
</div>
|
</div>
|
||||||
<el-button style="margin-left: 20px">确认修改</el-button>
|
<el-button style="margin-left: 20px" @click="onSaveStart">{{ $t('commons.button.confirm') }}</el-button>
|
||||||
<div v-if="form.slow_query_log === 'ON'">
|
<div v-if="variables.slow_query_log === 'ON'">
|
||||||
<codemirror
|
<codemirror
|
||||||
:autofocus="true"
|
:autofocus="true"
|
||||||
placeholder="None data"
|
placeholder="None data"
|
||||||
|
@ -23,6 +30,8 @@
|
||||||
:readOnly="true"
|
:readOnly="true"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ConfirmDialog ref="confirmDialogRef" @confirm="onSave"></ConfirmDialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
@ -30,11 +39,72 @@ import { Codemirror } from 'vue-codemirror';
|
||||||
import { javascript } from '@codemirror/lang-javascript';
|
import { javascript } from '@codemirror/lang-javascript';
|
||||||
import { oneDark } from '@codemirror/theme-one-dark';
|
import { oneDark } from '@codemirror/theme-one-dark';
|
||||||
import { reactive, ref } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
|
import { Database } from '@/api/interface/database';
|
||||||
|
import { LoadFile } from '@/api/modules/files';
|
||||||
|
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
|
||||||
|
import { updateMysqlVariables } from '@/api/modules/database';
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
import i18n from '@/lang';
|
||||||
|
|
||||||
const extensions = [javascript(), oneDark];
|
const extensions = [javascript(), oneDark];
|
||||||
const slowLogs = ref();
|
const slowLogs = ref();
|
||||||
const form = reactive({
|
|
||||||
|
const confirmDialogRef = ref();
|
||||||
|
|
||||||
|
const mysqlName = ref();
|
||||||
|
const mysqlKey = ref();
|
||||||
|
const variables = reactive({
|
||||||
slow_query_log: 'OFF',
|
slow_query_log: 'OFF',
|
||||||
long_query_time: 10,
|
long_query_time: 10,
|
||||||
});
|
});
|
||||||
|
const oldVariables = ref();
|
||||||
|
|
||||||
|
interface DialogProps {
|
||||||
|
mysqlName: string;
|
||||||
|
mysqlKey: string;
|
||||||
|
variables: Database.MysqlVariables;
|
||||||
|
}
|
||||||
|
const acceptParams = (params: DialogProps): void => {
|
||||||
|
mysqlName.value = params.mysqlName;
|
||||||
|
mysqlKey.value = params.mysqlKey;
|
||||||
|
variables.slow_query_log = params.variables.slow_query_log;
|
||||||
|
variables.long_query_time = Number(params.variables.long_query_time);
|
||||||
|
|
||||||
|
if (variables.slow_query_log === 'ON') {
|
||||||
|
let path = `/opt/1Panel/data/apps/${mysqlKey.value}/${mysqlName.value}/data/onepanel-slow.log`;
|
||||||
|
loadMysqlSlowlogs(path);
|
||||||
|
}
|
||||||
|
oldVariables.value = { ...variables };
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSaveStart = async () => {
|
||||||
|
let params = {
|
||||||
|
header: i18n.global.t('database.confChange'),
|
||||||
|
operationInfo: i18n.global.t('database.restartNowHelper'),
|
||||||
|
submitInputInfo: i18n.global.t('database.restartNow'),
|
||||||
|
};
|
||||||
|
confirmDialogRef.value!.acceptParams(params);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSave = async () => {
|
||||||
|
let param = [] as Array<Database.VariablesUpdate>;
|
||||||
|
if (variables.slow_query_log !== oldVariables.value.slow_query_log) {
|
||||||
|
param.push({ param: 'slow_query_log', value: variables.slow_query_log });
|
||||||
|
}
|
||||||
|
if (variables.long_query_time !== oldVariables.value.long_query_time) {
|
||||||
|
param.push({ param: 'long_query_time', value: variables.long_query_time });
|
||||||
|
}
|
||||||
|
param.push({ param: 'slow_query_log_file', value: '/var/lib/mysql/onepanel-slow.log' });
|
||||||
|
await updateMysqlVariables(mysqlName.value, param);
|
||||||
|
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadMysqlSlowlogs = async (path: string) => {
|
||||||
|
const res = await LoadFile({ path: path });
|
||||||
|
slowLogs.value = res.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
acceptParams,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,134 +1,139 @@
|
||||||
<template>
|
<template>
|
||||||
<el-card>
|
<div>
|
||||||
<el-form :model="mysqlVariables" :rules="variablesRules" ref="variableFormRef" label-width="160px">
|
<el-card>
|
||||||
<el-row>
|
<el-form :model="mysqlVariables" :rules="variablesRules" ref="variableFormRef" label-width="160px">
|
||||||
<el-col :span="1"><br /></el-col>
|
<el-row>
|
||||||
<el-col :span="9">
|
<el-col :span="1"><br /></el-col>
|
||||||
<el-form-item :label="$t('database.optimizationScheme')">
|
<el-col :span="9">
|
||||||
<el-select @change="changePlan" clearable v-model="plan">
|
<el-form-item :label="$t('database.optimizationScheme')">
|
||||||
<el-option
|
<el-select @change="changePlan" clearable v-model="plan">
|
||||||
v-for="item in planOptions"
|
<el-option
|
||||||
:key="item.id"
|
v-for="item in planOptions"
|
||||||
:label="item.title"
|
:key="item.id"
|
||||||
:value="item.id"
|
:label="item.title"
|
||||||
/>
|
:value="item.id"
|
||||||
</el-select>
|
/>
|
||||||
</el-form-item>
|
</el-select>
|
||||||
</el-col>
|
</el-form-item>
|
||||||
</el-row>
|
</el-col>
|
||||||
<el-row>
|
</el-row>
|
||||||
<el-col :span="1"><br /></el-col>
|
<el-row>
|
||||||
<el-col :span="9">
|
<el-col :span="1"><br /></el-col>
|
||||||
<el-form-item label="key_buffer_size" prop="key_buffer_size">
|
<el-col :span="9">
|
||||||
<el-input clearable v-model.number="mysqlVariables.key_buffer_size">
|
<el-form-item label="key_buffer_size" prop="key_buffer_size">
|
||||||
<template #append>MB</template>
|
<el-input clearable v-model.number="mysqlVariables.key_buffer_size">
|
||||||
</el-input>
|
<template #append>MB</template>
|
||||||
<span class="input-help">{{ $t('database.keyBufferSizeHelper') }}</span>
|
</el-input>
|
||||||
</el-form-item>
|
<span class="input-help">{{ $t('database.keyBufferSizeHelper') }}</span>
|
||||||
<el-form-item label="query_cache_size" prop="query_cache_size">
|
</el-form-item>
|
||||||
<el-input clearable v-model.number="mysqlVariables.query_cache_size">
|
<el-form-item label="query_cache_size" prop="query_cache_size">
|
||||||
<template #append>MB</template>
|
<el-input clearable v-model.number="mysqlVariables.query_cache_size">
|
||||||
</el-input>
|
<template #append>MB</template>
|
||||||
<span class="input-help">{{ $t('database.queryCacheSizeHelper') }}</span>
|
</el-input>
|
||||||
</el-form-item>
|
<span class="input-help">{{ $t('database.queryCacheSizeHelper') }}</span>
|
||||||
<el-form-item label="tmp_table_size" prop="tmp_table_size">
|
</el-form-item>
|
||||||
<el-input clearable v-model.number="mysqlVariables.tmp_table_size">
|
<el-form-item label="tmp_table_size" prop="tmp_table_size">
|
||||||
<template #append>MB</template>
|
<el-input clearable v-model.number="mysqlVariables.tmp_table_size">
|
||||||
</el-input>
|
<template #append>MB</template>
|
||||||
<span class="input-help">{{ $t('database.tmpTableSizeHelper') }}</span>
|
</el-input>
|
||||||
</el-form-item>
|
<span class="input-help">{{ $t('database.tmpTableSizeHelper') }}</span>
|
||||||
<el-form-item label="innodb_buffer_pool_size" prop="innodb_buffer_pool_size">
|
</el-form-item>
|
||||||
<el-input clearable v-model.number="mysqlVariables.innodb_buffer_pool_size">
|
<el-form-item label="innodb_buffer_pool_size" prop="innodb_buffer_pool_size">
|
||||||
<template #append>MB</template>
|
<el-input clearable v-model.number="mysqlVariables.innodb_buffer_pool_size">
|
||||||
</el-input>
|
<template #append>MB</template>
|
||||||
<span class="input-help">{{ $t('database.innodbBufferPoolSizeHelper') }}</span>
|
</el-input>
|
||||||
</el-form-item>
|
<span class="input-help">{{ $t('database.innodbBufferPoolSizeHelper') }}</span>
|
||||||
<el-form-item label="innodb_log_buffer_size" prop="innodb_log_buffer_size">
|
</el-form-item>
|
||||||
<el-input clearable v-model.number="mysqlVariables.innodb_log_buffer_size">
|
<el-form-item label="innodb_log_buffer_size" prop="innodb_log_buffer_size">
|
||||||
<template #append>MB</template>
|
<el-input clearable v-model.number="mysqlVariables.innodb_log_buffer_size">
|
||||||
</el-input>
|
<template #append>MB</template>
|
||||||
<span class="input-help">{{ $t('database.innodbLogBufferSizeHelper') }}</span>
|
</el-input>
|
||||||
</el-form-item>
|
<span class="input-help">{{ $t('database.innodbLogBufferSizeHelper') }}</span>
|
||||||
<el-form-item label="sort_buffer_size" prop="sort_buffer_size">
|
</el-form-item>
|
||||||
<el-input clearable v-model.number="mysqlVariables.sort_buffer_size">
|
<el-form-item label="sort_buffer_size" prop="sort_buffer_size">
|
||||||
<template #append>KB</template>
|
<el-input clearable v-model.number="mysqlVariables.sort_buffer_size">
|
||||||
</el-input>
|
<template #append>KB</template>
|
||||||
<span class="input-help">{{ $t('database.sortBufferSizeHelper') }}</span>
|
</el-input>
|
||||||
</el-form-item>
|
<span class="input-help">{{ $t('database.sortBufferSizeHelper') }}</span>
|
||||||
<el-form-item label="read_buffer_size" prop="read_buffer_size">
|
</el-form-item>
|
||||||
<el-input clearable v-model.number="mysqlVariables.read_buffer_size">
|
<el-form-item label="read_buffer_size" prop="read_buffer_size">
|
||||||
<template #append>KB</template>
|
<el-input clearable v-model.number="mysqlVariables.read_buffer_size">
|
||||||
</el-input>
|
<template #append>KB</template>
|
||||||
<span class="input-help">{{ $t('database.readBufferSizeHelper') }}</span>
|
</el-input>
|
||||||
</el-form-item>
|
<span class="input-help">{{ $t('database.readBufferSizeHelper') }}</span>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button
|
<el-button
|
||||||
icon="Collection"
|
icon="Collection"
|
||||||
@click="onSaveVariables(variableFormRef)"
|
@click="onSaveStart(variableFormRef)"
|
||||||
type="primary"
|
type="primary"
|
||||||
size="default"
|
size="default"
|
||||||
>
|
>
|
||||||
{{ $t('commons.button.save') }}
|
{{ $t('commons.button.save') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button icon="RefreshLeft" size="default">
|
<el-button icon="RefreshLeft" size="default">
|
||||||
{{ $t('database.restart') }}
|
{{ $t('database.restart') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="2"><br /></el-col>
|
<el-col :span="2"><br /></el-col>
|
||||||
<el-col :span="9">
|
<el-col :span="9">
|
||||||
<el-form-item label="read_rnd_buffer_size" prop="read_rnd_buffer_size">
|
<el-form-item label="read_rnd_buffer_size" prop="read_rnd_buffer_size">
|
||||||
<el-input clearable v-model.number="mysqlVariables.read_rnd_buffer_size">
|
<el-input clearable v-model.number="mysqlVariables.read_rnd_buffer_size">
|
||||||
<template #append>KB</template>
|
<template #append>KB</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
<span class="input-help">{{ $t('database.readRndBufferSizeHelper') }}</span>
|
<span class="input-help">{{ $t('database.readRndBufferSizeHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="join_buffer_size" prop="join_buffer_size">
|
<el-form-item label="join_buffer_size" prop="join_buffer_size">
|
||||||
<el-input clearable v-model.number="mysqlVariables.join_buffer_size">
|
<el-input clearable v-model.number="mysqlVariables.join_buffer_size">
|
||||||
<template #append>KB</template>
|
<template #append>KB</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
<span class="input-help">{{ $t('database.joinBufferSizeHelper') }}</span>
|
<span class="input-help">{{ $t('database.joinBufferSizeHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="thread_stack" prop="thread_stack">
|
<el-form-item label="thread_stack" prop="thread_stack">
|
||||||
<el-input clearable v-model.number="mysqlVariables.thread_stack">
|
<el-input clearable v-model.number="mysqlVariables.thread_stack">
|
||||||
<template #append>KB</template>
|
<template #append>KB</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
<span class="input-help">{{ $t('database.threadStackelper') }}</span>
|
<span class="input-help">{{ $t('database.threadStackelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="binlog_cache_size" prop="binlog_cache_size">
|
<el-form-item label="binlog_cache_size" prop="binlog_cache_size">
|
||||||
<el-input clearable v-model.number="mysqlVariables.binlog_cache_size">
|
<el-input clearable v-model.number="mysqlVariables.binlog_cache_size">
|
||||||
<template #append>KB</template>
|
<template #append>KB</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
<span class="input-help">{{ $t('database.binlogCacheSizeHelper') }}</span>
|
<span class="input-help">{{ $t('database.binlogCacheSizeHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="thread_cache_size" prop="thread_cache_size">
|
<el-form-item label="thread_cache_size" prop="thread_cache_size">
|
||||||
<el-input clearable v-model.number="mysqlVariables.thread_cache_size" />
|
<el-input clearable v-model.number="mysqlVariables.thread_cache_size" />
|
||||||
<span class="input-help">{{ $t('database.threadCacheSizeHelper') }}</span>
|
<span class="input-help">{{ $t('database.threadCacheSizeHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="table_open_cache" prop="table_open_cache">
|
<el-form-item label="table_open_cache" prop="table_open_cache">
|
||||||
<el-input clearable v-model.number="mysqlVariables.table_open_cache" />
|
<el-input clearable v-model.number="mysqlVariables.table_open_cache" />
|
||||||
<span class="input-help">{{ $t('database.tableOpenCacheHelper') }}</span>
|
<span class="input-help">{{ $t('database.tableOpenCacheHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="max_connections" prop="max_connections">
|
<el-form-item label="max_connections" prop="max_connections">
|
||||||
<el-input clearable v-model.number="mysqlVariables.max_connections" />
|
<el-input clearable v-model.number="mysqlVariables.max_connections" />
|
||||||
<span class="input-help">{{ $t('database.maxConnectionsHelper') }}</span>
|
<span class="input-help">{{ $t('database.maxConnectionsHelper') }}</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
<ConfirmDialog ref="confirmDialogRef" @confirm="onSaveVariables"></ConfirmDialog>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { reactive, ref } from 'vue';
|
import { reactive, ref } from 'vue';
|
||||||
import { Rules } from '@/global/form-rules';
|
import { Rules } from '@/global/form-rules';
|
||||||
import { ElMessage, FormInstance } from 'element-plus';
|
import { ElMessage, FormInstance } from 'element-plus';
|
||||||
import { Database } from '@/api/interface/database';
|
import { Database } from '@/api/interface/database';
|
||||||
import { loadMysqlVariables, updateMysqlVariables } from '@/api/modules/database';
|
import ConfirmDialog from '@/components/confirm-dialog/index.vue';
|
||||||
|
import { updateMysqlVariables } from '@/api/modules/database';
|
||||||
import i18n from '@/lang';
|
import i18n from '@/lang';
|
||||||
import { planOptions } from './../helper';
|
import { planOptions } from './../helper';
|
||||||
|
|
||||||
const plan = ref();
|
const plan = ref();
|
||||||
|
const confirmDialogRef = ref();
|
||||||
|
|
||||||
const variableFormRef = ref<FormInstance>();
|
const variableFormRef = ref<FormInstance>();
|
||||||
const oldVariables = ref<Database.MysqlVariables>();
|
const oldVariables = ref<Database.MysqlVariables>();
|
||||||
|
@ -175,30 +180,25 @@ const variablesRules = reactive({
|
||||||
const mysqlName = ref();
|
const mysqlName = ref();
|
||||||
interface DialogProps {
|
interface DialogProps {
|
||||||
mysqlName: string;
|
mysqlName: string;
|
||||||
|
variables: Database.MysqlVariables;
|
||||||
}
|
}
|
||||||
const acceptParams = (params: DialogProps): void => {
|
const acceptParams = (params: DialogProps): void => {
|
||||||
console.log('adad');
|
|
||||||
mysqlName.value = params.mysqlName;
|
mysqlName.value = params.mysqlName;
|
||||||
loadVariables();
|
mysqlVariables.key_buffer_size = Number(params.variables.key_buffer_size) / 1024 / 1024;
|
||||||
};
|
mysqlVariables.query_cache_size = Number(params.variables.query_cache_size) / 1024 / 1024;
|
||||||
|
mysqlVariables.tmp_table_size = Number(params.variables.tmp_table_size) / 1024 / 1024;
|
||||||
|
mysqlVariables.innodb_buffer_pool_size = Number(params.variables.innodb_buffer_pool_size) / 1024 / 1024;
|
||||||
|
mysqlVariables.innodb_log_buffer_size = Number(params.variables.innodb_log_buffer_size) / 1024 / 1024;
|
||||||
|
|
||||||
const loadVariables = async () => {
|
mysqlVariables.sort_buffer_size = Number(params.variables.sort_buffer_size) / 1024;
|
||||||
const res = await loadMysqlVariables(mysqlName.value);
|
mysqlVariables.read_buffer_size = Number(params.variables.read_buffer_size) / 1024;
|
||||||
mysqlVariables.key_buffer_size = Number(res.data.key_buffer_size) / 1024 / 1024;
|
mysqlVariables.read_rnd_buffer_size = Number(params.variables.read_rnd_buffer_size) / 1024;
|
||||||
mysqlVariables.query_cache_size = Number(res.data.query_cache_size) / 1024 / 1024;
|
mysqlVariables.join_buffer_size = Number(params.variables.join_buffer_size) / 1024;
|
||||||
mysqlVariables.tmp_table_size = Number(res.data.tmp_table_size) / 1024 / 1024;
|
mysqlVariables.thread_stack = Number(params.variables.thread_stack) / 1024;
|
||||||
mysqlVariables.innodb_buffer_pool_size = Number(res.data.innodb_buffer_pool_size) / 1024 / 1024;
|
mysqlVariables.binlog_cache_size = Number(params.variables.binlog_cache_size) / 1024;
|
||||||
mysqlVariables.innodb_log_buffer_size = Number(res.data.innodb_log_buffer_size) / 1024 / 1024;
|
mysqlVariables.thread_cache_size = Number(params.variables.thread_cache_size);
|
||||||
|
mysqlVariables.table_open_cache = Number(params.variables.table_open_cache);
|
||||||
mysqlVariables.sort_buffer_size = Number(res.data.sort_buffer_size) / 1024;
|
mysqlVariables.max_connections = Number(params.variables.max_connections);
|
||||||
mysqlVariables.read_buffer_size = Number(res.data.read_buffer_size) / 1024;
|
|
||||||
mysqlVariables.read_rnd_buffer_size = Number(res.data.read_rnd_buffer_size) / 1024;
|
|
||||||
mysqlVariables.join_buffer_size = Number(res.data.join_buffer_size) / 1024;
|
|
||||||
mysqlVariables.thread_stack = Number(res.data.thread_stack) / 1024;
|
|
||||||
mysqlVariables.binlog_cache_size = Number(res.data.binlog_cache_size) / 1024;
|
|
||||||
mysqlVariables.thread_cache_size = Number(res.data.thread_cache_size);
|
|
||||||
mysqlVariables.table_open_cache = Number(res.data.table_open_cache);
|
|
||||||
mysqlVariables.max_connections = Number(res.data.max_connections);
|
|
||||||
oldVariables.value = { ...mysqlVariables };
|
oldVariables.value = { ...mysqlVariables };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -223,62 +223,72 @@ const changePlan = async () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const onSaveVariables = async (formEl: FormInstance | undefined) => {
|
|
||||||
|
const onSaveStart = async (formEl: FormInstance | undefined) => {
|
||||||
if (!formEl) return;
|
if (!formEl) return;
|
||||||
formEl.validate(async (valid) => {
|
formEl.validate(async (valid) => {
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
let param = [] as Array<Database.VariablesUpdate>;
|
let params = {
|
||||||
if (oldVariables.value?.key_buffer_size !== mysqlVariables.key_buffer_size) {
|
header: i18n.global.t('database.confChange'),
|
||||||
param.push({ param: 'key_buffer_size', value: mysqlVariables.key_buffer_size * 1024 * 1024 });
|
operationInfo: i18n.global.t('database.restartNowHelper'),
|
||||||
}
|
submitInputInfo: i18n.global.t('database.restartNow'),
|
||||||
if (oldVariables.value?.query_cache_size !== mysqlVariables.query_cache_size) {
|
};
|
||||||
param.push({ param: 'query_cache_size', value: mysqlVariables.query_cache_size * 1024 * 1024 });
|
confirmDialogRef.value!.acceptParams(params);
|
||||||
}
|
|
||||||
if (oldVariables.value?.tmp_table_size !== mysqlVariables.tmp_table_size) {
|
|
||||||
param.push({ param: 'tmp_table_size', value: mysqlVariables.tmp_table_size * 1024 * 1024 });
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.innodb_buffer_pool_size !== mysqlVariables.innodb_buffer_pool_size) {
|
|
||||||
param.push({
|
|
||||||
param: 'innodb_buffer_pool_size',
|
|
||||||
value: mysqlVariables.innodb_buffer_pool_size * 1024 * 1024,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.innodb_log_buffer_size !== mysqlVariables.innodb_log_buffer_size) {
|
|
||||||
param.push({ param: 'innodb_log_buffer_size', value: mysqlVariables.innodb_log_buffer_size * 1024 * 1024 });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldVariables.value?.sort_buffer_size !== mysqlVariables.sort_buffer_size) {
|
|
||||||
param.push({ param: 'sort_buffer_size', value: mysqlVariables.sort_buffer_size * 1024 });
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.read_buffer_size !== mysqlVariables.read_buffer_size) {
|
|
||||||
param.push({ param: 'read_buffer_size', value: mysqlVariables.read_buffer_size * 1024 });
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.read_rnd_buffer_size !== mysqlVariables.read_rnd_buffer_size) {
|
|
||||||
param.push({ param: 'read_rnd_buffer_size', value: mysqlVariables.read_rnd_buffer_size * 1024 });
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.join_buffer_size !== mysqlVariables.join_buffer_size) {
|
|
||||||
param.push({ param: 'join_buffer_size', value: mysqlVariables.join_buffer_size * 1024 });
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.thread_stack !== mysqlVariables.thread_stack) {
|
|
||||||
param.push({ param: 'thread_stack', value: mysqlVariables.thread_stack * 1024 });
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.binlog_cache_size !== mysqlVariables.binlog_cache_size) {
|
|
||||||
param.push({ param: 'binlog_cache_size', value: mysqlVariables.binlog_cache_size * 1024 });
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.thread_cache_size !== mysqlVariables.thread_cache_size) {
|
|
||||||
param.push({ param: 'thread_cache_size', value: mysqlVariables.thread_cache_size });
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.table_open_cache !== mysqlVariables.table_open_cache) {
|
|
||||||
param.push({ param: 'table_open_cache', value: mysqlVariables.table_open_cache });
|
|
||||||
}
|
|
||||||
if (oldVariables.value?.max_connections !== mysqlVariables.max_connections) {
|
|
||||||
param.push({ param: 'max_connections', value: mysqlVariables.max_connections });
|
|
||||||
}
|
|
||||||
await updateMysqlVariables(mysqlName.value, param);
|
|
||||||
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onSaveVariables = async () => {
|
||||||
|
let param = [] as Array<Database.VariablesUpdate>;
|
||||||
|
if (oldVariables.value?.key_buffer_size !== mysqlVariables.key_buffer_size) {
|
||||||
|
param.push({ param: 'key_buffer_size', value: mysqlVariables.key_buffer_size * 1024 * 1024 });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.query_cache_size !== mysqlVariables.query_cache_size) {
|
||||||
|
param.push({ param: 'query_cache_size', value: mysqlVariables.query_cache_size * 1024 * 1024 });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.tmp_table_size !== mysqlVariables.tmp_table_size) {
|
||||||
|
param.push({ param: 'tmp_table_size', value: mysqlVariables.tmp_table_size * 1024 * 1024 });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.innodb_buffer_pool_size !== mysqlVariables.innodb_buffer_pool_size) {
|
||||||
|
param.push({
|
||||||
|
param: 'innodb_buffer_pool_size',
|
||||||
|
value: mysqlVariables.innodb_buffer_pool_size * 1024 * 1024,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.innodb_log_buffer_size !== mysqlVariables.innodb_log_buffer_size) {
|
||||||
|
param.push({ param: 'innodb_log_buffer_size', value: mysqlVariables.innodb_log_buffer_size * 1024 * 1024 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldVariables.value?.sort_buffer_size !== mysqlVariables.sort_buffer_size) {
|
||||||
|
param.push({ param: 'sort_buffer_size', value: mysqlVariables.sort_buffer_size * 1024 });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.read_buffer_size !== mysqlVariables.read_buffer_size) {
|
||||||
|
param.push({ param: 'read_buffer_size', value: mysqlVariables.read_buffer_size * 1024 });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.read_rnd_buffer_size !== mysqlVariables.read_rnd_buffer_size) {
|
||||||
|
param.push({ param: 'read_rnd_buffer_size', value: mysqlVariables.read_rnd_buffer_size * 1024 });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.join_buffer_size !== mysqlVariables.join_buffer_size) {
|
||||||
|
param.push({ param: 'join_buffer_size', value: mysqlVariables.join_buffer_size * 1024 });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.thread_stack !== mysqlVariables.thread_stack) {
|
||||||
|
param.push({ param: 'thread_stack', value: mysqlVariables.thread_stack * 1024 });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.binlog_cache_size !== mysqlVariables.binlog_cache_size) {
|
||||||
|
param.push({ param: 'binlog_cache_size', value: mysqlVariables.binlog_cache_size * 1024 });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.thread_cache_size !== mysqlVariables.thread_cache_size) {
|
||||||
|
param.push({ param: 'thread_cache_size', value: mysqlVariables.thread_cache_size });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.table_open_cache !== mysqlVariables.table_open_cache) {
|
||||||
|
param.push({ param: 'table_open_cache', value: mysqlVariables.table_open_cache });
|
||||||
|
}
|
||||||
|
if (oldVariables.value?.max_connections !== mysqlVariables.max_connections) {
|
||||||
|
param.push({ param: 'max_connections', value: mysqlVariables.max_connections });
|
||||||
|
}
|
||||||
|
await updateMysqlVariables(mysqlName.value, param);
|
||||||
|
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
|
||||||
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
acceptParams,
|
acceptParams,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue