mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
Show System metrics in hosts page
Implement simple collection of basic real time system metrics of hosts and the controller for the purpose of displaying them in the Web UI. The metrics are collected by the controller at a configurable interval and pushed out to web clients currently subscribed to the metrics.
This commit is contained in:
1 parent
69bdc8e884
commit
d64bf6015e
13 files changed
+409
-7
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import React, { useContext, useRef, useState, useEffect } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Button, Form, InputNumber, Modal, Table, Tag, Typography } from "antd";
|
||||
import { Button, Flex, Form, InputNumber, Modal, Progress, Switch, Table, Tag, Typography } from "antd";
|
||||
import CopyOutlined from "@ant-design/icons/lib/icons/CopyOutlined";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
@@ -10,7 +10,12 @@ import ControlContext from "./ControlContext";
|
||||
import PageHeader from "./PageHeader";
|
||||
import PageLayout from "./PageLayout";
|
||||
import PluginExtra from "./PluginExtra";
|
||||
import {
|
||||
MetricCpuRatio, MetricCpuUsed, MetricMemoryRatio, MetricMemoryUsed,
|
||||
MetricDiskUsed, MetricDiskRatio,
|
||||
} from "./system_metrics";
|
||||
import { useHosts } from "../model/host";
|
||||
import { useSystemMetrics } from "../model/system_metrics";
|
||||
import notify, { notifyErrorHandler } from "../util/notify";
|
||||
|
||||
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
|
||||
@@ -180,11 +185,13 @@ function CopyButton({ text, message }: { text:string, message:string }) {
|
||||
</Button>;
|
||||
}
|
||||
|
||||
|
||||
export default function HostsPage() {
|
||||
let account = useAccount();
|
||||
let navigate = useNavigate();
|
||||
let [hosts] = useHosts();
|
||||
const [metrics] = useSystemMetrics();
|
||||
const [showRatios, setShowRatios] = useState(true);
|
||||
const [showNumbers, setShowNumbers] = useState(false);
|
||||
|
||||
return <PageLayout nav={[{ name: "Hosts" }]}>
|
||||
<PageHeader
|
||||
@@ -192,6 +199,7 @@ export default function HostsPage() {
|
||||
extra={account.hasPermission("core.host.generate_token") ? <GenerateHostTokenButton /> : undefined}
|
||||
/>
|
||||
<Table
|
||||
style={{ overflowX: "auto" }}
|
||||
columns={[
|
||||
{
|
||||
title: "Name",
|
||||
@@ -199,6 +207,50 @@ export default function HostsPage() {
|
||||
defaultSortOrder: "ascend",
|
||||
sorter: (a, b) => strcmp(a.name, b.name),
|
||||
},
|
||||
{
|
||||
title: "CPU%",
|
||||
sorter: (a, b) => (metrics.get(a.id)?.cpuRatio ?? 0) - (metrics.get(b.id)?.cpuRatio ?? 0),
|
||||
render: (_, host) => <MetricCpuRatio metrics={metrics.get(host.id)} />,
|
||||
hidden: !showRatios,
|
||||
},
|
||||
{
|
||||
title: "Cores",
|
||||
sorter: (a, b) => (
|
||||
(metrics.get(a.id)?.cpuUsed ?? 0) - (metrics.get(b.id)?.cpuUsed ?? 0)
|
||||
),
|
||||
render: (_, host) => <MetricCpuUsed metrics={metrics.get(host.id)} />,
|
||||
hidden: !showNumbers,
|
||||
},
|
||||
{
|
||||
title: "Mem%",
|
||||
sorter: (a, b) => (
|
||||
(metrics.get(a.id)?.memoryRatio ?? 0) - (metrics.get(b.id)?.memoryRatio ?? 0)
|
||||
),
|
||||
render: (_, host) => <MetricMemoryRatio metrics={metrics.get(host.id)} />,
|
||||
hidden: !showRatios,
|
||||
},
|
||||
{
|
||||
title: "Memory",
|
||||
sorter: (a, b) => (
|
||||
(metrics.get(a.id)?.memoryUsed ?? 0) - (metrics.get(b.id)?.memoryUsed ?? 0)
|
||||
),
|
||||
render: (_, host) => <MetricMemoryUsed metrics={metrics.get(host.id)} />,
|
||||
hidden: !showNumbers,
|
||||
},
|
||||
{
|
||||
title: "Disk%",
|
||||
sorter: (a, b) => (metrics.get(a.id)?.diskAvailable ?? 0) - (metrics.get(b.id)?.diskAvailable ?? 0),
|
||||
render: (_, host) => <MetricDiskRatio metrics={metrics.get(host.id)} />,
|
||||
hidden: !showRatios,
|
||||
},
|
||||
{
|
||||
title: "Disk",
|
||||
sorter: (a, b) => (
|
||||
(metrics.get(a.id)?.diskUsed ?? 0) - (metrics.get(b.id)?.diskUsed ?? 0)
|
||||
),
|
||||
render: (_, host) => <MetricDiskUsed metrics={metrics.get(host.id)} />,
|
||||
hidden: !showNumbers,
|
||||
},
|
||||
{
|
||||
title: "Agent",
|
||||
dataIndex: "agent",
|
||||
@@ -235,6 +287,16 @@ export default function HostsPage() {
|
||||
},
|
||||
})}
|
||||
/>
|
||||
<Flex wrap="wrap" style={{ margin: "16px 0 0 0" }} gap="small">
|
||||
<label style={{ width: "14em", display: "flex", justifyContent: "space-between", marginRight: 16 }}>
|
||||
Show metric ratios:
|
||||
<Switch checked={showRatios} onChange={checked => { setShowRatios(checked); }} />
|
||||
</label>
|
||||
<label style={{ width: "14em", display: "flex", justifyContent: "space-between", marginRight: 16 }}>
|
||||
Show metric numbers:
|
||||
<Switch checked={showNumbers} onChange={checked => { setShowNumbers(checked); }} />
|
||||
</label>
|
||||
</Flex>
|
||||
<PluginExtra component="HostsPage" />
|
||||
</PageLayout>;
|
||||
};
|
||||
Reference in new issue
Block a user