@@ -89,7 +89,10 @@ function usePrometheusWebSocket() {
8989 console . log ( "📥 Received WebSocket message:" , message ) ;
9090
9191 if ( message . type === "prometheusQuery" && message . data ?. requestId ) {
92- console . log ( "🎯 Processing prometheus response for ID:" , message . data . requestId ) ;
92+ console . log (
93+ "🎯 Processing prometheus response for ID:" ,
94+ message . data . requestId
95+ ) ;
9396 const pending = pendingRequests . current . get ( message . data . requestId ) ;
9497 if ( pending ) {
9598 pendingRequests . current . delete ( message . data . requestId ) ;
@@ -101,7 +104,10 @@ function usePrometheusWebSocket() {
101104 pending . resolve ( message . data ) ;
102105 }
103106 } else {
104- console . warn ( "⚠️ No pending request found for ID:" , message . data . requestId ) ;
107+ console . warn (
108+ "⚠️ No pending request found for ID:" ,
109+ message . data . requestId
110+ ) ;
105111 }
106112 }
107113 } catch ( error ) {
@@ -175,25 +181,19 @@ function usePrometheusWebSocket() {
175181 }
176182 } , 10000 ) ;
177183
178- // Check if this is a full path (starts with http) or just a query
179- const isFullPath =
180- queryOrPath . startsWith ( "http://" ) ||
181- queryOrPath . startsWith ( "https://" ) ;
182-
183- console . log ( "🔍 Is full path:" , isFullPath ) ;
184-
185184 const message = {
186185 timestamp : new Date ( ) ,
187186 type : "prometheusQuery" ,
188187 data : {
189- ...( isFullPath
190- ? { fullPath : queryOrPath }
191- : { query : queryOrPath } ) ,
188+ fullPath : queryOrPath ,
192189 requestId,
193190 } ,
194191 } ;
195192
196- console . log ( "📨 Sending WebSocket message:" , JSON . stringify ( message , null , 2 ) ) ;
193+ console . log (
194+ "📨 Sending WebSocket message:" ,
195+ JSON . stringify ( message , null , 2 )
196+ ) ;
197197
198198 try {
199199 ws . send ( JSON . stringify ( message ) ) ;
@@ -224,17 +224,17 @@ export function PrometheusQueryBox({
224224
225225 // Hardcoded query definition wrapped in useMemo
226226 const hardcodedQuery = useMemo ( ( ) => {
227- const query = `round((container_memory_usage_bytes{pod=~" ${ sessionName } .*",container="amalthea-session"} / container_spec_memory_limit_bytes{pod=~" ${ sessionName } .*",container="amalthea-session"}) * 100, 0.01) > 80 ` ;
227+ const query = `ALERTS ` ;
228228 return {
229- label : "Memory Usage " ,
229+ label : "Alerts for this session " ,
230230 query,
231231 path : `http://prometheus-server.monitoring.svc.cluster.local/api/v1/query?query=${ encodeURIComponent (
232232 query
233233 ) } `,
234- description : "Memory usage percentage for this session" ,
234+ description : "Alerts for this session" ,
235235 icon : "memory" ,
236- unit : "% " ,
237- alertThreshold : 90 ,
236+ unit : "" ,
237+ alertThreshold : 0 ,
238238 } ;
239239 } , [ sessionName ] ) ;
240240
@@ -255,20 +255,20 @@ export function PrometheusQueryBox({
255255 async ( predefinedQuery : {
256256 label : string ;
257257 query : string ;
258- path ? : string ;
258+ path : string ;
259259 description ?: string ;
260260 icon ?: string ;
261261 unit : string ;
262262 alertThreshold : number ;
263263 } ) => {
264- if ( ! predefinedQuery . query . trim ( ) && ! predefinedQuery . path ?. trim ( ) )
265- return ;
264+ if ( ! predefinedQuery . path ?. trim ( ) ) return ;
266265
267- const queryToSend = predefinedQuery . path ?. trim ( ) || predefinedQuery . query . trim ( ) ;
268- console . log ( "📤 Sending query:" , queryToSend ) ;
266+ console . log ( "📤 Sending full path:" , predefinedQuery . path ) ;
269267
270268 try {
271- const result = await sendPrometheusQueryRef . current ( queryToSend ) ;
269+ const result = await sendPrometheusQueryRef . current (
270+ predefinedQuery . path
271+ ) ;
272272 return result ;
273273 } catch ( err ) {
274274 return null ;
@@ -310,6 +310,16 @@ export function PrometheusQueryBox({
310310 }
311311 } , [ executeQuery , hardcodedQuery , sessionName ] ) ;
312312
313+ const getAlertDetails = useCallback ( ( ) => {
314+ if ( queryResults . length === 0 ) return null ;
315+ const result = queryResults [ 0 ] ;
316+ if ( result . data . result . length === 0 ) return null ;
317+
318+ const alertInfo = result . data . result [ 0 ] . metric ;
319+ const alertName = alertInfo . name ;
320+ return alertName ;
321+ } , [ queryResults ] ) ;
322+
313323 const handleCloseButton = useCallback ( ( ) => {
314324 onClose ( ) ;
315325 } , [ onClose ] ) ;
@@ -320,6 +330,8 @@ export function PrometheusQueryBox({
320330
321331 const interval = setInterval ( ( ) => {
322332 getAllQueryResults ( ) ;
333+ let alertDetails = getAlertDetails ( ) ;
334+ console . log ( "🚨 Alert details:" , alertDetails ) ;
323335 } , 15000 ) ;
324336
325337 return ( ) => {
0 commit comments