refactor: runtime logs page.

pull/3445/head
ruibaby 2019-12-19 11:05:06 +08:00
parent 44bf4b767a
commit 00064d1d47
5 changed files with 148 additions and 65 deletions

View File

@ -18,4 +18,67 @@ actuatorApi.env = () => {
}) })
} }
actuatorApi.getSystemCpuCount = () => {
return service({
url: `${baseUrl}/metrics/system.cpu.count`,
method: 'get'
})
}
actuatorApi.getSystemCpuUsage = () => {
return service({
url: `${baseUrl}/metrics/system.cpu.usage`,
method: 'get'
})
}
actuatorApi.getProcessUptime = () => {
return service({
url: `${baseUrl}/metrics/process.uptime`,
method: 'get'
})
}
actuatorApi.getProcessStartTime = () => {
return service({
url: `${baseUrl}/metrics/process.start.time`,
method: 'get'
})
}
actuatorApi.getProcessCpuUsage = () => {
return service({
url: `${baseUrl}/metrics/process.cpu.usage`,
method: 'get'
})
}
actuatorApi.getJvmMemoryMax = () => {
return service({
url: `${baseUrl}/metrics/jvm.memory.max`,
method: 'get'
})
}
actuatorApi.getJvmMemoryCommitted = () => {
return service({
url: `${baseUrl}/metrics/jvm.memory.committed`,
method: 'get'
})
}
actuatorApi.getJvmMemoryUsed = () => {
return service({
url: `${baseUrl}/metrics/jvm.memory.used`,
method: 'get'
})
}
actuatorApi.getJvmGcPause = () => {
return service({
url: `${baseUrl}/metrics/jvm.gc.pause`,
method: 'get'
})
}
export default actuatorApi export default actuatorApi

View File

@ -106,4 +106,14 @@ adminApi.restartApplication = () => {
}) })
} }
adminApi.getLogFiles = lines => {
return service({
url: `${baseUrl}/halo/logfile`,
params: {
lines: lines
},
method: 'get'
})
}
export default adminApi export default adminApi

View File

@ -21,7 +21,15 @@
label="网站地址:" label="网站地址:"
help="* 需要加上 http://" help="* 需要加上 http://"
> >
<a-input v-model="link.url" /> <a-input v-model="link.url">
<a
href="javascript:void(0);"
slot="addonAfter"
@click="handleParseUrl"
>
<a-icon type="sync" />
</a>
</a-input>
</a-form-item> </a-form-item>
<a-form-item label="Logo"> <a-form-item label="Logo">
<a-input v-model="link.logo" /> <a-input v-model="link.logo" />
@ -276,6 +284,11 @@ export default {
this.loadTeams() this.loadTeams()
}) })
}, },
handleParseUrl() {
linkApi.getByParse(this.link.url).then(response => {
this.link = response.data.data
})
},
createOrUpdateLink() { createOrUpdateLink() {
if (!this.link.name) { if (!this.link.name) {
this.$notification['error']({ this.$notification['error']({

View File

@ -19,27 +19,27 @@
<tbody class="ant-table-tbody"> <tbody class="ant-table-tbody">
<tr> <tr>
<td>系统</td> <td>系统</td>
<td>{{ systemProperties.properties['os.name'].value }} {{ systemProperties.properties['os.version'].value }}</td> <td>{{ systemProperties['os.name'].value }} {{ systemProperties['os.version'].value }}</td>
</tr> </tr>
<tr> <tr>
<td>平台</td> <td>平台</td>
<td>{{ systemProperties.properties['os.arch'].value }}</td> <td>{{ systemProperties['os.arch'].value }}</td>
</tr> </tr>
<tr> <tr>
<td>语言</td> <td>语言</td>
<td>{{ systemProperties.properties['user.language'].value }}</td> <td>{{ systemProperties['user.language'].value }}</td>
</tr> </tr>
<tr> <tr>
<td>时区</td> <td>时区</td>
<td>{{ systemProperties.properties['user.timezone'].value }}</td> <td>{{ systemProperties['user.timezone'].value }}</td>
</tr> </tr>
<tr> <tr>
<td>当前用户</td> <td>当前用户</td>
<td>{{ systemProperties.properties['user.name'].value }}</td> <td>{{ systemProperties['user.name'].value }}</td>
</tr> </tr>
<tr> <tr>
<td>用户目录</td> <td>用户目录</td>
<td>{{ systemProperties.properties['user.home'].value }}</td> <td>{{ systemProperties['user.home'].value }}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -109,11 +109,11 @@
<tbody class="ant-table-tbody"> <tbody class="ant-table-tbody">
<tr> <tr>
<td>Java 名称</td> <td>Java 名称</td>
<td>{{ systemProperties.properties['java.vm.name'].value }}</td> <td>{{ systemProperties['java.vm.name'].value }}</td>
</tr> </tr>
<tr> <tr>
<td>Java 版本</td> <td>Java 版本</td>
<td>{{ systemProperties.properties['java.version'].value }}</td> <td>{{ systemProperties['java.version'].value }}</td>
</tr> </tr>
<tr> <tr>
<td>Java Home</td> <td>Java Home</td>
@ -122,7 +122,7 @@
:length="isMobile() ? 50 : 256" :length="isMobile() ? 50 : 256"
tooltip tooltip
> >
{{ systemProperties.properties['java.home'].value }} {{ systemProperties['java.home'].value }}
</ellipsis> </ellipsis>
</td> </td>
</tr> </tr>
@ -149,15 +149,11 @@
<tbody class="ant-table-tbody"> <tbody class="ant-table-tbody">
<tr> <tr>
<td>端口</td> <td>端口</td>
<td>{{ propertiesSourcesMap['server.ports'].properties['local.server.port'].value }}</td> <td>{{ propertiesSourcesMap['server.ports']['local.server.port'].value }}</td>
</tr> </tr>
<tr> <tr>
<td>PID</td> <td>PID</td>
<td>{{ systemProperties.properties['PID'].value }}</td> <td>{{ systemProperties['PID'].value }}</td>
</tr>
<tr>
<td>启动模式</td>
<td>{{ systemProperties.properties['spring.profiles.active'].value }}</td>
</tr> </tr>
<tr> <tr>
<td>启动时间</td> <td>启动时间</td>
@ -174,7 +170,7 @@
:length="isMobile() ? 50 : 256" :length="isMobile() ? 50 : 256"
tooltip tooltip
> >
{{ systemProperties.properties['user.dir'].value }} {{ systemProperties['user.dir'].value }}
</ellipsis> </ellipsis>
</td> </td>
</tr> </tr>
@ -185,7 +181,7 @@
:length="isMobile() ? 50 : 256" :length="isMobile() ? 50 : 256"
tooltip tooltip
> >
{{ systemProperties.properties['LOG_FILE'].value }} {{ systemProperties['LOG_FILE'].value }}
</ellipsis> </ellipsis>
</td> </td>
</tr> </tr>
@ -207,8 +203,6 @@
</template> </template>
<script> <script>
import { mixin, mixinDevice } from '@/utils/mixin.js' import { mixin, mixinDevice } from '@/utils/mixin.js'
import { mapGetters } from 'vuex'
import axios from 'axios'
import actuatorApi from '@/api/actuator' import actuatorApi from '@/api/actuator'
export default { export default {
name: 'Environment', name: 'Environment',
@ -216,7 +210,7 @@ export default {
data() { data() {
return { return {
propertiesSourcesMap: {}, propertiesSourcesMap: {},
systemProperties: {}, systemProperties: [],
interval: null, interval: null,
system: { system: {
cpu: { cpu: {
@ -248,57 +242,46 @@ export default {
this.loadSystemInfo() this.loadSystemInfo()
this.loadJvmInfo() this.loadJvmInfo()
}, },
computed: {
...mapGetters(['options'])
},
methods: { methods: {
loadEnv() { loadEnv() {
actuatorApi.env().then(response => { actuatorApi.env().then(response => {
const propertiesSources = response.data.propertySources const propertiesSources = response.data.propertySources
propertiesSources.forEach(item => { propertiesSources.forEach(item => {
this.propertiesSourcesMap[item.name] = item this.propertiesSourcesMap[item.name] = item.properties
this.systemProperties = this.propertiesSourcesMap['systemProperties']
}) })
this.systemProperties = this.propertiesSourcesMap['systemProperties']
}) })
}, },
loadSystemInfo() { loadSystemInfo() {
axios actuatorApi.getSystemCpuCount().then(response => {
.all([ this.system.cpu.count = response.data.measurements[0].value
axios.get(this.options.blog_url + '/api/admin/actuator/metrics/system.cpu.count'), })
axios.get(this.options.blog_url + '/api/admin/actuator/metrics/system.cpu.usage'), actuatorApi.getSystemCpuUsage().then(response => {
axios.get(this.options.blog_url + '/api/admin/actuator/metrics/process.uptime'), this.system.cpu.usage = Number(response.data.measurements[0].value * 100).toFixed(2)
axios.get(this.options.blog_url + '/api/admin/actuator/metrics/process.start.time'), })
axios.get(this.options.blog_url + '/api/admin/actuator/metrics/process.cpu.usage') actuatorApi.getProcessUptime().then(response => {
]) this.system.process.uptime = response.data.measurements[0].value
.then(response => { })
this.system.cpu.count = response[0].data.measurements[0].value actuatorApi.getProcessStartTime().then(response => {
this.system.cpu.usage = Number(response[1].data.measurements[0].value * 100).toFixed(2) this.system.process.startTime = response.data.measurements[0].value * 1000
this.system.process.uptime = response[2].data.measurements[0].value })
this.system.process.startTime = response[3].data.measurements[0].value * 1000 actuatorApi.getProcessCpuUsage().then(response => {
this.system.process.cpuUsage = response[4].data.measurements[0].value this.system.process.cpuUsage = response.data.measurements[0].value
}) })
.catch(response => {
this.$message.error('获取服务器系统信息失败!')
})
}, },
loadJvmInfo() { loadJvmInfo() {
axios actuatorApi.getJvmMemoryMax().then(response => {
.all([ this.jvm.memory.max = response.data.measurements[0].value
axios.get(this.options.blog_url + '/api/admin/actuator/metrics/jvm.memory.max'), })
axios.get(this.options.blog_url + '/api/admin/actuator/metrics/jvm.memory.committed'), actuatorApi.getJvmMemoryCommitted().then(response => {
axios.get(this.options.blog_url + '/api/admin/actuator/metrics/jvm.memory.used'), this.jvm.memory.committed = response.data.measurements[0].value
axios.get(this.options.blog_url + '/api/admin/actuator/metrics/jvm.gc.pause') })
]) actuatorApi.getJvmMemoryUsed().then(response => {
.then(r => { this.jvm.memory.used = response.data.measurements[0].value
this.jvm.memory.max = r[0].data.measurements[0].value })
this.jvm.memory.committed = r[1].data.measurements[0].value actuatorApi.getJvmGcPause().then(response => {
this.jvm.memory.used = r[2].data.measurements[0].value this.jvm.gc.pause.count = response.data.measurements[0].value
this.jvm.gc.pause.count = r[3].data.measurements[0].value })
})
.catch(r => {
console.error(r)
this.$message.error('获取 JVM 信息失败!')
})
}, },
handleRefresh() { handleRefresh() {
this.loadSystemInfo() this.loadSystemInfo()

View File

@ -17,6 +17,16 @@
type="primary" type="primary"
style="margin-right: 8px;" style="margin-right: 8px;"
>下载</a-button> >下载</a-button>
<a-select
defaultValue="200"
style="margin-right: 8px;width: 100px"
@change="handleLinesChange"
>
<a-select-option value="200">200 </a-select-option>
<a-select-option value="500">500 </a-select-option>
<a-select-option value="800">800 </a-select-option>
<a-select-option value="1000">1000 </a-select-option>
</a-select>
<a-button <a-button
type="dash" type="dash"
@click="()=>this.loadLogs()" @click="()=>this.loadLogs()"
@ -27,7 +37,7 @@
<script> <script>
import { codemirror } from 'vue-codemirror-lite' import { codemirror } from 'vue-codemirror-lite'
import 'codemirror/mode/shell/shell.js' import 'codemirror/mode/shell/shell.js'
import actuatorApi from '@/api/actuator' import adminApi from '@/api/admin'
export default { export default {
name: 'RuntimeLogs', name: 'RuntimeLogs',
components: { components: {
@ -42,7 +52,8 @@ export default {
line: true line: true
}, },
logContent: '', logContent: '',
loading: true loading: true,
logLines: 200
} }
}, },
created() { created() {
@ -51,10 +62,13 @@ export default {
methods: { methods: {
loadLogs() { loadLogs() {
this.loading = true this.loading = true
actuatorApi.logfile().then(response => { adminApi.getLogFiles(this.logLines).then(response => {
this.logContent = response.data this.logContent = response.data.data
this.loading = false this.loading = false
}) })
},
handleLinesChange(value) {
this.logLines = value
} }
} }
} }