-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsystem.js
executable file
·100 lines (90 loc) · 3.9 KB
/
system.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env node
import si from 'systeminformation';
import ora from 'ora';
import chalk from 'chalk';
import moment from 'moment';
import updateNotifier from 'update-notifier';
import { readFileSync } from 'fs';
const packageJSON = JSON.parse(readFileSync(new URL("./package.json", import.meta.url)));
updateNotifier({pkg: packageJSON}).notify();
// JavaScript To Convert Bytes To MB, KB, Etc - https://gist.github.com/lanqy/5193417
function bytesToSize(bytes) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
if (bytes === 0) return 'n/a'
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10)
if (i === 0) return `${bytes} ${sizes[i]}`
return `${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`
}
async function go() {
const spinner = new ora({
text: 'Fetching your System Data',
spinner: 'hamburger'
});
spinner.start();
setTimeout(() => {
spinner.color = 'yellow';
spinner.text = 'Successfully Fetched the System Data';
}, 1000);
try {
await new Promise(resolve => setTimeout(resolve, 2000));
const dataos = await si.osInfo();
const datacpu = await si.cpu();
const datamem = await si.mem();
const datadisk = await si.fsSize();
const datatime = await si.time();
var sysos = dataos;
var syscpu = datacpu;
var sysmem = datamem;
var sysdisk = datadisk;
var systime = datatime;
spinner.stop();
console.log('\n');
console.log(chalk.blueBright('---------------------------'));
console.log(chalk.cyanBright('Platform: ' + sysos.platform));
console.log(chalk.cyanBright('Distro: ' + sysos.distro));
if (sysos.codename == 0) {
console.log(chalk.cyanBright('CODE: n/a'));
} else {
console.log(chalk.cyanBright('CODE: ' + sysos.codename));
}
console.log(chalk.cyanBright('Version: ' + sysos.release));
console.log(chalk.cyanBright('Kernel: ' + sysos.kernel));
if (sysos.build == 0) {
console.log(chalk.cyanBright('Build: n/a'));
} else {
console.log(chalk.cyanBright('Build: ' + sysos.build));
}
console.log(chalk.cyanBright('Architecture: ' + sysos.arch));
console.log(chalk.blueBright('---------------------------'));
console.log(chalk.magentaBright('Brand: ' + syscpu.brand));
console.log(chalk.magentaBright('Manufacturer: ' + syscpu.manufacturer));
console.log(chalk.magentaBright('Cores: ' + syscpu.cores));
console.log(chalk.magentaBright('Processors: ' + syscpu.processors));
console.log(chalk.blueBright('---------------------------'));
console.log(chalk.yellowBright('Total Memory: ' + (bytesToSize(sysmem.total))));
console.log(chalk.yellowBright('Free Memory: ' + (bytesToSize(sysmem.free))));
console.log(chalk.yellowBright('Used Memory: ' + (bytesToSize(sysmem.used))));
console.log(chalk.yellowBright('Active Memory: ' + (bytesToSize(sysmem.active))));
console.log(chalk.yellowBright('Available Memory: ' + (bytesToSize(sysmem.available))));
console.log(chalk.yellowBright('Total Swap Memory: ' + (bytesToSize(sysmem.swaptotal))));
console.log(chalk.yellowBright('Total Swap Memory Used: ' + (bytesToSize(sysmem.swapused))));
console.log(chalk.yellowBright('Free Swap Memory: ' + (bytesToSize(sysmem.swapfree))));
console.log(chalk.blueBright('---------------------------'));
sysdisk.forEach((disk) => {
console.log(chalk.whiteBright('Disk Size: ' + (bytesToSize(disk.size))));
console.log(chalk.whiteBright('Disk used: ' + (bytesToSize(disk.used))));
console.log(chalk.whiteBright('Disk Usage: ' + disk.use + '%'));
console.log(chalk.whiteBright('Location: ' + disk.fs));
console.log(chalk.blueBright('---------------------------'));
});
console.log(chalk.greenBright('Time Zone: ' + systime.timezone));
console.log(chalk.greenBright('Time Zone Name: ' + systime.timezoneName));
console.log(chalk.greenBright('Current Time: ' + (moment(systime.current).format('LLLL'))));
console.log(chalk.blueBright('---------------------------'));
console.log('\n');
} catch (e) {
spinner.stop();
console.log(e)
}
}
go();