import React from 'react'; import Server from './Server.jsx'; import axios from 'axios'; import { Circle } from 'rc-progress'; export default class Status extends React.Component { constructor(props) { super(props); this.state = { fetching: true, statuses: {}, error: '', serverId: '', foundInfo: { shard: '', cluster: '' }, foundInfoError: '', percentage: 0, onlineOffline: '', }; } async componentDidMount() { this.getStatus(); } getStatus = async () => { try { this.setState({ fetching: true }); let statusRequest = await axios.get('/api/status'); const totalShards = 864; let connectedShards = 0; for (let server in statusRequest.data) { statusRequest.data[server].forEach(function(cluster) { let connectedCount = 0; if (cluster.result) connectedCount += cluster.result.connectedCount; connectedShards += connectedCount || 0; }); } let percentage = (connectedShards / totalShards) * 100; percentage = percentage.toFixed(0); this.setState({ statuses: statusRequest.data, fetching: false, percentage, onlineOffline: `${connectedShards} / ${totalShards}` }); this.findInfo(); } catch (e) { this.setState({ error: 'Failed to load status, trying again in 30 seconds.', fetching: false }); } setTimeout(this.getStatus, 30 * 1000); } onServerIDChange = (serverId) => { this.setState({ serverId: serverId.target.value }); } findInfo = () => { this.setState({ foundInfo: { shard: '', cluster: '' }, foundInfoError: ''}) if (this.state.serverId === '') return; let serverId = this.state.serverId.match(/(\d{15,})/); const totalShards = 864; if (serverId === null || serverId[1] === undefined) { this.setState({ foundInfo: { shard: '', cluster: '' }, foundInfoError: 'Invalid Server ID'}); return; } let shard = ~~((serverId[1]*1 / 4194304) % totalShards); let cluster = 0; Object.keys(this.state.statuses).forEach(server => { if (cluster !== 0) { return; } let search = this.state.statuses[server].find(i => (i.result && i.result.shards.includes(shard)) || (i.guessedShards && i.guessedShards.includes(shard))); if (search !== undefined) { cluster = server[0] + search.id; return; } }); if (cluster === 0) { cluster = 'unknown'; } this.setState({ foundInfo: { shard, cluster }, foundInfoError: ''}) } render() { let servers; let foundInfo; let hasLoaded = !!Object.keys(this.state.statuses).length; let percent = this.state.percentage; let shards = this.state.onlineOffline; if (this.state.foundInfoError !== '') { foundInfo = (

{this.state.foundInfoError}

); } if (this.state.foundInfo.shard !== '') { foundInfo = (

This server is on shard #{this.state.foundInfo.shard} which is on cluster {this.state.foundInfo.cluster}. The cluster has been highlighted blue, hover over it to see if there's any problems with it.

); } if (this.state.error === '') { servers = Object.keys(this.state.statuses).map(server => ); } let fetching = (

This page auto-updates every 30 seconds.

); if (this.state.fetching) { fetching = (

Getting status information, please wait...

); } return (
{fetching}
{hasLoaded ? (

Find info

{foundInfo}
) : ''}

{this.state.error}

Legend:

Operational
Partial Outage
Major Outage
IPC Timeout

Hover over a cluster for more information.

  • {percent}% online
  • {shards} shards connected
{servers}
); } }