mem_avail

This commit is contained in:
ekzyis 2025-01-28 16:07:05 +01:00
parent d701098d84
commit 9645fb8dc2
2 changed files with 20 additions and 0 deletions

View File

@ -11,3 +11,11 @@ CREATE TABLE host_uptime (
-- uptime in seconds -- uptime in seconds
uptime INT NOT NULL uptime INT NOT NULL
); );
CREATE TABLE host_mem (
id SERIAL PRIMARY KEY,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
host_id INT NOT NULL REFERENCES host(id),
-- available memory in kB
mem_avail INT NOT NULL
);

12
status
View File

@ -15,3 +15,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_mem (host_id, mem_avail)
SELECT id, '$(cat /proc/meminfo | grep 'MemAvailable' | awk '{print $2}')'
FROM host_upsert
RETURNING *;
EOF