Compare commits

..

6 Commits

Author SHA1 Message Date
6c8b9ace28 cpu_load_1m 2025-01-28 17:08:30 +01:00
ff551e0f62 disk_free 2025-01-28 17:08:30 +01:00
705afb2bbb psql script 2025-01-28 17:08:25 +01:00
9645fb8dc2 mem_avail 2025-01-28 17:08:25 +01:00
d701098d84 use /proc/uptime 2025-01-28 17:08:21 +01:00
f3545980b7 uptime 2025-01-28 17:08:15 +01:00
2 changed files with 20 additions and 0 deletions

View File

@ -27,3 +27,11 @@ CREATE TABLE host_disk (
-- free disk space in kB -- free disk space in kB
disk_free INT NOT NULL 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 FROM host_upsert
RETURNING *; RETURNING *;
EOF 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