uptime
This commit is contained in:
parent
439397ceb8
commit
f3545980b7
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
13
schema.sql
Normal file
13
schema.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
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
|
||||||
|
);
|
17
status
Executable file
17
status
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/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, '$(uptime -r | awk '{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