feat: add multi-location uptime monitoring via Globalping
## Changes ### Server - Add `locations` field to Monitor model and types (up to 5 locations per monitor) - Add `location` field to Check metadata for per-location tracking - Add `globalpingApiKey` to AppSettings for API key management - Create GlobalpingService that wraps the Globalping SDK to run distributed HTTP/ping checks from multiple global locations (NA, EU, AS, SA, OC, AF) - Extend SuperSimpleQueueHelper with fire-and-forget Globalping checks that run alongside the existing local check without affecting the main pipeline - Add location-aware check queries with aggregation pipeline grouping by location in MongoChecksRepository - Filter location checks from main uptime aggregation to preserve local check as source of truth for status/incidents - Extend monitor details endpoint to return per-location check data - Add GET /globalping/locations endpoint for available location options - Add globalpingKeySet to settings response - Add Joi validation for locations and globalpingApiKey fields ### Client - Add locations multi-select (Autocomplete with chips) to monitor creation form, shown only for HTTP and ping monitor types - Add SettingsGlobalping component for API key management (matching existing PageSpeed pattern with set/reset flow) - Add per-location breakdown section to uptime details page with tabs, avg response time, uptime percentage, and response time charts - Add globe icon with tooltip to monitor table for monitors with locations - Add Zod validation for locations field in HTTP and ping schemas - Add all translation keys for globalping settings, locations form, and location details sections ## Benefits - Users gain visibility into geographic availability and latency data - Local check remains the source of truth, Globalping runs alongside - Supports up to 5 locations per monitor with 6 continent-level options - Graceful degradation when API key is not configured or rate limited
This commit is contained in:
1 parent
1c1474cd6f
commit
e39b44db6c
33 files changed
+1258
-24
No files matched your search
@@ -27,12 +27,18 @@ import {
|
||||
SliderWithLabel,
|
||||
Dialog,
|
||||
} from "@/Components/v2/inputs";
|
||||
import Chip from "@mui/material/Chip";
|
||||
import { useGet, usePost, usePatch, useDelete } from "@/Hooks/UseApi";
|
||||
import { useMonitorForm } from "@/Hooks/useMonitorForm";
|
||||
import type { Monitor, MonitorType, GamesMap } from "@/Types/Monitor";
|
||||
import type { Notification } from "@/Types/Notification";
|
||||
import type { MonitorFormData } from "@/Validation/monitor";
|
||||
|
||||
interface GlobalpingLocation {
|
||||
id: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
interface GeneralSettingsConfig {
|
||||
urlLabel: string;
|
||||
urlPlaceholder: string;
|
||||
@@ -146,6 +152,9 @@ const CreateMonitorPage = () => {
|
||||
|
||||
const { data: notifications } = useGet<Notification[]>("/notifications/team");
|
||||
const { data: games } = useGet<GamesMap>("/monitors/games");
|
||||
const { data: globalpingLocations } = useGet<GlobalpingLocation[]>(
|
||||
"/monitors/globalping/locations"
|
||||
);
|
||||
|
||||
const { schema, defaults } = useMonitorForm({
|
||||
data: existingMonitor ?? null,
|
||||
@@ -489,6 +498,56 @@ const CreateMonitorPage = () => {
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Global locations - only for http and ping types */}
|
||||
{(watchedType === "http" || watchedType === "ping") && globalpingLocations && globalpingLocations.length > 0 && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.locations.title")}
|
||||
subtitle={t("pages.createMonitor.form.locations.description")}
|
||||
rightContent={
|
||||
<Controller
|
||||
name="locations"
|
||||
control={control}
|
||||
render={({ field }) => {
|
||||
const locationOptions = (globalpingLocations ?? []).map((loc) => ({
|
||||
...loc,
|
||||
name: loc.label,
|
||||
}));
|
||||
const selectedLocations = locationOptions.filter((loc) =>
|
||||
(field.value ?? []).includes(loc.id)
|
||||
);
|
||||
return (
|
||||
<Stack spacing={theme.spacing(4)}>
|
||||
<Autocomplete
|
||||
multiple
|
||||
options={locationOptions}
|
||||
value={selectedLocations}
|
||||
getOptionLabel={(option) => option.name}
|
||||
onChange={(_: unknown, newValue: typeof locationOptions) => {
|
||||
const ids = newValue.map((loc) => loc.id);
|
||||
if (ids.length <= 5) {
|
||||
field.onChange(ids);
|
||||
}
|
||||
}}
|
||||
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||||
renderTags={(value, getTagProps) =>
|
||||
value.map((option, index) => (
|
||||
<Chip
|
||||
{...getTagProps({ index })}
|
||||
key={option.id}
|
||||
label={option.name}
|
||||
size="small"
|
||||
/>
|
||||
))
|
||||
}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Alert Thresholds - only for hardware type */}
|
||||
{generalSettingsConfig.showSecret && (
|
||||
<ConfigBox
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
import Box from "@mui/material/Box";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Button from "@mui/material/Button";
|
||||
import ConfigBox from "@/Components/v1/ConfigBox/index.jsx";
|
||||
import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx";
|
||||
import { PasswordEndAdornment } from "@/Components/v1/Inputs/TextInput/Adornments/index.jsx";
|
||||
import { useTheme } from "@emotion/react";
|
||||
import { PropTypes } from "prop-types";
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Controller } from "react-hook-form";
|
||||
|
||||
const SettingsGlobalping = ({
|
||||
isAdmin,
|
||||
HEADING_SX,
|
||||
isGlobalpingKeySet,
|
||||
globalpingKeyHasBeenReset,
|
||||
setGlobalpingKeyHasBeenReset,
|
||||
defaults,
|
||||
control,
|
||||
setValue,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const theme = useTheme();
|
||||
|
||||
if (!isAdmin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<ConfigBox>
|
||||
<Box>
|
||||
<Typography
|
||||
component="h1"
|
||||
variant="h2"
|
||||
>
|
||||
{t("pages.settings.globalpingSettings.title")}
|
||||
</Typography>
|
||||
<Typography sx={HEADING_SX}>
|
||||
{t("pages.settings.globalpingSettings.description")}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Stack gap={theme.spacing(20)}>
|
||||
{(isGlobalpingKeySet === false || globalpingKeyHasBeenReset === true) && (
|
||||
<Controller
|
||||
name="globalpingApiKey"
|
||||
control={control}
|
||||
defaultValue={defaults.globalpingApiKey}
|
||||
render={({ field, fieldState }) => (
|
||||
<TextInput
|
||||
{...field}
|
||||
label={t("pages.settings.globalpingSettings.labelApiKey")}
|
||||
type={"password"}
|
||||
optionalLabel="(Optional)"
|
||||
endAdornment={<PasswordEndAdornment />}
|
||||
error={!!fieldState.error}
|
||||
helperText={fieldState.error?.message}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isGlobalpingKeySet === true && globalpingKeyHasBeenReset === false && (
|
||||
<Box>
|
||||
<Typography>
|
||||
{t("pages.settings.globalpingSettings.labelApiKeySet")}
|
||||
</Typography>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setValue("globalpingApiKey", "");
|
||||
setGlobalpingKeyHasBeenReset(true);
|
||||
}}
|
||||
variant="contained"
|
||||
color="error"
|
||||
sx={{ mt: theme.spacing(4) }}
|
||||
>
|
||||
{t("reset")}
|
||||
</Button>
|
||||
</Box>
|
||||
)}
|
||||
</Stack>
|
||||
</ConfigBox>
|
||||
);
|
||||
};
|
||||
|
||||
SettingsGlobalping.propTypes = {
|
||||
isAdmin: PropTypes.bool,
|
||||
HEADING_SX: PropTypes.object,
|
||||
isGlobalpingKeySet: PropTypes.bool,
|
||||
globalpingKeyHasBeenReset: PropTypes.bool,
|
||||
setGlobalpingKeyHasBeenReset: PropTypes.func,
|
||||
defaults: PropTypes.object,
|
||||
control: PropTypes.object,
|
||||
setValue: PropTypes.func,
|
||||
};
|
||||
|
||||
export default SettingsGlobalping;
|
||||
@@ -5,6 +5,7 @@ import SettingsTimeZone from "./SettingsTimeZone.jsx";
|
||||
import SettingsUI from "./SettingsUI.jsx";
|
||||
import SettingsURL from "./SettingsURL.jsx";
|
||||
import SettingsPagespeed from "./SettingsPagespeed.jsx";
|
||||
import SettingsGlobalping from "./SettingsGlobalping.jsx";
|
||||
import SettingsDemoMonitors from "./SettingsDemoMonitors.jsx";
|
||||
import SettingsAbout from "./SettingsAbout.jsx";
|
||||
import SettingsEmail from "./SettingsEmail.jsx";
|
||||
@@ -34,6 +35,10 @@ const Settings = () => {
|
||||
fetchedSettings?.pagespeedKeySet ?? false
|
||||
);
|
||||
const [apiKeyHasBeenReset, setApiKeyHasBeenReset] = useState(false);
|
||||
const [isGlobalpingKeySet, setIsGlobalpingKeySet] = useState(
|
||||
fetchedSettings?.globalpingKeySet ?? false
|
||||
);
|
||||
const [globalpingKeyHasBeenReset, setGlobalpingKeyHasBeenReset] = useState(false);
|
||||
const [isEmailPasswordSet, setIsEmailPasswordSet] = useState(
|
||||
fetchedSettings?.emailPasswordSet ?? false
|
||||
);
|
||||
@@ -63,6 +68,7 @@ const Settings = () => {
|
||||
useEffect(() => {
|
||||
if (fetchedSettings) {
|
||||
setIsApiKeySet(fetchedSettings?.pagespeedKeySet);
|
||||
setIsGlobalpingKeySet(fetchedSettings?.globalpingKeySet);
|
||||
setIsEmailPasswordSet(fetchedSettings?.emailPasswordSet);
|
||||
}
|
||||
}, [fetchedSettings]);
|
||||
@@ -74,10 +80,14 @@ const Settings = () => {
|
||||
if (response?.data) {
|
||||
const data = response.data;
|
||||
setIsApiKeySet(data.pagespeedKeySet);
|
||||
setIsGlobalpingKeySet(data.globalpingKeySet);
|
||||
setIsEmailPasswordSet(data.emailPasswordSet);
|
||||
if (data.pagespeedKeySet === true) {
|
||||
setApiKeyHasBeenReset(false);
|
||||
}
|
||||
if (data.globalpingKeySet === true) {
|
||||
setGlobalpingKeyHasBeenReset(false);
|
||||
}
|
||||
if (data.emailPasswordSet === true) {
|
||||
setEmailPasswordHasBeenReset(false);
|
||||
}
|
||||
@@ -134,6 +144,16 @@ const Settings = () => {
|
||||
defaults={defaults}
|
||||
setValue={setValue}
|
||||
/>
|
||||
<SettingsGlobalping
|
||||
isAdmin={isAdmin}
|
||||
HEADING_SX={HEADING_SX}
|
||||
isGlobalpingKeySet={isGlobalpingKeySet}
|
||||
globalpingKeyHasBeenReset={globalpingKeyHasBeenReset}
|
||||
setGlobalpingKeyHasBeenReset={setGlobalpingKeyHasBeenReset}
|
||||
control={control}
|
||||
defaults={defaults}
|
||||
setValue={setValue}
|
||||
/>
|
||||
<SettingsURL
|
||||
HEADING_SX={HEADING_SX}
|
||||
control={control}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { BasePage } from "@/Components/v2/design-elements";
|
||||
import { HeaderTimeRange } from "@/Components/v2/common";
|
||||
import Stack from "@mui/material/Stack";
|
||||
import Box from "@mui/material/Box";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Tabs from "@mui/material/Tabs";
|
||||
import Tab from "@mui/material/Tab";
|
||||
import {
|
||||
HistogramStatus,
|
||||
RadialAvgResponse,
|
||||
@@ -17,7 +21,7 @@ import { useState, useMemo } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useGet } from "@/Hooks/UseApi";
|
||||
import type { MonitorDetailsResponse } from "@/Types/Monitor";
|
||||
import type { MonitorDetailsResponse, LocationCheckData } from "@/Types/Monitor";
|
||||
import type { ChecksResponse } from "@/Types/Check";
|
||||
import type { RootState } from "@/Types/state";
|
||||
import { formatDateWithTz } from "@/Utils/TimeUtils";
|
||||
@@ -38,6 +42,7 @@ const UptimeDetailsPage = () => {
|
||||
const [page, setPage] = useState<number>(0);
|
||||
const [rowsPerPage, setRowsPerPage] = useState<number>(5);
|
||||
const [dateRange, setDateRange] = useState<string>("recent");
|
||||
const [selectedLocationTab, setSelectedLocationTab] = useState<number>(0);
|
||||
|
||||
const monitorDetailsUrl = useMemo(() => {
|
||||
if (!monitorId) {
|
||||
@@ -108,6 +113,15 @@ const UptimeDetailsPage = () => {
|
||||
const checks = checksData?.checks ?? [];
|
||||
const checksCount = checksData?.checksCount ?? 0;
|
||||
|
||||
const locationChecks = monitorData?.locationChecks;
|
||||
const locationKeys = useMemo(
|
||||
() => (locationChecks ? Object.keys(locationChecks).sort() : []),
|
||||
[locationChecks]
|
||||
);
|
||||
const selectedLocation = locationKeys[selectedLocationTab] ?? null;
|
||||
const selectedLocationData: LocationCheckData | null =
|
||||
selectedLocation && locationChecks ? locationChecks[selectedLocation] : null;
|
||||
|
||||
return (
|
||||
<BasePage>
|
||||
<HeaderMonitorControls
|
||||
@@ -152,6 +166,63 @@ const UptimeDetailsPage = () => {
|
||||
checks={monitorData?.groupedChecks || []}
|
||||
range={dateRange}
|
||||
/>
|
||||
{locationKeys.length > 0 && (
|
||||
<Box>
|
||||
<Typography
|
||||
variant="h2"
|
||||
sx={{ mb: theme.spacing(4) }}
|
||||
>
|
||||
{t("pages.uptime.details.locations.title")}
|
||||
</Typography>
|
||||
<Tabs
|
||||
value={selectedLocationTab}
|
||||
onChange={(_e, newVal) => setSelectedLocationTab(newVal)}
|
||||
sx={{ mb: theme.spacing(4) }}
|
||||
>
|
||||
{locationKeys.map((loc) => (
|
||||
<Tab
|
||||
key={loc}
|
||||
label={loc}
|
||||
/>
|
||||
))}
|
||||
</Tabs>
|
||||
{selectedLocationData && (
|
||||
<Stack gap={theme.spacing(4)}>
|
||||
<Stack
|
||||
direction="row"
|
||||
gap={theme.spacing(8)}
|
||||
>
|
||||
<Box>
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
>
|
||||
{t("pages.uptime.details.locations.avgResponseTime")}
|
||||
</Typography>
|
||||
<Typography variant="h3">
|
||||
{Math.round(selectedLocationData.avgResponseTime)} ms
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box>
|
||||
<Typography
|
||||
variant="body2"
|
||||
color="text.secondary"
|
||||
>
|
||||
{t("pages.uptime.details.locations.uptime")}
|
||||
</Typography>
|
||||
<Typography variant="h3">
|
||||
{(selectedLocationData.uptimePercentage * 100).toFixed(1)}%
|
||||
</Typography>
|
||||
</Box>
|
||||
</Stack>
|
||||
<HistogramDetails
|
||||
checks={selectedLocationData.groupedChecks || []}
|
||||
range={dateRange}
|
||||
/>
|
||||
</Stack>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
<ChecksTable
|
||||
checks={checks}
|
||||
count={checksCount}
|
||||
|
||||
@@ -9,7 +9,8 @@ import {
|
||||
} from "@/Components/v2/design-elements";
|
||||
import { HeatmapResponseTime, HistogramResponseTime } from "@/Components/v2/common";
|
||||
import { ActionsMenu } from "@/Components/v2/actions-menu";
|
||||
import { ArrowDown, ArrowUp } from "lucide-react";
|
||||
import { ArrowDown, ArrowUp, Globe } from "lucide-react";
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useTheme } from "@mui/material/styles";
|
||||
@@ -167,7 +168,20 @@ export const MonitorTable = ({
|
||||
),
|
||||
|
||||
render: (row) => {
|
||||
return row?.name;
|
||||
return (
|
||||
<Stack
|
||||
direction="row"
|
||||
alignItems="center"
|
||||
gap={theme.spacing(2)}
|
||||
>
|
||||
{row?.name}
|
||||
{row.locations && row.locations.length > 0 && (
|
||||
<Tooltip title={`${row.locations.length} ${t("pages.uptime.table.headers.locations").toLowerCase()}: ${row.locations.join(", ")}`}>
|
||||
<Globe size={14} />
|
||||
</Tooltip>
|
||||
)}
|
||||
</Stack>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user