summaryrefslogtreecommitdiff
path: root/includes/refresh-status.php
blob: d3fa0e79459e5c84f1604b7865707671556f47a0 (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
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
<?php

if (!isset($_SERVER['argv'])) die("This script can only be run in a CLI environment.");

// Status

$servers = [
    json_decode(exec("ssh -p 2222 root@zephyrheights.equestria.dev starshine-status"), true),
    //json_decode(exec("ssh -p 2224 root@zephyrheights-testing.equestria.dev starshine-status"), true),
    json_decode(exec("ssh -p 2223 root@maretimebay.equestria.dev starshine-status"), true),
    json_decode(exec("ssh -p 22 fedora@bridlewood.equestria.dev starshine-status"), true),
];

$total = [
    "ram" => array_reduce(array_map(function ($i) {
        return $i["ram"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "ramTotal" => array_reduce(array_map(function ($i) {
        return $i["ramTotal"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "disk" => array_reduce(array_map(function ($i) {
        return $i["disk"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "diskTotal" => array_reduce(array_map(function ($i) {
        return $i["diskTotal"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "cores" => array_reduce(array_map(function ($i) {
        return $i["cores"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "ghz" => array_reduce(array_map(function ($i) {
        return $i["ghz"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "ghzMax" => array_reduce(array_map(function ($i) {
        return $i["ghzMax"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "ghzMin" => array_reduce(array_map(function ($i) {
        return $i["ghzMin"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "cache" => array_reduce(array_map(function ($i) {
        return $i["cache"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "cpuLoad" => array_reduce(array_map(function ($i) {
        return $i["cpuLoad"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }) / count($servers),
    "processes" => array_reduce(array_map(function ($i) {
        return $i["processes"];
    }, $servers), function ($a, $b) {
        return $a + $b;
    }),
    "io" => max(array_map(function ($i) {
        return $i["io"];
    }, $servers)),
    "kernel" => array_values(array_unique(array_map(function ($i) {
        return $i["kernel"];
    }, $servers)))
];

var_dump($total);

file_put_contents("./data/status.json", json_encode([
    "services" => json_decode(file_get_contents("https://status.equestria.dev/status.json"), true),
    "servers" => $total,
    "updated" => time()
]));