import{r as c,j as i}from"./vendor-react-wBh_31cN.js";import{M as p}from"./metadata-field-B_vcklh-.js";import{S as k}from"./separator-2OqrG5Vy.js";import{V as t}from"./value-76ihWpF6.js";import{aq as Q}from"./index-BKr2rJhV.js";import{u as j}from"./useTitle-DQo_L6Ox.js";import{t as w}from"./titles-CzjGGAB3.js";import{C as a}from"./ClusterCard-DiUtFK1N.js";import{c as d,d as m,e as T,g,a as f,M as h}from"./trinoUtils-DN18CYax.js";const l=()=>Array(h).fill(0),M=()=>({runningQueries:l(),queuedQueries:l(),blockedQueries:l(),activeWorkers:l(),runningDrivers:l(),reservedMemory:l(),rowInputRate:l(),byteInputRate:l(),perWorkerCpuTimeRate:l(),lastRefresh:null,lastInputRows:0,lastInputBytes:0,lastCpuTime:0}),A=({stats:r,isLoadingStats:o,cluster:u,isLoadingCluster:y,hideHeader:x=!1})=>{j(w.queryEngine);const[e,v]=c.useState(M);return c.useEffect(()=>{r&&v(n=>{if(n.lastRefresh===null)return{...n,runningQueries:m(r.runningQueries,n.runningQueries),queuedQueries:m(r.queuedQueries,n.queuedQueries),blockedQueries:m(r.blockedQueries,n.blockedQueries),activeWorkers:m(r.activeWorkers,n.activeWorkers),runningDrivers:d(r.runningDrivers,n.runningDrivers),reservedMemory:d(r.reservedMemory,n.reservedMemory),lastInputRows:r.totalInputRows,lastInputBytes:r.totalInputBytes,lastCpuTime:r.totalCpuTimeSecs,lastRefresh:Date.now()};const R=r.totalInputRows-n.lastInputRows,b=r.totalInputBytes-n.lastInputBytes,I=r.totalCpuTimeSecs-n.lastCpuTime,s=(Date.now()-n.lastRefresh)/1e3;return{runningQueries:m(r.runningQueries,n.runningQueries),queuedQueries:m(r.queuedQueries,n.queuedQueries),blockedQueries:m(r.blockedQueries,n.blockedQueries),activeWorkers:m(r.activeWorkers,n.activeWorkers),runningDrivers:d(r.runningDrivers,n.runningDrivers),reservedMemory:d(r.reservedMemory,n.reservedMemory),rowInputRate:d(R/(s||1),n.rowInputRate),byteInputRate:d(b/(s||1),n.byteInputRate),perWorkerCpuTimeRate:d(I/(r.activeWorkers||1)/(s||1),n.perWorkerCpuTimeRate),lastInputRows:r.totalInputRows,lastInputBytes:r.totalInputBytes,lastCpuTime:r.totalCpuTimeSecs,lastRefresh:Date.now()}})},[r]),y?i.jsx(Q,{}):i.jsxs("div",{className:"flex flex-col",children:[!x&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex justify-end gap-20",children:[i.jsx(p,{label:"Version",className:"w-max",children:i.jsx(t,{primary:!0,children:u==null?void 0:u.nodeVersion.version})}),i.jsx(p,{label:"Environment",className:"w-max",children:i.jsx(t,{primary:!0,children:u==null?void 0:u.environment})}),i.jsx(p,{label:"Uptime",className:"w-max",children:i.jsx(t,{primary:!0,children:u==null?void 0:u.uptime})})]}),i.jsx("div",{className:"w-full",children:i.jsx(k,{className:"my-5 h-[3px] bg-border"})})]}),i.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-5",children:[i.jsx(a,{title:"Running queries",values:e==null?void 0:e.runningQueries,loading:o,tooltip:"Total number of queries currently running"}),i.jsx(a,{title:"Active workers",values:e==null?void 0:e.activeWorkers,loading:o,tooltip:"Total number of active worker nodes"}),i.jsx(a,{title:"Input Rows/s",values:e==null?void 0:e.rowInputRate,loading:o,tooltip:"Moving average of input rows processed per second",numberFormatter:T}),i.jsx(a,{title:"Queued queries",values:e==null?void 0:e.queuedQueries,loading:o,tooltip:"Total number of queries currently queued and awaiting execution"}),i.jsx(a,{title:"Runnable drivers",values:e==null?void 0:e.runningDrivers,loading:o,tooltip:"Moving average of total running drivers",numberFormatter:g}),i.jsx(a,{title:"Input Bytes/s",values:e==null?void 0:e.byteInputRate,loading:o,tooltip:"Moving average of input bytes processed per second",numberFormatter:f}),i.jsx(a,{title:"Blocked Queries",values:e==null?void 0:e.blockedQueries,loading:o,tooltip:"Total number of queries currently blocked and unable to make progress"}),i.jsx(a,{title:"Reserved Memory (B)",values:e==null?void 0:e.reservedMemory,loading:o,tooltip:"Total amount of memory reserved by all running queries",numberFormatter:f}),i.jsx(a,{title:"Worker Parallelism",values:e==null?void 0:e.perWorkerCpuTimeRate,loading:o,tooltip:"Moving average of CPU time utilized per second per worker",numberFormatter:g})]})]})};export{A as T};
