disk_free

This commit is contained in:
ekzyis 2025-01-28 16:44:29 +01:00
parent 705afb2bbb
commit ff551e0f62
2 changed files with 21 additions and 1 deletions

View File

@ -19,3 +19,11 @@ CREATE TABLE host_mem (
-- available memory in kB -- available memory in kB
mem_avail INT NOT NULL mem_avail INT NOT NULL
); );
CREATE TABLE host_disk (
id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
host_id INT NOT NULL REFERENCES host(id),
-- free disk space in kB
disk_free INT NOT NULL
);

12
status
View File

@ -27,3 +27,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_disk (host_id, disk_free)
SELECT id, '$(df / | awk 'NR==2{print $4}')'
FROM host_upsert
RETURNING *;
EOF