Moved the Agents into their own repo. Kept the agent.pl just for reference
This commit is contained in:
parent
22381be29a
commit
8680a02b13
18132 changed files with 0 additions and 2569420 deletions
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
return [
|
||||
// SQLite DB (auto-created)
|
||||
'db_path' => __DIR__ . '/../status.sqlite',
|
||||
|
||||
// Shared secret the machines use when POSTing
|
||||
'ingest_token' => '6e93b1e50f5e32c33060c0488eb2d90c8acf132307f3d83abb162e9986808a27',
|
||||
|
||||
// Set if you want Discord alerts (or leave empty to disable)
|
||||
'discord_webhook' => 'https://discord.com/api/webhooks/XXXXX/XXXXX',
|
||||
|
||||
// Host considered UP if last sample newer than this many seconds
|
||||
'up_grace_seconds' => 10*60, // 10 minutes
|
||||
|
||||
// Alert rules (machine DOWN when no sample for 3 intervals @5min)
|
||||
'down_consecutive_threshold' => 3, // 3 missed = DOWN alert
|
||||
'network_issue_failures' => 2, // 2 fails in last window => NETWORK ISSUE
|
||||
'network_issue_window' => 20, // last 20 intervals (~100 minutes)
|
||||
|
||||
// CORS for summary API (public site pulls from panel). Adjust to your domain or leave '' to disable CORS.
|
||||
'cors_allow_origin' => '',
|
||||
];
|
||||
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
function db_open(array $cfg): PDO {
|
||||
$path = $cfg['db_path'];
|
||||
$init = !file_exists($path);
|
||||
$pdo = new PDO('sqlite:' . $path, null, null, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
if ($init) db_init($pdo);
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
function db_init(PDO $db): void {
|
||||
$db->exec("
|
||||
PRAGMA journal_mode=WAL;
|
||||
CREATE TABLE hosts (
|
||||
host_id TEXT PRIMARY KEY,
|
||||
location TEXT,
|
||||
last_seen INTEGER,
|
||||
last_up INTEGER DEFAULT 1,
|
||||
alert_state TEXT DEFAULT 'OK' -- OK|DOWN|WARN
|
||||
);
|
||||
CREATE TABLE host_metrics (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
host_id TEXT,
|
||||
ts INTEGER,
|
||||
cpu_pct REAL,
|
||||
mem_pct REAL,
|
||||
disk_total_bytes INTEGER,
|
||||
disk_free_bytes INTEGER
|
||||
);
|
||||
CREATE INDEX idx_host_metrics ON host_metrics(host_id, ts);
|
||||
|
||||
CREATE TABLE process_metrics (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
host_id TEXT,
|
||||
ts INTEGER,
|
||||
server_id TEXT, -- numeric folder name under /home/gameserver/
|
||||
pid INTEGER,
|
||||
exe TEXT,
|
||||
cwd TEXT,
|
||||
cpu_cores REAL, -- fraction of a core (e.g., 0.35)
|
||||
rss_bytes INTEGER
|
||||
);
|
||||
CREATE INDEX idx_proc_metrics ON process_metrics(host_id, server_id, ts);
|
||||
|
||||
CREATE TABLE statuses (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
host_id TEXT,
|
||||
ts INTEGER,
|
||||
up INTEGER -- 1 up, 0 down (by heartbeat)
|
||||
);
|
||||
CREATE INDEX idx_status ON statuses(host_id, ts);
|
||||
");
|
||||
}
|
||||
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|
||||
5) Panel API — per-host detail (optional)
|
||||
|
||||
/var/www/html/panel/status/api/host.php?host_id=KC
|
||||
*/
|
||||
$cfg = require __DIR__ . '/config.php';
|
||||
require __DIR__ . '/db.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$host_id = $_GET['host_id'] ?? '';
|
||||
if ($host_id===''){ http_response_code(400); echo json_encode(['error'=>'host_id required']); exit; }
|
||||
|
||||
$db = db_open($cfg);
|
||||
$grace = (int)$cfg['up_grace_seconds'];
|
||||
$now=time();
|
||||
|
||||
$h = $db->prepare("SELECT * FROM hosts WHERE host_id=?");
|
||||
$h->execute([$host_id]);
|
||||
$host = $h->fetch();
|
||||
if (!$host){ http_response_code(404); echo json_encode(['error'=>'unknown host']); exit; }
|
||||
|
||||
$up = ($now - (int)$host['last_seen']) <= $grace;
|
||||
|
||||
$metrics = $db->prepare("
|
||||
SELECT ts, cpu_pct, mem_pct, disk_total_bytes, disk_free_bytes
|
||||
FROM host_metrics WHERE host_id=? ORDER BY ts DESC LIMIT 1
|
||||
"); $metrics->execute([$host_id]); $m = $metrics->fetch();
|
||||
|
||||
$procs = $db->prepare("
|
||||
SELECT server_id, pid, exe, cwd, cpu_cores, rss_bytes
|
||||
FROM process_metrics WHERE host_id=? AND ts=(SELECT MAX(ts) FROM process_metrics WHERE host_id=?)
|
||||
"); $procs->execute([$host_id,$host_id]); $plist = $procs->fetchAll();
|
||||
|
||||
echo json_encode([
|
||||
'host' => ['host_id'=>$host['host_id'], 'location'=>$host['location'], 'status'=>$up?'UP':'DOWN', 'last_seen'=>(int)$host['last_seen']],
|
||||
'metrics' => $m ?: null,
|
||||
'processes' => array_map(function($p){
|
||||
$p['rss_mib'] = round($p['rss_bytes']/1048576,1);
|
||||
return $p;
|
||||
}, $plist),
|
||||
]);
|
||||
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
$cfg = require __DIR__ . '/config.php';
|
||||
require __DIR__ . '/db.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$raw = file_get_contents('php://input');
|
||||
$data = json_decode($raw, true);
|
||||
if (!$data) { http_response_code(400); echo json_encode(['error'=>'bad json']); exit; }
|
||||
|
||||
if (($data['token'] ?? '') !== $cfg['ingest_token']) {
|
||||
http_response_code(403); echo json_encode(['error'=>'forbidden']); exit;
|
||||
}
|
||||
|
||||
$host_id = trim($data['host_id'] ?? '');
|
||||
$location = trim($data['location'] ?? '');
|
||||
$machine = $data['machine'] ?? null;
|
||||
$procs = $data['processes'] ?? [];
|
||||
|
||||
if ($host_id === '' || !$machine) {
|
||||
http_response_code(400); echo json_encode(['error'=>'missing host_id or machine']); exit;
|
||||
}
|
||||
|
||||
$db = db_open($cfg);
|
||||
$now = time();
|
||||
$db->beginTransaction();
|
||||
|
||||
$db->prepare("
|
||||
INSERT INTO hosts(host_id, location, last_seen, last_up, alert_state)
|
||||
VALUES(?,?,?,?,?)
|
||||
ON CONFLICT(host_id) DO UPDATE SET location=excluded.location, last_seen=excluded.last_seen
|
||||
")->execute([$host_id, $location, $now, 1, 'OK']);
|
||||
|
||||
$db->prepare("
|
||||
INSERT INTO host_metrics(host_id, ts, cpu_pct, mem_pct, disk_total_bytes, disk_free_bytes)
|
||||
VALUES (?,?,?,?,?,?)
|
||||
")->execute([
|
||||
$host_id, $now,
|
||||
(float)$machine['cpu_pct'], (float)$machine['mem_pct'],
|
||||
(int)$machine['disk_total_bytes'], (int)$machine['disk_free_bytes']
|
||||
]);
|
||||
|
||||
$insP = $db->prepare("
|
||||
INSERT INTO process_metrics(host_id, ts, server_id, pid, exe, cwd, cpu_cores, rss_bytes)
|
||||
VALUES (?,?,?,?,?,?,?,?)
|
||||
");
|
||||
foreach ($procs as $p) {
|
||||
$insP->execute([
|
||||
$host_id, $now,
|
||||
(string)($p['server_id'] ?? ''),
|
||||
(int)$p['pid'], (string)$p['exe'], (string)$p['cwd'],
|
||||
(float)$p['cpu_cores'], (int)$p['rss_bytes']
|
||||
]);
|
||||
}
|
||||
|
||||
$db->prepare("INSERT INTO statuses(host_id, ts, up) VALUES (?,?,1)")->execute([$host_id, $now]);
|
||||
|
||||
$db->commit();
|
||||
|
||||
echo json_encode(['ok'=>true, 'stored_at'=>$now]);
|
||||
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
$cfg = require __DIR__ . '/config.php';
|
||||
require __DIR__ . '/db.php';
|
||||
|
||||
if ($cfg['cors_allow_origin']) {
|
||||
header('Access-Control-Allow-Origin: '.$cfg['cors_allow_origin']);
|
||||
header('Vary: Origin');
|
||||
}
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$db = db_open($cfg);
|
||||
$grace = (int)$cfg['up_grace_seconds'];
|
||||
$now = time();
|
||||
|
||||
$rows = $db->query("
|
||||
SELECT h.host_id, h.location, h.last_seen,
|
||||
(SELECT cpu_pct FROM host_metrics WHERE host_id=h.host_id ORDER BY ts DESC LIMIT 1) AS cpu_pct,
|
||||
(SELECT mem_pct FROM host_metrics WHERE host_id=h.host_id ORDER BY ts DESC LIMIT 1) AS mem_pct
|
||||
FROM hosts h
|
||||
ORDER BY h.location, h.host_id
|
||||
")->fetchAll();
|
||||
|
||||
$out = [];
|
||||
foreach ($rows as $r) {
|
||||
$up = ($now - (int)$r['last_seen']) <= $grace;
|
||||
$out[] = [
|
||||
'host_id' => $r['host_id'],
|
||||
'location' => $r['location'],
|
||||
'status' => $up ? 'UP' : 'DOWN',
|
||||
'cpu_pct' => is_null($r['cpu_pct']) ? null : round($r['cpu_pct'],1),
|
||||
'mem_pct' => is_null($r['mem_pct']) ? null : round($r['mem_pct'],1),
|
||||
'last_seen' => (int)$r['last_seen'],
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode(['generated_at'=>$now, 'hosts'=>$out]);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue