@@ -9,12 +9,13 @@ import {
99 Spin ,
1010 Statistic ,
1111 Table ,
12+ Tabs ,
1213 Tag ,
1314 Typography ,
1415} from 'antd' ;
1516import type { ColumnsType } from 'antd/es/table' ;
1617import dayjs from 'dayjs' ;
17- import { useMemo } from 'react' ;
18+ import { useMemo , useState } from 'react' ;
1819import {
1920 api ,
2021 type InternalMetricCounter ,
@@ -53,6 +54,48 @@ type EndpointRow = {
5354 total : number ;
5455} ;
5556
57+ const SERVICE_STATUS_TARGETS = [
58+ {
59+ key : 'jd1' ,
60+ label : 'jd1' ,
61+ host : '1.rnupdate.online' ,
62+ baseUrl : 'https://1.rnupdate.online/api' ,
63+ } ,
64+ {
65+ key : 'jd2' ,
66+ label : 'jd2' ,
67+ host : '2.rnupdate.online' ,
68+ baseUrl : 'https://2.rnupdate.online/api' ,
69+ } ,
70+ {
71+ key : 'jd3' ,
72+ label : 'jd3' ,
73+ host : '3.rnupdate.online' ,
74+ baseUrl : 'https://3.rnupdate.online/api' ,
75+ } ,
76+ {
77+ key : 'jd4' ,
78+ label : 'jd4' ,
79+ host : '4.rnupdate.online' ,
80+ baseUrl : 'https://4.rnupdate.online/api' ,
81+ } ,
82+ {
83+ key : 's1' ,
84+ label : 's1' ,
85+ host : 's1.reactnative.cn' ,
86+ baseUrl : 'https://s1.reactnative.cn/api' ,
87+ } ,
88+ {
89+ key : 'p' ,
90+ label : 'p' ,
91+ host : 'p.reactnative.cn' ,
92+ baseUrl : 'https://p.reactnative.cn/api' ,
93+ } ,
94+ ] as const ;
95+
96+ type ServiceStatusTarget = ( typeof SERVICE_STATUS_TARGETS ) [ number ] ;
97+ type ServiceStatusTargetKey = ServiceStatusTarget [ 'key' ] ;
98+
5699const counterLabels : Record < string , string > = {
57100 'api.request.error' : '5xx' ,
58101 'api.request.total' : '请求' ,
@@ -449,15 +492,19 @@ const endpointColumns: ColumnsType<EndpointRow> = [
449492 } ,
450493] ;
451494
452- export const Component = ( ) => {
495+ function ServiceStatusPanel ( { target } : { target : ServiceStatusTarget } ) {
453496 const {
454497 data : snapshot ,
455498 error,
456499 isFetching,
457500 refetch,
458501 } = useQuery ( {
459- queryFn : ( ) => api . getInternalMetrics ( ) ,
460- queryKey : [ 'internalMetrics' ] ,
502+ queryFn : ( ) =>
503+ api . getInternalMetrics ( {
504+ baseUrl : target . baseUrl ,
505+ suppressErrorToast : true ,
506+ } ) ,
507+ queryKey : [ 'internalMetrics' , target . key ] ,
461508 refetchInterval : 30_000 ,
462509 } ) ;
463510
@@ -505,13 +552,14 @@ export const Component = () => {
505552 : 0 ;
506553
507554 return (
508- < div className = "page-section" >
555+ < >
509556 < div className = "mb-4 flex flex-col gap-3 md:flex-row md:items-center md:justify-between" >
510557 < div >
511- < Title level = { 4 } className = "m-0!" >
512- 服务状态
558+ < Title level = { 5 } className = "m-0!" >
559+ { target . label }
513560 </ Title >
514561 < div className = "mt-1 flex flex-wrap gap-2" >
562+ < Tag > { target . host } </ Tag >
515563 { snapshot ?. generatedAt && (
516564 < Tag >
517565 { dayjs ( snapshot . generatedAt ) . format ( 'YYYY-MM-DD HH:mm:ss' ) }
@@ -638,6 +686,42 @@ export const Component = () => {
638686 />
639687 </ Card >
640688 </ Spin >
689+ </ >
690+ ) ;
691+ }
692+
693+ export const Component = ( ) => {
694+ const [ activeTargetKey , setActiveTargetKey ] =
695+ useState < ServiceStatusTargetKey > ( SERVICE_STATUS_TARGETS [ 0 ] . key ) ;
696+ const activeTarget =
697+ SERVICE_STATUS_TARGETS . find ( ( target ) => target . key === activeTargetKey ) ??
698+ SERVICE_STATUS_TARGETS [ 0 ] ;
699+
700+ return (
701+ < div className = "page-section" >
702+ < div className = "mb-4" >
703+ < Title level = { 4 } className = "m-0!" >
704+ 服务状态
705+ </ Title >
706+ < Text type = "secondary" > 按节点查看内部指标和运行状态。</ Text >
707+ </ div >
708+ < Tabs
709+ activeKey = { activeTarget . key }
710+ className = "mb-4"
711+ items = { SERVICE_STATUS_TARGETS . map ( ( target ) => ( {
712+ key : target . key ,
713+ label : (
714+ < span className = "inline-flex items-center gap-2" >
715+ < span > { target . label } </ span >
716+ < span className = "hidden text-xs text-slate-400 md:inline" >
717+ { target . host }
718+ </ span >
719+ </ span >
720+ ) ,
721+ } ) ) }
722+ onChange = { ( key ) => setActiveTargetKey ( key as ServiceStatusTargetKey ) }
723+ />
724+ < ServiceStatusPanel key = { activeTarget . key } target = { activeTarget } />
641725 </ div >
642726 ) ;
643727} ;
0 commit comments