mirror of
				https://github.com/1Panel-dev/1Panel.git
				synced 2025-10-31 19:26:02 +08:00 
			
		
		
		
	fix: 数据库慢日志实现修改
This commit is contained in:
		
							parent
							
								
									015baec864
								
							
						
					
					
						commit
						3f01ef61e5
					
				
					 3 changed files with 58 additions and 35 deletions
				
			
		|  | @ -352,8 +352,9 @@ export default { | ||||||
|         slowLog: 'Slowlogs', |         slowLog: 'Slowlogs', | ||||||
|         noData: 'No slow log yet...', |         noData: 'No slow log yet...', | ||||||
| 
 | 
 | ||||||
|         isOn: 'Is on', |         isOn: 'On', | ||||||
|         longQueryTime: 'Slow query threshold', |         longQueryTime: 'threshold(s)', | ||||||
|  |         thresholdRangeHelper: 'Please enter the correct threshold (1 - 600).', | ||||||
| 
 | 
 | ||||||
|         status: 'The current state', |         status: 'The current state', | ||||||
|         baseParam: 'Basic parameter', |         baseParam: 'Basic parameter', | ||||||
|  |  | ||||||
|  | @ -361,8 +361,9 @@ export default { | ||||||
|         slowLog: '慢日志', |         slowLog: '慢日志', | ||||||
|         noData: '暂无慢日志...', |         noData: '暂无慢日志...', | ||||||
| 
 | 
 | ||||||
|         isOn: '是否开启', |         isOn: '开启', | ||||||
|         longQueryTime: '慢查询阈值', |         longQueryTime: '阈值(秒)', | ||||||
|  |         thresholdRangeHelper: '请输入正确的阈值(1 - 600)', | ||||||
| 
 | 
 | ||||||
|         status: '当前状态', |         status: '当前状态', | ||||||
|         terminal: '终端模式', |         terminal: '终端模式', | ||||||
|  |  | ||||||
|  | @ -1,32 +1,35 @@ | ||||||
| <template> | <template> | ||||||
|     <div> |     <div> | ||||||
|         <span style="float: left; line-height: 30px">{{ $t('database.longQueryTime') }}</span> |         <el-form label-position="left" label-width="80px"> | ||||||
|         <div style="margin-left: 5px; float: left"> |             <el-form-item :label="$t('database.isOn')"> | ||||||
|             <el-input @input="checkValid" type="number" v-model.number="variables.long_query_time"> |                 <el-switch | ||||||
|                 <template #append>{{ $t('database.second') }}</template> |                     v-model="variables.slow_query_log" | ||||||
|             </el-input> |                     active-value="ON" | ||||||
|             <span v-if="errTime" class="input-error">{{ $t('commons.rule.numberRange', [1, 600]) }}</span> |                     inactive-value="OFF" | ||||||
|         </div> |                     @change="handleSlowLogs" | ||||||
|         <span style="float: left; margin-left: 20px; line-height: 30px">{{ $t('database.isOn') }}</span> |                 /> | ||||||
|         <el-switch |             </el-form-item> | ||||||
|             style="margin-left: 5px; float: left" |             <el-form-item :label="$t('database.longQueryTime')" v-if="detailShow"> | ||||||
|             v-model="variables.slow_query_log" |                 <div style="float: left"> | ||||||
|             active-value="ON" |                     <el-input type="number" v-model.number="variables.long_query_time" /> | ||||||
|             inactive-value="OFF" |                 </div> | ||||||
|             @change="handleSlowLogs" |                 <el-button style="float: left; margin-left: 10px" @click="openSlowLogs" type="primary"> | ||||||
|         /> |                     {{ $t('commons.button.save') }} | ||||||
|         <div style="margin-left: 20px; float: left"> |                 </el-button> | ||||||
|             <el-checkbox border v-model="isWatch">{{ $t('commons.button.watch') }}</el-checkbox> |                 <div style="float: left; margin-left: 20px"> | ||||||
|         </div> |                     <el-checkbox border v-model="isWatch">{{ $t('commons.button.watch') }}</el-checkbox> | ||||||
|         <el-button style="margin-left: 20px" @click="onDownload" icon="Download"> |                 </div> | ||||||
|             {{ $t('file.download') }} |                 <el-button style="margin-left: 20px" @click="onDownload" icon="Download"> | ||||||
|         </el-button> |                     {{ $t('file.download') }} | ||||||
|  |                 </el-button> | ||||||
|  |             </el-form-item> | ||||||
|  |         </el-form> | ||||||
|         <codemirror |         <codemirror | ||||||
|             :autofocus="true" |             :autofocus="true" | ||||||
|             :placeholder="$t('database.noData')" |             :placeholder="$t('database.noData')" | ||||||
|             :indent-with-tab="true" |             :indent-with-tab="true" | ||||||
|             :tabSize="4" |             :tabSize="4" | ||||||
|             style="margin-top: 10px; height: calc(100vh - 392px); width: 100%" |             style="height: calc(100vh - 427px); width: 100%" | ||||||
|             :lineWrapping="true" |             :lineWrapping="true" | ||||||
|             :matchBrackets="true" |             :matchBrackets="true" | ||||||
|             theme="cobalt" |             theme="cobalt" | ||||||
|  | @ -53,7 +56,7 @@ import { updateMysqlVariables } from '@/api/modules/database'; | ||||||
| import { dateFormatForName } from '@/utils/util'; | import { dateFormatForName } from '@/utils/util'; | ||||||
| import i18n from '@/lang'; | import i18n from '@/lang'; | ||||||
| import { loadBaseDir } from '@/api/modules/setting'; | import { loadBaseDir } from '@/api/modules/setting'; | ||||||
| import { MsgSuccess } from '@/utils/message'; | import { MsgError, MsgSuccess } from '@/utils/message'; | ||||||
| 
 | 
 | ||||||
| const extensions = [javascript(), oneDark]; | const extensions = [javascript(), oneDark]; | ||||||
| const slowLogs = ref(); | const slowLogs = ref(); | ||||||
|  | @ -61,10 +64,11 @@ const view = shallowRef(); | ||||||
| const handleReady = (payload) => { | const handleReady = (payload) => { | ||||||
|     view.value = payload.view; |     view.value = payload.view; | ||||||
| }; | }; | ||||||
|  | const detailShow = ref(); | ||||||
|  | const isOnEdit = ref(); | ||||||
| 
 | 
 | ||||||
| const confirmDialogRef = ref(); | const confirmDialogRef = ref(); | ||||||
| 
 | 
 | ||||||
| const errTime = ref(); |  | ||||||
| const isWatch = ref(); | const isWatch = ref(); | ||||||
| let timer: NodeJS.Timer | null = null; | let timer: NodeJS.Timer | null = null; | ||||||
| 
 | 
 | ||||||
|  | @ -87,6 +91,7 @@ const acceptParams = async (params: DialogProps): Promise<void> => { | ||||||
|     const pathRes = await loadBaseDir(); |     const pathRes = await loadBaseDir(); | ||||||
|     let path = `${pathRes.data}/apps/mysql/${mysqlName.value}/data/1Panel-slow.log`; |     let path = `${pathRes.data}/apps/mysql/${mysqlName.value}/data/1Panel-slow.log`; | ||||||
|     if (variables.slow_query_log === 'ON') { |     if (variables.slow_query_log === 'ON') { | ||||||
|  |         detailShow.value = true; | ||||||
|         loadMysqlSlowlogs(path); |         loadMysqlSlowlogs(path); | ||||||
|     } |     } | ||||||
|     timer = setInterval(() => { |     timer = setInterval(() => { | ||||||
|  | @ -99,6 +104,28 @@ const acceptParams = async (params: DialogProps): Promise<void> => { | ||||||
| const emit = defineEmits(['loading']); | const emit = defineEmits(['loading']); | ||||||
| 
 | 
 | ||||||
| const handleSlowLogs = async () => { | const handleSlowLogs = async () => { | ||||||
|  |     if (variables.slow_query_log === 'ON') { | ||||||
|  |         detailShow.value = true; | ||||||
|  |         isOnEdit.value = true; | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |     if (isOnEdit.value) { | ||||||
|  |         detailShow.value = false; | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|  |     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 openSlowLogs = () => { | ||||||
|  |     if (!(variables.long_query_time > 0 && variables.long_query_time <= 600)) { | ||||||
|  |         MsgError(i18n.global.t('database.thresholdRangeHelper')); | ||||||
|  |         return; | ||||||
|  |     } | ||||||
|     let params = { |     let params = { | ||||||
|         header: i18n.global.t('database.confChange'), |         header: i18n.global.t('database.confChange'), | ||||||
|         operationInfo: i18n.global.t('database.restartNowHelper'), |         operationInfo: i18n.global.t('database.restartNowHelper'), | ||||||
|  | @ -111,14 +138,7 @@ const onCancle = async () => { | ||||||
|     variables.slow_query_log = variables.slow_query_log === 'ON' ? 'OFF' : 'ON'; |     variables.slow_query_log = variables.slow_query_log === 'ON' ? 'OFF' : 'ON'; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const checkValid = () => { |  | ||||||
|     errTime.value = !(variables.long_query_time > 0 && variables.long_query_time < 600); |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| const onSave = async () => { | const onSave = async () => { | ||||||
|     if (!(variables.long_query_time > 0 && variables.long_query_time < 600)) { |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
|     let param = [] as Array<Database.VariablesUpdate>; |     let param = [] as Array<Database.VariablesUpdate>; | ||||||
|     if (variables.slow_query_log !== oldVariables.value.slow_query_log) { |     if (variables.slow_query_log !== oldVariables.value.slow_query_log) { | ||||||
|         param.push({ param: 'slow_query_log', value: variables.slow_query_log }); |         param.push({ param: 'slow_query_log', value: variables.slow_query_log }); | ||||||
|  | @ -131,6 +151,7 @@ const onSave = async () => { | ||||||
|     await updateMysqlVariables(param) |     await updateMysqlVariables(param) | ||||||
|         .then(() => { |         .then(() => { | ||||||
|             emit('loading', false); |             emit('loading', false); | ||||||
|  |             isOnEdit.value = false; | ||||||
|             MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); |             MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); | ||||||
|         }) |         }) | ||||||
|         .catch(() => { |         .catch(() => { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue