sevMonitor.js 10.1 KB
import React,{Component} from 'react';
import './style.less';
import WhiteBar from '../../components/Common/WhiteBar';
import {Row,Col,Table,Icon} from 'antd';
import { API_SYS_MONITOR } from '@src/Api';
import axios from '@src/axios/index';

export default class AccessLog extends Component {
	state = {
		serverInfo: {}
	}
	componentDidMount () {
		this.getServerInfo();
	}
	// 获取服务器信息
	getServerInfo = () => {
		axios.ajax({
			url: API_SYS_MONITOR.getServerInfo,
		}).then((res) => {
			res.diskStats = res.diskStats.map((item,index) => {
				return {...item,key:index}
			});
			this.setState({serverInfo: res});
		});
	}
	render () {
		const columns = [
			{title: '序号', dataIndex: 'key', key: 'key', render: (key) => {
				return key + 1;
			}},
			{title: '盘符路径', dataIndex: 'diskPath', key: 'diskPath'},
			{title: '文件系统', dataIndex: 'fileSystem', key: 'fileSystem'},
			{title: '盘符类型', dataIndex: 'diskType', key: 'diskType'},
			{title: '总大小', dataIndex: 'allSpace', key: 'allSpace'},
			{title: '可用大小', dataIndex: 'availableSpace', key: 'availableSpace'},
			{title: '已用大小', dataIndex: 'usedSpace', key: 'usedSpace'},
			{title: '已用百分百', dataIndex: 'usedPct', key: 'usedPct'}
		];
		const serverInfo  = this.state.serverInfo;
		return (
			<div className="com-sevMonitor">
				<WhiteBar title="服务器监控" />
				<div className="panel-wrapper">
					<Row gutter={16}>
						<Col span={8}>
							<Panel 
								title="CUP"
								icon="iconfont icon-cpu"
								background="linear-gradient(86deg,rgba(9,141,239,1),rgba(45,159,242,1))">
								<ul>
									<li className="title clear">
										<p className="f_left">属性</p>
										<p className="f_right"></p>
									</li>
									<li className="clear">
										<p className="item f_left">核心数</p>
										<p className="f_right">{serverInfo.cpuNum}</p>
									</li>
									<li className="clear">
										<p className="item f_left">最大功率</p>
										<p className="f_right">{serverInfo.cpuMaxGhz}</p>
									</li>
									<li className="clear">
										<p className="item f_left">实时功率</p>
										<p className="f_right">{serverInfo.cpuNowGhz}</p>
									</li>
									<li className="clear">
										<p className="item f_left">使用率</p>
										<p className="f_right">{serverInfo.cpuPct}</p>
									</li>
								</ul>
							</Panel>
						</Col>
						<Col span={8}>
							<Panel 
								title="内存"
								icon="iconfont icon-neicun"
								background="linear-gradient(86deg,rgba(73,209,183,1),rgba(97,235,213,1))">
								<ul>
									<li className="title clear">
										<p className="w_30">属性</p>
										<p className="w_30">内存</p>
										<p className="w_30">JVM</p>
									</li>
									<li className="clear">
										<p className="item w_30">总内存</p>
										<p className="w_30">{serverInfo.memAll}</p>
										<p className="w_30">{serverInfo.jvmAll}</p>
									</li>
									<li className="clear">
										<p className="item w_30">剩余内存</p>
										<p className="w_30">{serverInfo.memRest}</p>
										<p className="w_30">{serverInfo.jvmRest}</p>
									</li>
									<li className="clear">
										<p className="item w_30">已用内存</p>
										<p className="w_30">{serverInfo.memUsed}</p>
										<p className="w_30">{serverInfo.jvmUsed}</p>
									</li>
									<li className="clear">
										<p className="item w_30">使用率</p>
										<p className="w_30">{serverInfo.memPct}</p>
										<p className="w_30">{serverInfo.jvmPct}</p>
									</li>
								</ul>
							</Panel>
						</Col>
						<Col span={8}>
							<Panel 
								title="堆/堆栈"
								icon="iconfont icon-dui"
								background="linear-gradient(86deg,rgba(254,156,12,1),rgba(252,194,59,1))">
								<ul>
									<li className="title clear">
										<p className="w_30">属性</p>
										<p className="w_30"></p>
										<p className="w_30">堆栈</p>
									</li>
									<li className="clear">
										<p className="item w_30">初始大小</p>
										<p className="w_30">{serverInfo.heapInit}</p>
										<p className="w_30">{serverInfo.nonHeapInit}</p>
									</li>
									<li className="clear">
										<p className="item w_30">最大内存</p>
										<p className="w_30">{serverInfo.heapMaxMem}</p>
										<p className="w_30">{serverInfo.nonHeapMaxMem}</p>
									</li>
									<li className="clear">
										<p className="item w_30">已用内存</p>
										<p className="w_30">{serverInfo.heapUsedMem}</p>
										<p className="w_30">{serverInfo.nonHeapUsedMem}</p>
									</li>
									<li className="clear">
										<p className="item w_30">可用内存</p>
										<p className="w_30">{serverInfo.heapAvailableMem}</p>
										<p className="w_30">{serverInfo.nonHeapAvailableMem}</p>
									</li>
								</ul>
							</Panel>
						</Col>
					</Row>
					<Row gutter={16} style={{marginTop: 20}}>
						<Col span={12}>
							<Panel 
								title="服务信息"
								icon="iconfont icon-server"
								background="linear-gradient(90deg,rgba(86,104,219,1),rgba(125,139,226,1))">
								<ul>
									<li className="clear">
										<p className="item f_left">服务器名称</p>
										<p className="f_right">{serverInfo.serverName}</p>
									</li>
									<li className="clear">
										<p className="item f_left">服务器IP</p>
										<p className="f_right">{serverInfo.serverIp}</p>
									</li>
									<li className="clear">
										<p className="item f_left">操作系统</p>
										<p className="f_right">{serverInfo.operationName}</p>
									</li>
									<li className="clear">
										<p className="item f_left">系统架构</p>
										<p className="f_right">{serverInfo.systemArch}</p>
									</li>
								</ul>
							</Panel>
						</Col>
						<Col span={12}>
							<Panel 
								title="平台参数"
								icon="iconfont icon-argu"
								background="linear-gradient(90deg,rgba(86,104,219,1),rgba(125,139,226,1))">
								<ul>
									<li className="clear">
										<p className="item f_left">当前工作路径</p>
										<p className="f_right">{serverInfo.currentWorkPath}</p>
									</li>
									<li className="clear">
										<p className="item f_left">日志存放路径</p>
										<p className="f_right">{serverInfo.logSavePath}</p>
									</li>
									<li className="clear">
										<p className="item f_left">上传文件路径</p>
										<p className="f_right">{serverInfo.uploadFilePath}</p>
									</li>
									<li className="clear">
										<p className="item f_left">系统架构</p>
										<p className="f_right">{serverInfo.systemArch}</p>
									</li>
								</ul>
							</Panel>
						</Col>
					</Row>
					<Row style={{marginTop: 20}}>
						<Col span={24}>
							<Panel 
								title="java虚拟机问题"
								icon="iconfont icon-xuniji"
								background="linear-gradient(90deg,rgba(86,104,219,1),rgba(125,139,226,1))">
								<ul>
									<li>
										<p className="w_50">
											<span className="item mr_50">java名称</span>
											<span>{serverInfo.javaName}</span>
										</p>
										<p className="w_50">
											<span className="item mr_50">java版本</span>
											<span>{serverInfo.javaVersion}</span>
										</p>
									</li>
									<li>
										<p className="w_50">
											<span className="item mr_50">启动时间</span>
											<span>{serverInfo.startTime}</span>
										</p>
										<p className="w_50">
											<span className="item mr_50">运行时长</span>
											<span>{serverInfo.runTime}</span>
										</p>
									</li>
									<li>
										<p className="w_50">
											<span className="item mr_50">安装路径</span>
											<span>{serverInfo.javaHome}</span>
										</p>
										<p className="w_50">
											<span className="item mr_50">启动参数</span>
											<span>{serverInfo.startParam}</span>
										</p>
									</li>
								</ul>
							</Panel>
						</Col>
					</Row>
					<Row style={{marginTop: 20,marginBottom: 30}}>
						<Panel 
							title="磁盘状态"
							icon="iconfont icon-cipan"
							background="linear-gradient(90deg,rgba(86,104,219,1),rgba(125,139,226,1))">
							<Table 
							dataSource={serverInfo.diskStats}
							pagination={{hideOnSinglePage: true}}
							columns={columns}>
							</Table>
						</Panel>
					</Row>
				</div>
			</div>
		);
	}
}

// 面板组件
class Panel extends Component {
	state = {
		// true 展开 false 折叠
		collapse: true, 
		// 样式控制
		textStyle: {
			background: '#fff',
			padding: 15,
			transition: 'all ease .3s',
			overflow: 'hidden'
		},
		// iconstyle
		iconStyle: {
			float: 'right',
			marginTop: 12,
			transition: 'transform ease .3s',
		}
	}
	// 点击事件
	handleCollapse () {
		if (this.state.collapse) {
			// 折叠起来
			this.setState({
				collapse: false,
				textStyle: {
					background: '#fff',
					padding: 0,
					transition: 'all ease .3s',
					height: 0,
					overflow: 'hidden'
				},
				iconStyle: {
					float: 'right',
					marginTop: 12,
					transition: 'transform ease .3s',
					transform: 'rotate(90deg)'
				}
			});
		} else {
			// 展开
			this.setState({
				collapse: true,
				textStyle: {
					background: '#fff',
					padding: 15,
					transition: 'all ease .3s',
					overflow: 'hidden'
				},
				iconStyle: {
					float: 'right',
					marginTop: 12,
					transition: 'transform ease .3s'
				}
			});
		}
	}
	render () {
		const headerStyle = {
			width: '100%',
			height: '42px',
			lineHeight: '42px',
			background: this.props.background,
			color: '#fff',
			paddingLeft: 20,
			paddingRight: 20,
			cursor: 'pointer'
		};
		return (
			<div>
				<div onClick={this.handleCollapse.bind(this)} style={{...headerStyle}} className="header">
					<span style={{fontSize: 30,verticalAlign:'middle',marginRight: 5}} className={this.props.icon}></span>
					{this.props.title}
					<Icon style={{...this.state.iconStyle}} type="caret-down" theme="filled" />
				</div>
				<div style={{...this.state.textStyle}} className="textWrapper">
					{this.props.children}
				</div>
			</div>
		);
	}
}