-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
148a145
commit 2f16fe4
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</> | ||
); | ||
} |