File tree Expand file tree Collapse file tree
client/src/features/overview/pages Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,21 @@ function ServerInstance() {
2828 useEffect ( ( ) => {
2929 if ( ! instance ) return ;
3030
31+ // Fetch metrics immediately on page load
32+ const fetchMetrics = async ( ) => {
33+ try {
34+ const response = await axiosInstance . get ( `/api/metrics/instance?pod=${ instance . podName } ` ) ;
35+ if ( response . data . success ) {
36+ setMetrics ( response . data . data . metrics ) ;
37+ }
38+ } catch ( error ) {
39+ console . error ( 'Failed to fetch initial metrics:' , error ) ;
40+ }
41+ } ;
42+
43+ fetchMetrics ( ) ;
44+
45+ // Set up WebSocket listener for real-time updates
3146 const metricsListener = new InstanceMetricsListener ( ( data ) => {
3247 if ( data . podName === instance . podName ) {
3348 setMetrics ( data . metrics ) ;
Original file line number Diff line number Diff line change 1+ import { ApiEndpoint , AuthType } from '../types' ;
2+ import InstanceMetricsService from '../../services/instanceMetricsService' ;
3+ import { InstanceResourceMetrics } from '../../../../shared/model/instance' ;
4+
5+ export interface GetInstanceMetricsResponse {
6+ podName : string ;
7+ metrics : InstanceResourceMetrics ;
8+ }
9+
10+ export const getInstanceMetricsEndpoint : ApiEndpoint < unknown , GetInstanceMetricsResponse > = {
11+ path : '/api/metrics/instance' ,
12+ method : 'get' ,
13+ auth : AuthType . Basic ,
14+ handler : async ( req , res ) => {
15+ try {
16+ const { pod } = req . query ;
17+
18+ if ( ! pod || typeof pod !== 'string' ) {
19+ return res . status ( 400 ) . json ( {
20+ success : false ,
21+ error : 'Pod name is required'
22+ } ) ;
23+ }
24+
25+ const metricsService = InstanceMetricsService . getInstance ( ) ;
26+ const metrics = await metricsService . getMetricsForPod ( pod ) ;
27+
28+ res . json ( {
29+ success : true ,
30+ data : {
31+ podName : pod ,
32+ metrics
33+ }
34+ } ) ;
35+ } catch ( error ) {
36+ console . error ( 'Failed to fetch instance metrics:' , error ) ;
37+ res . status ( 500 ) . json ( {
38+ success : false ,
39+ error : 'Failed to fetch instance metrics'
40+ } ) ;
41+ }
42+ }
43+ } ;
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import {resetPasswordEndpoint} from "../../../api/users/resetPassword";
3131import { deleteUserEndpoint } from "../../../api/users/deleteUser" ;
3232import { getCpuMetricsEndpoint } from "../../../api/metrics/getCpuMetrics" ;
3333import { getMemoryMetricsEndpoint } from "../../../api/metrics/getMemoryMetrics" ;
34+ import { getInstanceMetricsEndpoint } from "../../../api/metrics/getInstanceMetrics" ;
3435import { getDeploymentsEndpoint } from "../../../api/deployments/getDeployments" ;
3536import { ApiEndpoint , AuthType } from "../../../api/types" ;
3637import { handleAdminAuth , handleBasicAuth } from "../../../middleware/auth" ;
@@ -127,6 +128,7 @@ export default class ApiManager {
127128 //Metrics
128129 this . addEndpoint ( getCpuMetricsEndpoint ) ;
129130 this . addEndpoint ( getMemoryMetricsEndpoint ) ;
131+ this . addEndpoint ( getInstanceMetricsEndpoint ) ;
130132
131133 //File Sessions
132134 this . addEndpoint ( createSessionEndpoint ) ;
Original file line number Diff line number Diff line change @@ -54,6 +54,11 @@ class InstanceMetricsService {
5454 }
5555 }
5656
57+ public async getMetricsForPod ( podName : string , namespace : string = 'default' ) : Promise < InstanceResourceMetrics > {
58+ const instance = { podName } as Instance ;
59+ return await this . getInstanceMetrics ( instance ) ;
60+ }
61+
5762 private async broadcastMetrics ( ) : Promise < void > {
5863 if ( ! this . socketManager ) {
5964 console . warn ( 'SocketManager not set, skipping metrics broadcast' ) ;
You can’t perform that action at this time.
0 commit comments