// Copyright 2022 The Casdoor Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. import {Card, Col, Divider, Progress, Row, Spin, Tour} from "antd"; import * as SystemBackend from "./backend/SystemInfo"; import React from "react"; import * as Setting from "./Setting"; import * as TourConfig from "./TourConfig"; import i18next from "i18next"; import PrometheusInfoTable from "./table/PrometheusInfoTable"; class SystemInfo extends React.Component { constructor(props) { super(props); this.state = { systemInfo: {cpuUsage: [], memoryUsed: 0, memoryTotal: 0}, versionInfo: {}, prometheusInfo: {apiThroughput: [], apiLatency: [], totalThroughput: 0}, intervalId: null, loading: true, isTourVisible: TourConfig.getTourVisible(), }; } UNSAFE_componentWillMount() { SystemBackend.getSystemInfo("").then(res => { this.setState({ systemInfo: res.data, loading: false, }); const id = setInterval(() => { SystemBackend.getSystemInfo("").then(res => { this.setState({ systemInfo: res.data, }); }).catch(error => { Setting.showMessage("error", `System info failed to get: ${error}`); }); SystemBackend.getPrometheusInfo().then(res => { this.setState({ prometheusInfo: res.data, }); }); }, 1000 * 2); this.setState({intervalId: id}); }).catch(error => { Setting.showMessage("error", `System info failed to get: ${error}`); }); SystemBackend.getVersionInfo().then(res => { this.setState({ versionInfo: res.data, }); }).catch(err => { Setting.showMessage("error", `Version info failed to get: ${err}`); }); } componentDidMount() { window.addEventListener("storageTourChanged", this.handleTourChange); } handleTourChange = () => { this.setState({isTourVisible: TourConfig.getTourVisible()}); }; componentWillUnmount() { if (this.state.intervalId !== null) { clearInterval(this.state.intervalId); } window.removeEventListener("storageTourChanged", this.handleTourChange); } setIsTourVisible = () => { TourConfig.setIsTourVisible(false); this.setState({isTourVisible: false}); }; handleTourComplete = () => { const nextPathName = TourConfig.getNextUrl(); if (nextPathName !== "") { this.props.history.push("/" + nextPathName); TourConfig.setIsTourVisible(true); } }; getSteps = () => { const nextPathName = TourConfig.getNextUrl(); const steps = TourConfig.getSteps(); steps.map((item, index) => { item.target = () => document.getElementById(item.id) || null; if (index === steps.length - 1) { item.nextButtonProps = { children: TourConfig.getNextButtonChild(nextPathName), }; } }); return steps; }; render() { const cpuUi = this.state.systemInfo.cpuUsage?.length <= 0 ? i18next.t("system:Failed to get CPU usage") : this.state.systemInfo.cpuUsage.map((usage, i) => { return ( ); }); const memUi = this.state.systemInfo.memoryUsed && this.state.systemInfo.memoryTotal && this.state.systemInfo.memoryTotal <= 0 ? i18next.t("system:Failed to get memory usage") :
{Setting.getFriendlyFileSize(this.state.systemInfo.memoryUsed)} / {Setting.getFriendlyFileSize(this.state.systemInfo.memoryTotal)}

; const latencyUi = this.state.prometheusInfo.apiLatency === null || this.state.prometheusInfo.apiLatency?.length <= 0 ? : ; const throughputUi = this.state.prometheusInfo.apiThroughput === null || this.state.prometheusInfo.apiThroughput?.length <= 0 ? : ; const link = this.state.versionInfo?.version !== "" ? `https://github.com/casdoor/casdoor/releases/tag/${this.state.versionInfo?.version}` : ""; let versionText = this.state.versionInfo?.version !== "" ? this.state.versionInfo?.version : i18next.t("system:Unknown version"); if (this.state.versionInfo?.commitOffset > 0) { versionText += ` (ahead+${this.state.versionInfo?.commitOffset})`; } if (!Setting.isMobile()) { return ( <> {this.state.loading ? : cpuUi} {this.state.loading ? : memUi} {this.state.loading ? : latencyUi} {this.state.loading ? : throughputUi}
{i18next.t("system:An Identity and Access Management (IAM) / Single-Sign-On (SSO) platform with web UI supporting OAuth 2.0, OIDC, SAML and CAS")}
GitHub: Casdoor
{i18next.t("system:Version")}: {versionText}
{i18next.t("system:Official website")}: https://casdoor.org
{i18next.t("system:Community")}: Get in Touch!
( {current + 1} / {total} )} onFinish={this.handleTourComplete} /> ); } else { return ( {this.state.loading ? : cpuUi} {this.state.loading ? : memUi}
{i18next.t("system:An Identity and Access Management (IAM) / Single-Sign-On (SSO) platform with web UI supporting OAuth 2.0, OIDC, SAML and CAS")}
GitHub: Casdoor
{i18next.t("system:Version")}: {versionText}
{i18next.t("system:Official website")}: https://casdoor.org
{i18next.t("system:Community")}: Get in Touch!
); } } } export default SystemInfo;