cpu_load_1m

This commit is contained in:
ekzyis 2025-01-28 17:07:35 +01:00
parent ff551e0f62
commit 6c8b9ace28
2 changed files with 20 additions and 0 deletions

View File

@ -27,3 +27,11 @@ CREATE TABLE host_disk (
-- free disk space in kB
disk_free INT NOT NULL
);
CREATE TABLE host_cpu (
id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
host_id INT NOT NULL REFERENCES host(id),
-- cpu load for last minute
cpu_load_1m FLOAT NOT NULL
);

12
status
View File

@ -39,3 +39,15 @@ psql -w <<EOF
FROM host_upsert
RETURNING *;
EOF
psql -w <<EOF
WITH host_upsert AS (
INSERT INTO host (name) VALUES ('$(hostname)')
ON CONFLICT (name) DO UPDATE SET name = EXCLUDED.name
RETURNING id
)
INSERT INTO host_cpu (host_id, cpu_load_1m)
SELECT id, '$(top -bn1 | head -1 | awk -F'load average: ' '{print $2}' | awk -F, '{print $1}')'
FROM host_upsert
RETURNING *;
EOF