aboutsummaryrefslogtreecommitdiff
path: root/index.ts
blob: 00d399b2d058d69f5349e3862c83b540bba4d1a5 (plain)
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
import express from "express";
import si from "systeminformation";

const app = express();

app.get("/json", async (req, res) => {
    // Gives the info for this server
    let cpu = await si.cpu();
    let cpuSpeed = await si.cpuCurrentSpeed();
    let temp = await si.cpuTemperature();
    let memory = await si.mem();
    let os = await si.osInfo();
    let time = si.time();
    let load = await si.currentLoad();
    let processes = await si.processes();

    let uptime = parseInt(time.uptime) * 1000;

    res.json({
        name: os.hostname,
        cpu: {
            processors: cpu.processors,
            model: `${cpu.manufacturer} ${cpu.brand}`,
            cores: cpu.cores,
            speed: cpuSpeed.avg,
            temperature: temp.main,
            load: load.currentLoadSystem
        },
        processes: {
            total: processes.all,
            running: processes.running,
            sleeping: processes.sleeping,
            blocked: processes.blocked,
            unknown: processes.unknown
        },
        swapmemory: {
            used: memory.swapused,
            free: memory.swapfree,
            total: memory.swaptotal
        },
        physicalmemory: {
            used: memory.used,
            free: memory.free,
            total: memory.total
        },
        os: {
            name: os.distro,
            version: os.release
        },
        uptime: uptime,
        version: "1.0.0"
    });
});

app.listen(52937, () => {
    console.log("listening!");
});