Files
twenty/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminQueueExpandableContainer.tsx
T
nitin d6655a2c3b Health monitor status for admin panel (#10186)
# Health Monitoring for Self-Hosted Instances

This PR implements basic health monitoring for self-hosted instances in
the admin panel.

## Service Status Checks
We're adding real-time health checks for:
- Redis Connection
- Database Connection
- Worker Status
- Message Sync Status

## Existing Functionality
We already have message sync and captcha counters that store aggregated
metrics in cache within a configurable time window (default: 5 minutes).

## New Endpoints
1. `/healthz` - Basic server health check for Kubernetes pod monitoring
2. `/healthz/{serviceName}` - Individual service health checks (returns
200 if healthy)
3. `/metricsz/{metricName}` - Time-windowed metrics (message sync,
captcha)
4. GraphQL resolver in admin panel for UI consumption

All endpoints use the same underlying service, with different
presentation layers for infrastructure and UI needs.

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
2025-02-18 15:52:19 +01:00

104 lines
3.5 KiB
TypeScript

import { SettingsListCard } from '@/settings/components/SettingsListCard';
import { Table } from '@/ui/layout/table/components/Table';
import { TableCell } from '@/ui/layout/table/components/TableCell';
import { TableRow } from '@/ui/layout/table/components/TableRow';
import styled from '@emotion/styled';
import { AnimatedExpandableContainer, Status } from 'twenty-ui';
import {
AdminPanelHealthServiceStatus,
AdminPanelWorkerQueueHealth,
} from '~/generated/graphql';
const StyledExpandedContent = styled.div`
border: 1px solid ${({ theme }) => theme.border.color.medium};
border-radius: ${({ theme }) => theme.border.radius.sm};
padding-top: ${({ theme }) => theme.spacing(1)};
padding-bottom: ${({ theme }) => theme.spacing(3)};
padding-left: ${({ theme }) => theme.spacing(3)};
padding-right: ${({ theme }) => theme.spacing(3)};
`;
const StyledContainer = styled.div`
margin-bottom: ${({ theme }) => theme.spacing(3)};
margin-top: ${({ theme }) => theme.spacing(5)};
`;
const StyledTableRow = styled(TableRow)`
height: ${({ theme }) => theme.spacing(6)};
`;
const StyledQueueMetricsTitle = styled.div`
color: ${({ theme }) => theme.font.color.primary};
font-size: ${({ theme }) => theme.font.size.sm};
font-weight: ${({ theme }) => theme.font.weight.medium};
margin-bottom: ${({ theme }) => theme.spacing(3)};
padding-left: ${({ theme }) => theme.spacing(3)};
`;
export const SettingsAdminQueueExpandableContainer = ({
queues,
selectedQueue,
}: {
queues: AdminPanelWorkerQueueHealth[];
selectedQueue: string | null;
}) => {
const selectedQueueData = queues.find(
(queue) => queue.name === selectedQueue,
);
return (
<AnimatedExpandableContainer
isExpanded={!!selectedQueue}
mode="fit-content"
>
{selectedQueueData && (
<>
<StyledContainer>
<SettingsListCard
items={[{ ...selectedQueueData, id: selectedQueueData.name }]}
getItemLabel={(
item: AdminPanelWorkerQueueHealth & { id: string },
) => item.name}
isLoading={false}
RowRightComponent={({
item,
}: {
item: AdminPanelWorkerQueueHealth;
}) => (
<Status
color={
item.status === AdminPanelHealthServiceStatus.OPERATIONAL
? 'green'
: 'red'
}
text={item.status.toLowerCase()}
weight="medium"
/>
)}
/>
</StyledContainer>
<StyledQueueMetricsTitle> Metrics:</StyledQueueMetricsTitle>
<StyledExpandedContent>
<Table>
<StyledTableRow>
<TableCell align="left">Workers</TableCell>
<TableCell align="right">{selectedQueueData.workers}</TableCell>
</StyledTableRow>
{Object.entries(selectedQueueData.metrics)
.filter(([key]) => key !== '__typename')
.map(([key, value]) => (
<StyledTableRow key={key}>
<TableCell align="left">
{key.charAt(0).toUpperCase() + key.slice(1)}
</TableCell>
<TableCell align="right">{value}</TableCell>
</StyledTableRow>
))}
</Table>
</StyledExpandedContent>
</>
)}
</AnimatedExpandableContainer>
);
};