Compare commits
6 Commits
8568c6ea0d
...
6c8b9ace28
Author | SHA1 | Date | |
---|---|---|---|
6c8b9ace28 | |||
ff551e0f62 | |||
705afb2bbb | |||
9645fb8dc2 | |||
d701098d84 | |||
f3545980b7 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
7
psql
Normal file
7
psql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export $(cat .env | xargs)
|
||||||
|
|
||||||
|
psql -w
|
37
schema.sql
Normal file
37
schema.sql
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
CREATE TABLE host (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
name VARCHAR(255) NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE host_uptime (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
host_id INT NOT NULL REFERENCES host(id),
|
||||||
|
-- uptime in seconds
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
53
status
Executable file
53
status
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export $(cat .env | xargs)
|
||||||
|
|
||||||
|
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_uptime (host_id, uptime)
|
||||||
|
SELECT id, '$(cat /proc/uptime | awk -F. '{print $1}')'
|
||||||
|
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_mem (host_id, mem_avail)
|
||||||
|
SELECT id, '$(cat /proc/meminfo | grep 'MemAvailable' | awk '{print $2}')'
|
||||||
|
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_disk (host_id, disk_free)
|
||||||
|
SELECT id, '$(df / | awk 'NR==2{print $4}')'
|
||||||
|
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
|
5
template.env
Normal file
5
template.env
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
PGHOST=
|
||||||
|
PGPORT=
|
||||||
|
PGUSER=
|
||||||
|
PGPASSWORD=
|
||||||
|
PGDATABASE=
|
Loading…
x
Reference in New Issue
Block a user