|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- <template>
- <div v-loading="!show" element-loading-text="数据加载中..." :style="!show ? 'height: 500px' : 'height: 100%'" class="app-container">
- <div v-if="show">
- <el-card class="box-card">
- <div style="color: #666;font-size: 13px;">
- <svg-icon icon-class="system" style="margin-right: 5px" />
- <span>
- 系统:{{ data.sys.os }}
- </span>
- <span>
- IP:{{ data.sys.ip }}
- </span>
- <span>
- 项目已不间断运行:{{ data.sys.day }}
- </span>
- <i class="el-icon-refresh" style="margin-left: 40px" @click="init" />
- </div>
- </el-card>
- <el-card class="box-card">
- <div slot="header" class="clearfix">
- <span style="font-weight: bold;color: #666;font-size: 15px">状态</span>
- </div>
- <div>
- <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6" style="margin-bottom: 10px">
- <div class="title">CPU使用率</div>
- <el-tooltip placement="top-end">
- <div slot="content" style="font-size: 12px;">
- <div style="padding: 3px;">
- {{ data.cpu.name }}
- </div>
- <div style="padding: 3px">
- {{ data.cpu.package }}
- </div>
- <div style="padding: 3px">
- {{ data.cpu.core }}
- </div>
- <div style="padding: 3px">
- {{ data.cpu.logic }}
- </div>
- </div>
- <div class="content">
- <el-progress type="dashboard" :percentage="parseFloat(data.cpu.used)" />
- </div>
- </el-tooltip>
- <div class="footer">{{ data.cpu.coreNumber }} 核心</div>
- </el-col>
- <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6" style="margin-bottom: 10px">
- <div class="title">内存使用率</div>
- <el-tooltip placement="top-end">
- <div slot="content" style="font-size: 12px;">
- <div style="padding: 3px;">
- 总量:{{ data.memory.total }}
- </div>
- <div style="padding: 3px">
- 已使用:{{ data.memory.used }}
- </div>
- <div style="padding: 3px">
- 空闲:{{ data.memory.available }}
- </div>
- </div>
- <div class="content">
- <el-progress type="dashboard" :percentage="parseFloat(data.memory.usageRate)" />
- </div>
- </el-tooltip>
- <div class="footer">{{ data.memory.used }} / {{ data.memory.total }}</div>
- </el-col>
- <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6" style="margin-bottom: 10px">
- <div class="title">交换区使用率</div>
- <el-tooltip placement="top-end">
- <div slot="content" style="font-size: 12px;">
- <div style="padding: 3px;">
- 总量:{{ data.swap.total }}
- </div>
- <div style="padding: 3px">
- 已使用:{{ data.swap.used }}
- </div>
- <div style="padding: 3px">
- 空闲:{{ data.swap.available }}
- </div>
- </div>
- <div class="content">
- <el-progress type="dashboard" :percentage="parseFloat(data.swap.usageRate)" />
- </div>
- </el-tooltip>
- <div class="footer">{{ data.swap.used }} / {{ data.swap.total }}</div>
- </el-col>
- <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6" style="margin-bottom: 10px">
- <div class="title">磁盘使用率</div>
- <div class="content">
- <el-tooltip placement="top-end">
- <div slot="content" style="font-size: 12px;">
- <div style="padding: 3px">
- 总量:{{ data.disk.total }}
- </div>
- <div style="padding: 3px">
- 空闲:{{ data.disk.available }}
- </div>
- </div>
- <div class="content">
- <el-progress type="dashboard" :percentage="parseFloat(data.disk.usageRate)" />
- </div>
- </el-tooltip>
- </div>
- <div class="footer">{{ data.disk.used }} / {{ data.disk.total }}</div>
- </el-col>
- </div>
- </el-card>
-
- <div>
- <el-row :gutter="6">
- <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12" style="margin-bottom: 10px">
- <el-card class="box-card">
- <div slot="header" class="clearfix">
- <span style="font-weight: bold;color: #666;font-size: 15px">CPU使用率监控</span>
- </div>
- <div>
- <v-chart :options="cpuInfo" />
- </div>
- </el-card>
- </el-col>
- <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12" style="margin-bottom: 10px">
- <el-card class="box-card">
- <div slot="header" class="clearfix">
- <span style="font-weight: bold;color: #666;font-size: 15px">内存使用率监控</span>
- </div>
- <div>
- <v-chart :options="memoryInfo" />
- </div>
- </el-card>
- </el-col>
- </el-row>
- </div>
- </div>
- </div>
- </template>
-
- <script>
- import ECharts from 'vue-echarts'
- import 'echarts/lib/chart/line'
- import 'echarts/lib/component/polar'
- import { initData } from '@/api/data'
- export default {
- name: 'ServerMonitor',
- components: {
- 'v-chart': ECharts
- },
- data() {
- return {
- show: false,
- monitor: null,
- url: 'api/monitor',
- data: {},
- cpuInfo: {
- tooltip: {
- trigger: 'axis'
- },
- xAxis: {
- type: 'category',
- boundaryGap: false,
- data: []
- },
- yAxis: {
- type: 'value',
- min: 0,
- max: 100,
- interval: 20
- },
- series: [{
- data: [],
- type: 'line',
- areaStyle: {
- normal: {
- color: 'rgb(32, 160, 255)' // 改变区域颜色
- }
- },
- itemStyle: {
- normal: {
- color: '#6fbae1',
- lineStyle: {
- color: '#6fbae1' // 改变折线颜色
- }
- }
- }
- }]
- },
- memoryInfo: {
- tooltip: {
- trigger: 'axis'
- },
- xAxis: {
- type: 'category',
- boundaryGap: false,
- data: []
- },
- yAxis: {
- type: 'value',
- min: 0,
- max: 100,
- interval: 20
- },
- series: [{
- data: [],
- type: 'line',
- areaStyle: {
- normal: {
- color: 'rgb(32, 160, 255)' // 改变区域颜色
- }
- },
- itemStyle: {
- normal: {
- color: '#6fbae1',
- lineStyle: {
- color: '#6fbae1' // 改变折线颜色
- }
- }
- }
- }]
- }
- }
- },
- created() {
- this.init()
- this.monitor = window.setInterval(() => {
- setTimeout(() => {
- this.init()
- }, 2)
- }, 3500)
- },
- destroyed() {
- clearInterval(this.monitor)
- },
- methods: {
- init() {
- initData(this.url, {}).then(data => {
- this.data = data
- this.show = true
- if (this.cpuInfo.xAxis.data.length >= 8) {
- this.cpuInfo.xAxis.data.shift()
- this.memoryInfo.xAxis.data.shift()
- this.cpuInfo.series[0].data.shift()
- this.memoryInfo.series[0].data.shift()
- }
- this.cpuInfo.xAxis.data.push(data.time)
- this.memoryInfo.xAxis.data.push(data.time)
- this.cpuInfo.series[0].data.push(parseFloat(data.cpu.used))
- this.memoryInfo.series[0].data.push(parseFloat(data.memory.usageRate))
- })
- }
- }
- }
- </script>
-
- <style rel="stylesheet/scss" lang="scss" scoped>
- ::v-deep .box-card {
- margin-bottom: 5px;
- span {
- margin-right: 28px;
- }
- .el-icon-refresh {
- margin-right: 10px;
- float: right;
- cursor:pointer;
- }
- }
- .cpu, .memory, .swap, .disk {
- width: 20%;
- float: left;
- padding-bottom: 20px;
- margin-right: 5%;
- }
- .title {
- text-align: center;
- font-size: 15px;
- font-weight: 500;
- color: #999;
- margin-bottom: 16px;
- }
- .footer {
- text-align: center;
- font-size: 15px;
- font-weight: 500;
- color: #999;
- margin-top: -5px;
- margin-bottom: 10px;
- }
- .content {
- text-align: center;
- margin-top: 5px;
- margin-bottom: 5px;
- }
- </style>
|