mirror of
https://github.com/karl0ss/homepage.git
synced 2025-05-02 05:23:39 +01:00
Feature: Added gatus uptime widget (#2729)
This commit is contained in:
parent
58fa63f7cb
commit
e803c3bf16
12
docs/widgets/services/gatus.md
Normal file
12
docs/widgets/services/gatus.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
title: Gatus
|
||||||
|
description: Gatus Widget Configuration
|
||||||
|
---
|
||||||
|
|
||||||
|
Allowed fields: `["up", "down", "uptime"]`.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
widget:
|
||||||
|
type: gatus
|
||||||
|
url: http://gatus.host.or.ip:port
|
||||||
|
```
|
@ -55,6 +55,7 @@ nav:
|
|||||||
- widgets/services/freshrss.md
|
- widgets/services/freshrss.md
|
||||||
- widgets/services/fritzbox.md
|
- widgets/services/fritzbox.md
|
||||||
- widgets/services/gamedig.md
|
- widgets/services/gamedig.md
|
||||||
|
- widgets/services/gatus.md
|
||||||
- widgets/services/ghostfolio.md
|
- widgets/services/ghostfolio.md
|
||||||
- widgets/services/glances.md
|
- widgets/services/glances.md
|
||||||
- widgets/services/gluetun.md
|
- widgets/services/gluetun.md
|
||||||
|
@ -694,6 +694,11 @@
|
|||||||
"targets_down": "Targets Down",
|
"targets_down": "Targets Down",
|
||||||
"targets_total": "Total Targets"
|
"targets_total": "Total Targets"
|
||||||
},
|
},
|
||||||
|
"gatus": {
|
||||||
|
"up": "Sites Up",
|
||||||
|
"down": "Sites Down",
|
||||||
|
"uptime": "Uptime"
|
||||||
|
},
|
||||||
"ghostfolio": {
|
"ghostfolio": {
|
||||||
"gross_percent_today": "Today",
|
"gross_percent_today": "Today",
|
||||||
"gross_percent_1y": "One year",
|
"gross_percent_1y": "One year",
|
||||||
|
@ -29,6 +29,7 @@ const components = {
|
|||||||
freshrss: dynamic(() => import("./freshrss/component")),
|
freshrss: dynamic(() => import("./freshrss/component")),
|
||||||
fritzbox: dynamic(() => import("./fritzbox/component")),
|
fritzbox: dynamic(() => import("./fritzbox/component")),
|
||||||
gamedig: dynamic(() => import("./gamedig/component")),
|
gamedig: dynamic(() => import("./gamedig/component")),
|
||||||
|
gatus: dynamic(() => import("./gatus/component")),
|
||||||
ghostfolio: dynamic(() => import("./ghostfolio/component")),
|
ghostfolio: dynamic(() => import("./ghostfolio/component")),
|
||||||
glances: dynamic(() => import("./glances/component")),
|
glances: dynamic(() => import("./glances/component")),
|
||||||
gluetun: dynamic(() => import("./gluetun/component")),
|
gluetun: dynamic(() => import("./gluetun/component")),
|
||||||
|
51
src/widgets/gatus/component.jsx
Normal file
51
src/widgets/gatus/component.jsx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
|
import Container from "components/services/widget/container";
|
||||||
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||||
|
import Block from "components/services/widget/block";
|
||||||
|
|
||||||
|
export default function Component({ service }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const { widget } = service;
|
||||||
|
|
||||||
|
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");
|
||||||
|
|
||||||
|
if (statusError) {
|
||||||
|
return <Container service={service} error={statusError} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!statusData) {
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="gatus.up" />
|
||||||
|
<Block label="gatus.down" />
|
||||||
|
<Block label="gatus.uptime" />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let sitesUp = 0;
|
||||||
|
let sitesDown = 0;
|
||||||
|
Object.values(statusData).forEach((site) => {
|
||||||
|
const lastResult = site.results[site.results.length - 1];
|
||||||
|
if (lastResult?.success === true) {
|
||||||
|
sitesUp += 1;
|
||||||
|
} else {
|
||||||
|
sitesDown += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Adapted from https://github.com/bastienwirtz/homer/blob/b7cd8f9482e6836a96b354b11595b03b9c3d67cd/src/components/services/UptimeKuma.vue#L105
|
||||||
|
const resultsList = Object.values(statusData).reduce((a, b) => a.concat(b.results), []);
|
||||||
|
const percent = resultsList.reduce((a, b) => a + (b?.success === true ? 1 : 0), 0) / resultsList.length;
|
||||||
|
const uptime = (percent * 100).toFixed(1);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Container service={service}>
|
||||||
|
<Block label="gatus.up" value={t("common.number", { value: sitesUp })} />
|
||||||
|
<Block label="gatus.down" value={t("common.number", { value: sitesDown })} />
|
||||||
|
<Block label="gatus.uptime" value={t("common.percent", { value: uptime })} />
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
15
src/widgets/gatus/widget.js
Normal file
15
src/widgets/gatus/widget.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||||
|
import genericProxyHandler from "utils/proxy/handlers/generic";
|
||||||
|
|
||||||
|
const widget = {
|
||||||
|
api: "{url}/{endpoint}",
|
||||||
|
proxyHandler: genericProxyHandler,
|
||||||
|
|
||||||
|
mappings: {
|
||||||
|
status: {
|
||||||
|
endpoint: "api/v1/endpoints/statuses",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default widget;
|
@ -23,6 +23,7 @@ import flood from "./flood/widget";
|
|||||||
import freshrss from "./freshrss/widget";
|
import freshrss from "./freshrss/widget";
|
||||||
import fritzbox from "./fritzbox/widget";
|
import fritzbox from "./fritzbox/widget";
|
||||||
import gamedig from "./gamedig/widget";
|
import gamedig from "./gamedig/widget";
|
||||||
|
import gatus from "./gatus/widget";
|
||||||
import ghostfolio from "./ghostfolio/widget";
|
import ghostfolio from "./ghostfolio/widget";
|
||||||
import glances from "./glances/widget";
|
import glances from "./glances/widget";
|
||||||
import gluetun from "./gluetun/widget";
|
import gluetun from "./gluetun/widget";
|
||||||
@ -128,6 +129,7 @@ const widgets = {
|
|||||||
freshrss,
|
freshrss,
|
||||||
fritzbox,
|
fritzbox,
|
||||||
gamedig,
|
gamedig,
|
||||||
|
gatus,
|
||||||
ghostfolio,
|
ghostfolio,
|
||||||
glances,
|
glances,
|
||||||
gluetun,
|
gluetun,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user