Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status page #30

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"node-pg-migrate": "7.6.1",
"pg": "8.12.0",
"react": "18.3.1",
"react-dom": "18.3.1"
"react-dom": "18.3.1",
"swr": "2.2.5"
},
"devDependencies": {
"@commitlint/cli": "19.4.0",
Expand Down
55 changes: 55 additions & 0 deletions pages/status/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import useSwr from "swr";

async function fetchAPI(key) {
const response = await fetch(key);
const responseBody = await response.json();
return responseBody;
}

export default function StatusPage() {
return (
<>
<h1>Status</h1>
<UpdatedAt />
<br />
<Status />
</>
);
}

function UpdatedAt() {
const { isLoading, data } = useSwr("/api/v1/status", fetchAPI, {
refreshInterval: 2000,
});

let updatedAtText = "Carregando...";

if (!isLoading && data) {
updatedAtText = new Date(data.updated_at).toLocaleString("pt-BR");
}

return <div>Ultima atualização: {updatedAtText}</div>;
}

function Status() {
const { isLoading, data } = useSwr("/api/v1/status", fetchAPI, {
refreshInterval: 2000,
});

let databaseStatus;

if (isLoading) return <div>Carregando...</div>;

if (!data?.dependencies?.database)
return <div>Não foi possível obter as informações.</div>;

databaseStatus = data.dependencies.database;

return (
<>
<div>Versão do Banco de Dados: {databaseStatus.version}</div>
<div>Número máximo de conexões: {databaseStatus.max_connections}</div>
<div>Conexões abertas: {databaseStatus.opened_connections}</div>
</>
);
}