Fix status page.

This commit is contained in:
Thomas E Lackey 2020-06-08 22:50:45 -05:00
parent c0efe66ec4
commit eabd69c953
6 changed files with 30 additions and 55 deletions

View File

@ -26,19 +26,22 @@ const useStyles = makeStyles(theme => ({
const VersionCheck = () => {
const classes = useStyles();
const [{ current, latest }, setUpgrade] = useState({});
const status = useQueryStatusReducer(useQuery(SYSTEM_STATUS));
const statusRespone = useQueryStatusReducer(useQuery(SYSTEM_STATUS));
const wnsResponse = useQueryStatusReducer(useQuery(WNS_RECORDS, {
pollInterval: CHECK_INTERVAL,
variables: { type: 'wrn:resource' }
variables: { attributes: { type: 'wrn:resource' } }
}));
// Check version.
useEffect(() => {
if (status && wnsResponse) {
const { dxos: { image: current } } = status.system_status;
if (statusRespone && wnsResponse) {
const statusData = JSON.parse(statusRespone.system_status.json);
const wnsData = JSON.parse(wnsResponse.wns_records.json);
const { dxos: { image: current = '0.0.0' } = {} } = statusData;
let latest = current;
const data = JSON.parse(wnsResponse.wns_records.json);
data.forEach(({ attributes: { name, version } }) => {
wnsData.forEach(({ attributes: { name, version } }) => {
// TODO(burdon): Filter by type (WRN?)
if (name.startsWith('dxos/xbox:')) {
if (compareVersions(version, latest) > 0) {

View File

@ -16,18 +16,20 @@ import Toolbar from '../../components/Toolbar';
const Status = () => {
const { config } = useContext(ConsoleContext);
const data = useQueryStatusReducer(useQuery(SYSTEM_STATUS, { pollInterval: config.api.intervalQuery }));
if (!data) {
const systemResponse = useQueryStatusReducer(useQuery(SYSTEM_STATUS, { pollInterval: config.api.intervalQuery }));
if (!systemResponse) {
return null;
}
const data = JSON.parse(systemResponse.system_status.json);
return (
<Panel
toolbar={
<Toolbar />
}
>
<Json data={data.system_status} />
<Json data={data} />
</Panel>
);
};

View File

@ -4,18 +4,7 @@
query {
system_status {
timestamp
dxos {
image
}
system {
network {
address
}
nodejs {
version
environment
}
}
timestamp,
json
}
}

View File

@ -1,7 +1,7 @@
{
"build": {
"name": "@dxos/console-app",
"buildDate": "2020-06-08T23:14:00.921Z",
"buildDate": "2020-06-09T03:18:46.229Z",
"version": "1.0.0-beta.0"
}
}

View File

@ -2,26 +2,7 @@
# Copyright 2020 DxOS.org
#
type DXOSInfo {
image: String
}
type NetworkInfo {
address: [String]
}
type NodeInfo {
version: String
environment: String
}
type SystemInfo {
network: NetworkInfo
nodejs: NodeInfo
}
type SystemStatus {
timestamp: String!
dxos: DXOSInfo
system: SystemInfo
json: String!
}

View File

@ -30,7 +30,9 @@ const getSystemInfo = async () => {
const ifaces = os.networkInterfaces();
const addresses = Object.entries(ifaces).reduce((result, [, values]) => {
values.forEach(({ family, address }) => {
if (family === 'IPv4' && address !== '127.0.0.1') {
address = address.toLowerCase();
//TODO(telackey): Include link-local IPv6?
if (!address.startsWith('127.') && !address.startsWith('fe80::') && !address.startsWith('::1')) {
result.push(address);
}
});
@ -42,7 +44,7 @@ const getSystemInfo = async () => {
const device = await si.system();
return {
cpu: pick(cpu, 'brand', 'cores', 'manufacturer', 'vendor'),
cpu: pick(cpu, 'brand', 'cores', 'manufacturer', 'vendor', 'speed'),
memory: {
total: size(memory.total, 'M'),
@ -54,21 +56,23 @@ const getSystemInfo = async () => {
device: pick(device, 'model', 'serial', 'version'),
network: {
address: addresses
addresses
},
// https://nodejs.org/api/os.html
os: {
arch: os.arch(),
type: os.type(),
platform: os.platform(),
version: os.version ? os.version() : undefined, // Node > 13
uptime: moment().subtract(os.uptime(), 'seconds').fromNow()
},
time: {
now: moment(),
up: moment().subtract(os.uptime(), 'seconds'),
},
nodejs: {
version: process.version,
environment: process.env.NODE_ENV
version: process.version
}
};
};
@ -80,11 +84,7 @@ export const systemResolvers = {
return {
timestamp: new Date().toUTCString(),
dxos: {
// TODO(burdon): ???
image: '0.0.1'
},
system
json: JSON.stringify(system)
};
}
}