Skip to content

Commit 6ab1418

Browse files
perf: Optimize supervisor log reading (#11545)
Refs #11515
1 parent 1f70646 commit 6ab1418

File tree

4 files changed

+133
-52
lines changed

4 files changed

+133
-52
lines changed

agent/app/service/file.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,9 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi
658658
configPath = pathSet.Value
659659
}
660660
logFilePath, _ = ini_conf.GetIniValue(configPath, "supervisord", "logfile")
661+
case constant.Supervisor:
662+
logDir := path.Join(global.Dir.DataDir, "tools", "supervisord", "log")
663+
logFilePath = path.Join(logDir, req.Name)
661664
}
662665

663666
file, err := os.Open(logFilePath)

frontend/src/views/toolbox/supervisor/file/index.vue

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
<template>
22
<DrawerPro
33
v-model="open"
4-
:header="title"
4+
:header="$t('website.source')"
55
@close="handleClose"
66
:size="globalStore.isFullScreen ? 'full' : 'large'"
77
:fullScreen="true"
88
>
99
<template #content>
10-
<div v-if="req.file != 'config'">
11-
<el-tabs v-model="req.file" type="card" @tab-click="handleChange">
12-
<el-tab-pane :label="$t('logs.runLog')" name="out.log"></el-tab-pane>
13-
<el-tab-pane :label="$t('logs.errLog')" name="err.log"></el-tab-pane>
14-
</el-tabs>
15-
<el-checkbox border v-model="tailLog" class="float-left" @change="changeTail">
16-
{{ $t('commons.button.watch') }}
17-
</el-checkbox>
18-
<el-button class="ml-5" @click="cleanLog" icon="Delete">
19-
{{ $t('commons.button.clean') }}
20-
</el-button>
21-
</div>
22-
<br />
2310
<div v-loading="loading">
2411
<CodemirrorPro class="mt-5" v-model="content" :heightDiff="400"></CodemirrorPro>
2512
</div>
@@ -28,19 +15,17 @@
2815
<template #footer>
2916
<span>
3017
<el-button @click="handleClose" :disabled="loading">{{ $t('commons.button.cancel') }}</el-button>
31-
<el-button type="primary" :disabled="loading" @click="submit()" v-if="req.file === 'config'">
18+
<el-button type="primary" :disabled="loading" @click="submit()">
3219
{{ $t('commons.button.confirm') }}
3320
</el-button>
3421
</span>
3522
</template>
3623
</DrawerPro>
37-
<OpDialog ref="opRef" @search="getContent" />
3824
</template>
3925
<script lang="ts" setup>
4026
import { onUnmounted, reactive, ref } from 'vue';
4127
import { operateSupervisorProcessFile } from '@/api/modules/host-tool';
4228
import i18n from '@/lang';
43-
import { TabsPaneContext } from 'element-plus';
4429
import { MsgSuccess } from '@/utils/message';
4530
import { GlobalStore } from '@/store';
4631
const globalStore = GlobalStore();
@@ -55,10 +40,6 @@ const req = reactive({
5540
operate: '',
5641
content: '',
5742
});
58-
const title = ref('');
59-
const opRef = ref();
60-
61-
let timer: NodeJS.Timer | null = null;
6243
6344
const em = defineEmits(['search']);
6445
@@ -73,21 +54,6 @@ const getContent = () => {
7354
});
7455
};
7556
76-
const handleChange = (tab: TabsPaneContext) => {
77-
req.file = tab.props.name.toString();
78-
getContent();
79-
};
80-
81-
const changeTail = () => {
82-
if (tailLog.value) {
83-
timer = setInterval(() => {
84-
getContent();
85-
}, 1000 * 5);
86-
} else {
87-
onCloseLog();
88-
}
89-
};
90-
9157
const handleClose = () => {
9258
content.value = '';
9359
open.value = false;
@@ -117,26 +83,12 @@ const acceptParams = (name: string, file: string, operate: string) => {
11783
req.file = file;
11884
req.operate = operate;
11985
120-
title.value = file == 'config' ? i18n.global.t('website.source') : i18n.global.t('commons.button.log');
12186
getContent();
12287
open.value = true;
12388
};
12489
125-
const cleanLog = async () => {
126-
let log = req.file === 'out.log' ? i18n.global.t('logs.runLog') : i18n.global.t('logs.errLog');
127-
opRef.value.acceptParams({
128-
title: i18n.global.t('commons.button.clean'),
129-
names: [req.name],
130-
msg: i18n.global.t('commons.msg.operatorHelper', [log, i18n.global.t('commons.button.clean')]),
131-
api: operateSupervisorProcessFile,
132-
params: { name: req.name, operate: 'clear', file: req.file },
133-
});
134-
};
135-
13690
const onCloseLog = async () => {
13791
tailLog.value = false;
138-
clearInterval(Number(timer));
139-
timer = null;
14092
};
14193
14294
onUnmounted(() => {

frontend/src/views/toolbox/supervisor/index.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<el-card v-if="showStopped" class="mask-prompt">
44
<span>{{ $t('tool.supervisor.notStartWarn') }}</span>
55
</el-card>
6-
<LayoutContent :title="$t('tool.supervisor.list', 2)" v-loading="loading">
6+
<LayoutContent :title="$t(' tool.supervisor.list', 2)" v-loading="loading">
77
<template #prompt v-if="!globalStore.isFxplay">
88
<el-alert type="info" :closable="false">
99
<template #title>
@@ -157,11 +157,14 @@
157157
</LayoutContent>
158158
<Create ref="createRef" @close="search"></Create>
159159
<File ref="fileRef" @search="search"></File>
160+
<Log ref="logRef" @close="search" />
160161
<ProcessDetail ref="processDetailRef" />
161162
</div>
162163
</template>
163164

164165
<script setup lang="ts">
166+
import Log from './log/index.vue';
167+
165168
import SuperVisorStatus from './status/index.vue';
166169
import { ref } from 'vue';
167170
import ConfigSuperVisor from './config/index.vue';
@@ -181,6 +184,7 @@ const loading = ref(false);
181184
const setSuperVisor = ref(false);
182185
const createRef = ref();
183186
const fileRef = ref();
187+
const logRef = ref();
184188
const processDetailRef = ref();
185189
const data = ref();
186190
const maskShow = ref(true);
@@ -324,6 +328,10 @@ const getFile = (name: string, file: string) => {
324328
fileRef.value.acceptParams(name, file, 'get');
325329
};
326330
331+
const openLog = (name: string) => {
332+
logRef.value.acceptParams(name);
333+
};
334+
327335
const edit = (row: HostTool.SupersivorProcess) => {
328336
createRef.value.acceptParams('update', row);
329337
};
@@ -344,7 +352,7 @@ const buttons = [
344352
{
345353
label: i18n.global.t('commons.button.log'),
346354
click: function (row: HostTool.SupersivorProcess) {
347-
getFile(row.name, 'out.log');
355+
openLog(row.name);
348356
},
349357
},
350358
{
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<template>
2+
<DrawerPro
3+
v-model="open"
4+
:header="$t('commons.button.log') + ' - ' + supervisorName"
5+
@close="handleClose"
6+
:size="globalStore.isFullScreen ? 'full' : 'large'"
7+
:fullScreen="true"
8+
>
9+
<template #content>
10+
<el-tabs v-model="tab" type="card" @tab-click="handleChange">
11+
<el-tab-pane :label="$t('logs.runLog')" name="out.log"></el-tab-pane>
12+
<el-tab-pane :label="$t('logs.errLog')" name="err.log"></el-tab-pane>
13+
</el-tabs>
14+
15+
<LogFile
16+
:key="logKey"
17+
ref="logRef"
18+
v-if="openLog"
19+
:config="logConfig"
20+
v-model:loading="loading"
21+
v-model:has-content="hasContent"
22+
:height-diff="300"
23+
>
24+
<template #button>
25+
<el-button @click="cleanLog" icon="Delete" :disabled="hasContent === false">
26+
{{ $t('commons.button.clean') }}
27+
</el-button>
28+
</template>
29+
</LogFile>
30+
</template>
31+
32+
<template #footer>
33+
<span>
34+
<el-button @click="handleClose" :disabled="loading">{{ $t('commons.button.cancel') }}</el-button>
35+
</span>
36+
</template>
37+
</DrawerPro>
38+
<OpDialog ref="opRef" @search="refreshLog" />
39+
</template>
40+
<script lang="ts" setup>
41+
import LogFile from '@/components/log/file/index.vue';
42+
43+
import { onUnmounted, reactive, ref } from 'vue';
44+
import { GlobalStore } from '@/store';
45+
import { operateSupervisorProcessFile } from '@/api/modules/host-tool';
46+
import i18n from '@/lang';
47+
import { TabsPaneContext } from 'element-plus';
48+
const globalStore = GlobalStore();
49+
50+
const logConfig = reactive({
51+
type: 'supervisor',
52+
id: undefined,
53+
name: '',
54+
colorMode: 'nginx',
55+
});
56+
const loading = ref(false);
57+
const open = ref(false);
58+
const tab = ref('out.log');
59+
const openLog = ref();
60+
const supervisorName = ref('');
61+
const opRef = ref();
62+
const logKey = ref(0);
63+
const hasContent = ref(false);
64+
65+
const em = defineEmits(['close']);
66+
67+
const handleChange = (tab: TabsPaneContext) => {
68+
openLog.value = false;
69+
logConfig.name = supervisorName.value + '.' + tab.props.name.toString();
70+
logKey.value++;
71+
openLog.value = true;
72+
};
73+
74+
const handleClose = () => {
75+
open.value = false;
76+
};
77+
78+
const acceptParams = (name: string) => {
79+
tab.value = 'out.log';
80+
supervisorName.value = name;
81+
logConfig.name = name + '.' + tab.value;
82+
open.value = true;
83+
openLog.value = true;
84+
};
85+
86+
const onCloseLog = async () => {
87+
em('close');
88+
};
89+
90+
const refreshLog = () => {
91+
logKey.value++;
92+
};
93+
94+
const cleanLog = async () => {
95+
let log = tab.value === 'out.log' ? i18n.global.t('logs.runLog') : i18n.global.t('logs.errLog');
96+
opRef.value.acceptParams({
97+
title: i18n.global.t('commons.button.clean'),
98+
names: [supervisorName.value],
99+
msg: i18n.global.t('commons.msg.operatorHelper', [log, i18n.global.t('commons.button.clean')]),
100+
api: operateSupervisorProcessFile,
101+
params: { name: supervisorName.value, operate: 'clear', file: tab.value },
102+
});
103+
};
104+
105+
onUnmounted(() => {
106+
onCloseLog();
107+
});
108+
109+
defineExpose({
110+
acceptParams,
111+
});
112+
</script>
113+
114+
<style scoped lang="scss">
115+
.fullScreen {
116+
border: none;
117+
}
118+
</style>

0 commit comments

Comments
 (0)