import React from 'react'; import superagent from 'superagent'; import { fromUnixTime, formatDistanceToNow } from "date-fns"; import { formatInTimeZone } from 'date-fns-tz' import {Button, Header, Label, Table, Image, Icon, Progress} from 'semantic-ui-react'; import NetworkWrapper from './NetworkWrapper.jsx'; import { DEFAULT_TIMEZONE } from '../CloudApi/Constants.js'; // This is an arbitrary estimate of the maximum number of peers per c5.large server. const ESTIMATED_MAX_PEERS_PER_SERVER = 180.0; class MediaServerRow extends React.Component { constructor(props) { super(props); } async setActivationStatus(activationStatus, e) { await superagent.put(`/cloud/admin/network/media-server/${this.props.server.mediaServerId}`).accept('json') .send({ activationStatus }); } render() { if (!this.props.server) { return
; } const createdAt = formatInTimeZone(new Date(this.props.server.createdAt), DEFAULT_TIMEZONE, 'PPPp z'); const uptime = formatDistanceToNow(new Date(this.props.server.createdAt)); const status = ; const activationStatus = this.props.server.activationStatus === "Retired" ? : ; const accelerated = this.props.server.isAccelerated && return ( {activationStatus} {this.props.server.name} {status}{accelerated} {this.props.server.ipAddress} {this.props.server.minPort}-{this.props.server.maxPort} {this.props.server.instanceType} ({this.props.server.instanceId}) {this.props.server.region} {this.props.server.load} {(this.props.server.load / ESTIMATED_MAX_PEERS_PER_SERVER * 100.0).toFixed(1)}% {uptime} {this.props.server.activationStatus == "Active" && } {this.props.server.activationStatus == "Retired" && } ) } } export default class MediaServers extends React.Component { constructor(props) { super(props); this.state = { servers: [], loading: false }; } async componentDidMount() { this.setState({ loading: true }); const res = await superagent.get(`/cloud/admin/network/media-servers`).accept('json'); console.log(res.body); this.setState({ loading: false, servers: res.body}); } render() { const networkCapacity = this.state.servers.length * ESTIMATED_MAX_PEERS_PER_SERVER; const networkUsage = _.sum(this.state.servers.map(server => server.load)); const capacityPercentage = (networkUsage / networkCapacity * 100.0).toFixed(1); return (
Network Usage ({networkUsage}/{networkCapacity})
Status Server Public IP Port Range Server Type Region Current Connections Estimated Load Uptime Tools {this.state.servers.map(server => { return ( ); })}

"Retired" - will serve active connections but won't take on new ones. Used before shutting down a server.

); } }