-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#7716] Config > Admin > Agent Statistic
- Loading branch information
1 parent
e3c4cdd
commit 2b30132
Showing
16 changed files
with
502 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
15 changes: 15 additions & 0 deletions
15
web-frontend/src/main/v3/apps/web/src/pages/config/AgentStatistic.tsx
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,15 @@ | ||
import { useAtomValue } from 'jotai'; | ||
import { getLayoutWithConfiguration, getLayoutWithSideNavigation } from '@/components/Layout'; | ||
import { AgentStatisticPage as CommonAgentStatisticPage, withInitialFetch } from '@pinpoint-fe/ui'; | ||
import { configurationAtom } from '@pinpoint-fe/atoms'; | ||
|
||
export interface AgentStatisticPageProps {} | ||
const AgentStatisticPage = () => { | ||
const configuration = useAtomValue(configurationAtom); | ||
|
||
return <CommonAgentStatisticPage configuration={configuration} />; | ||
}; | ||
|
||
export default withInitialFetch((props: AgentStatisticPageProps) => | ||
getLayoutWithSideNavigation(getLayoutWithConfiguration(<AgentStatisticPage {...props} />)), | ||
); |
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
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
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
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
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
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
13 changes: 13 additions & 0 deletions
13
web-frontend/src/main/v3/packages/hooks/src/api/useAgentsStatistics.ts
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,13 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { END_POINTS, SearchApplication } from '@pinpoint-fe/constants'; | ||
import { queryFn } from './reactQueryHelper'; | ||
|
||
export const useGetAgentsStatistics = (load: boolean) => { | ||
const { data, isLoading, refetch } = useQuery<SearchApplication.Response>({ | ||
queryKey: [END_POINTS.AGENT_STATISTICS], | ||
queryFn: queryFn(`${END_POINTS.AGENT_STATISTICS}`), | ||
enabled: !!load, | ||
}); | ||
|
||
return { data, isLoading, refetch }; | ||
}; |
61 changes: 61 additions & 0 deletions
61
...tend/src/main/v3/packages/ui/src/components/Config/agentStatistic/AgentStatisticChart.tsx
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,61 @@ | ||
import { colors } from '../../../constant'; | ||
import { | ||
ChartConfig, | ||
ChartContainer, | ||
ChartLegend, | ||
ChartLegendContent, | ||
} from '../../../components/ui'; | ||
import { XAxis, YAxis, LabelList, Bar, BarChart } from 'recharts'; | ||
|
||
export type ChartData = { | ||
vmVersion?: string; | ||
agentVersion?: string; | ||
value: number; | ||
}; | ||
|
||
export function AgentStatisticChart({ | ||
type, | ||
chartData, | ||
}: { | ||
type: 'vmVersion' | 'agentVersion'; | ||
chartData?: ChartData[]; | ||
}) { | ||
const chartConfig = { | ||
value: { | ||
label: type === 'vmVersion' ? 'JVM' : 'Agent', | ||
color: type === 'vmVersion' ? colors.blue[600] : colors.orange[500], | ||
}, | ||
} satisfies ChartConfig; | ||
|
||
return ( | ||
<ChartContainer config={chartConfig} className="w-full h-full"> | ||
<BarChart | ||
accessibilityLayer | ||
data={chartData} | ||
layout="vertical" | ||
margin={{ | ||
right: 50, | ||
left: 15, | ||
}} | ||
> | ||
<XAxis type="number" dataKey={'value'} /> | ||
<YAxis | ||
dataKey={type} | ||
type="category" | ||
width={type === 'vmVersion' ? 60 : 120} | ||
tickLine={false} | ||
/> | ||
<ChartLegend content={<ChartLegendContent />} /> | ||
<Bar dataKey="value" fill="var(--color-value)"> | ||
<LabelList | ||
dataKey="value" | ||
position="right" | ||
offset={8} | ||
className="fill-foreground" | ||
fontSize={12} | ||
/> | ||
</Bar> | ||
</BarChart> | ||
</ChartContainer> | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
...main/v3/packages/ui/src/components/Config/agentStatistic/AgentStatisticChartContainer.tsx
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,34 @@ | ||
import React from 'react'; | ||
import { AgentStatisticChart, ChartData } from './AgentStatisticChart'; | ||
import { SearchApplication } from '@pinpoint-fe/constants'; | ||
|
||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const useVersionChartData = (data: any, versionKey: 'vmVersion' | 'agentVersion') => | ||
React.useMemo(() => { | ||
const instances = data?.flatMap((group: SearchApplication.Application) => group.instancesList); | ||
|
||
const versionCounts = instances?.reduce((acc: any, instance: SearchApplication.Instance) => { | ||
const version = instance[versionKey]; | ||
if (version) { | ||
acc[version] = (acc[version] || 0) + 1; | ||
} | ||
return acc; | ||
}, {} as any); | ||
|
||
return Object.entries(versionCounts || {}).map(([version, value]) => ({ | ||
[versionKey]: version, | ||
value, | ||
})); | ||
}, [data, versionKey]); | ||
|
||
export function AgentStatisticContainer({ data }: { data?: SearchApplication.Application[] }) { | ||
const vmVersionChartData = useVersionChartData(data, 'vmVersion'); | ||
const agentVersionChartData = useVersionChartData(data, 'agentVersion'); | ||
|
||
return ( | ||
<div className="flex min-w-full gap-5 max-h-[40%]"> | ||
<AgentStatisticChart type="vmVersion" chartData={vmVersionChartData as ChartData[]} /> | ||
<AgentStatisticChart type="agentVersion" chartData={agentVersionChartData as ChartData[]} /> | ||
</div> | ||
); | ||
} |
78 changes: 78 additions & 0 deletions
78
...nd/src/main/v3/packages/ui/src/components/Config/agentStatistic/AgentStatisticFetcher.tsx
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,78 @@ | ||
import React from 'react'; | ||
import { HiOutlineRefresh } from 'react-icons/hi'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Configuration } from '@pinpoint-fe/constants'; | ||
import { Button, Separator } from '../../../components'; | ||
import { useGetAgentsStatistics } from '@pinpoint-fe/hooks'; | ||
import { CgSpinner } from 'react-icons/cg'; | ||
import { cn } from '../../../lib'; | ||
import { AgentStatisticContainer } from './AgentStatisticChartContainer'; | ||
import { AgentStatisticTable } from './AgentStatisticTable'; | ||
import { format } from 'date-fns'; | ||
|
||
export interface AgentStatisticFetcherProps { | ||
configuration?: Configuration; | ||
} | ||
|
||
export const AgentStatisticFetcher = ({ configuration }: AgentStatisticFetcherProps) => { | ||
void configuration; // Not use configuration | ||
|
||
const { t } = useTranslation(); | ||
const [load, setLoad] = React.useState(false); | ||
const [loadDate, setLoadDate] = React.useState<Date>(); | ||
|
||
const { data, isLoading, refetch } = useGetAgentsStatistics(load); | ||
|
||
function handleClickLoad() { | ||
setLoad(true); | ||
} | ||
|
||
function handleReload() { | ||
refetch(); | ||
} | ||
|
||
React.useEffect(() => { | ||
setLoadDate(new Date()); | ||
}, [data]); | ||
|
||
return ( | ||
<div className="flex flex-col h-full"> | ||
<div className="flex gap-10"> | ||
<h3 className="text-lg font-semibold">Agent statistic</h3> | ||
</div> | ||
<Separator className="my-6" /> | ||
<div className="bg-red-300"></div> | ||
<div className="h-[-webkit-fill-available] relative overflow-hidden"> | ||
{isLoading && ( | ||
<div className="absolute flex items-center justify-center w-full h-full"> | ||
<CgSpinner className="absolute opacity-100 animate-spin" size={100} /> | ||
<div className="w-full h-full bg-gray-400 opacity-20"></div> | ||
</div> | ||
)} | ||
{data ? ( | ||
<div className="flex flex-col h-full gap-5"> | ||
<div className="flex flex-row items-center justify-end gap-1"> | ||
{loadDate && format(loadDate, 'yyyy.MM.dd HH:mm:ss')} | ||
<Button onClick={handleReload} size="sm"> | ||
<HiOutlineRefresh size={18} /> | ||
</Button> | ||
</div> | ||
<AgentStatisticContainer data={data} /> | ||
<AgentStatisticTable data={data} /> | ||
</div> | ||
) : ( | ||
<div | ||
className={cn('flex flex-col items-center justify-center h-full gap-3', { | ||
'opacity-20': isLoading, | ||
})} | ||
> | ||
{t('CONFIGURATION.AGENT_STATISTIC.LOAD_GUIDE')} | ||
<Button className="w-max" onClick={handleClickLoad} disabled={isLoading}> | ||
{t('CONFIGURATION.AGENT_STATISTIC.LOADING')} | ||
</Button> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.