import{r as a,u as D,j as e,T as k,bf as Q,K as i,s as U,b3 as X,o as l,p as P,k as M,d5 as Y,bl as ee,d as te,Z as re,C as ne,V as se,i as v,a as h,aH as T,b,d6 as oe,J as ie,by as ae,aD as le,d7 as me,G as C,H as R,l as ce,m as ue,A as de,bn as pe}from"./index-CCv_8omK.js";import{u as fe,T as xe}from"./html-title-xzTyg8m0.js";import{T as ge}from"./traffic-DrN7qkrg.js";import{H as he}from"./index-4-FW3N_0.js";import{x as V}from"./index-DRYJ0xIl.js";import{C as ye,M as L}from"./memory-r4Kexlry.js";import{C as ve}from"./CardContent-gyrk9EIw.js";import{u as Ce}from"./useLocalStorage-CbBU4OS9.js";import{T as je,a as Ie}from"./ToggleButtonGroup-uvIn6Jyh.js";import"./iframe-DhbAf7eB.js";import"./ChevronLeft-OivB2aTv.js";import"./ChevronRight-CV3PmYHH.js";import"./index-DBii9-f-.js";import"./typeof-QjJsDpFa.js";import"./base-chart-AQkuFrPC.js";import"./index-CEPQQlo6.js";import"./AdapterDayjs-AIDIzsfb.js";import"./useThemeProps-CRd6upHX.js";import"./CSSTransition-Cf_KzaPo.js";import"./visuallyHidden-Dan1xhjv.js";import"./FilterList-xUYmSJ-Y.js";import"./emotion-cache.browser.esm-CdT-VIlA.js";import"./index-hu34K3US.js";import"./redux-DfszZyTl.js";import"./depsEqual-BNz3Z5UN.js";import"./index-DkBdKcP-.js";import"./TableSearch-CAaRXXpO.js";import"./Search-3L2yy5pr.js";import"./Clear-Cz6Yzx0g.js";import"./MoreVert-BUlWqUnK.js";import"./getValidReactChildren-BQH98pcn.js";const be=o=>a.createElement("svg",{width:32,height:32,viewBox:"0 0 32 32",xmlns:"http://www.w3.org/2000/svg",...o},a.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M2.08295 3.2C2.08295 2.58144 2.58439 2.08 3.20295 2.08H28.8029C29.4215 2.08 29.9229 2.58144 29.9229 3.2V13.44C29.9229 14.0586 29.4215 14.56 28.8029 14.56H3.20295C2.58439 14.56 2.08295 14.0586 2.08295 13.44V3.2ZM4.32295 4.32V12.32H27.6829V4.32H4.32295ZM2.08295 18.56C2.08295 17.9414 2.58439 17.44 3.20295 17.44H28.8029C29.4215 17.44 29.9229 17.9414 29.9229 18.56V28.8C29.9229 29.4186 29.4215 29.92 28.8029 29.92H3.20295C2.58439 29.92 2.08295 29.4186 2.08295 28.8V18.56ZM4.32295 19.68V27.68H27.6829V19.68H4.32295Z",fill:"currentColor"}),a.createElement("path",{d:"M8.96297 7.04001H7.68297C7.51323 7.04001 7.35044 7.10744 7.23042 7.22746C7.1104 7.34748 7.04297 7.51027 7.04297 7.68001V8.96001C7.04297 9.12975 7.1104 9.29253 7.23042 9.41256C7.35044 9.53258 7.51323 9.60001 7.68297 9.60001H8.96297C9.13271 9.60001 9.29549 9.53258 9.41552 9.41256C9.53554 9.29253 9.60297 9.12975 9.60297 8.96001V7.68001C9.60297 7.51027 9.53554 7.34748 9.41552 7.22746C9.29549 7.10744 9.13271 7.04001 8.96297 7.04001ZM8.96297 22.4H7.68297C7.51323 22.4 7.35044 22.4674 7.23042 22.5875C7.1104 22.7075 7.04297 22.8703 7.04297 23.04V24.32C7.04297 24.4897 7.1104 24.6525 7.23042 24.7726C7.35044 24.8926 7.51323 24.96 7.68297 24.96H8.96297C9.13271 24.96 9.29549 24.8926 9.41552 24.7726C9.53554 24.6525 9.60297 24.4897 9.60297 24.32V23.04C9.60297 22.8703 9.53554 22.7075 9.41552 22.5875C9.29549 22.4674 9.13271 22.4 8.96297 22.4ZM14.083 7.04001H12.803C12.6332 7.04001 12.4704 7.10744 12.3504 7.22746C12.2304 7.34748 12.163 7.51027 12.163 7.68001V8.96001C12.163 9.12975 12.2304 9.29253 12.3504 9.41256C12.4704 9.53258 12.6332 9.60001 12.803 9.60001H14.083C14.2527 9.60001 14.4155 9.53258 14.5355 9.41256C14.6555 9.29253 14.723 9.12975 14.723 8.96001V7.68001C14.723 7.51027 14.6555 7.34748 14.5355 7.22746C14.4155 7.10744 14.2527 7.04001 14.083 7.04001ZM14.083 22.4H12.803C12.6332 22.4 12.4704 22.4674 12.3504 22.5875C12.2304 22.7075 12.163 22.8703 12.163 23.04V24.32C12.163 24.4897 12.2304 24.6525 12.3504 24.7726C12.4704 24.8926 12.6332 24.96 12.803 24.96H14.083C14.2527 24.96 14.4155 24.8926 14.5355 24.7726C14.6555 24.6525 14.723 24.4897 14.723 24.32V23.04C14.723 22.8703 14.6555 22.7075 14.5355 22.5875C14.4155 22.4674 14.2527 22.4 14.083 22.4Z",fill:"currentColor"}));function Me(){const{api:o,info:s}=D();return e.jsx(ge,{client:o,did:s.did})}function $({style:o={},title:s=null,value:m=null,graph:c=null,description:p=null,empty:f=null}){return e.jsx(ke,{children:e.jsxs(ve,{style:{...o},children:[e.jsx(k,{sx:{color:"text.secondary",fontSize:14},children:s}),f&&Q.isValidElement(f)?e.jsx(i,{style:{height:150},sx:{color:"text.secondary",display:"flex",justifyContent:"center",alignItems:"center"},children:f}):e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"h5",component:"div",sx:{mt:1},children:m}),c,!!p&&e.jsx(i,{sx:{display:"flex",color:"text.secondary",fontSize:12,marginTop:3},children:p})]})]})})}$.propTypes={style:l.object,title:l.node,value:l.node,graph:l.node,description:l.any,empty:l.node};const ke=U(X)`
  .card-content {
    height: 150px;
  }

  .card-sparkline {
    flex: 2;
    display: flex;
    position: relative;
    *[hidden] {
      display: none;
    }
  }
  .sparkline {
    stroke: ${o=>o.theme.palette.primary.main};
    fill: ${o=>o.theme.palette.primary.main}1A;
  }
  .tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 2px 5px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 9999;
  }
  .sparkline--cursor {
    stroke: orange;
  }

  .sparkline--spot {
    fill: red;
    stroke: red;
  }
`;function Ee(o){return e.jsx(Y,{...o,sx:ee(s=>({".MuiLinearProgress-root":{height:10},".MuiLinearProgress-colorPrimary":{backgroundColor:s.palette.grey[s.palette.mode==="light"?200:700]},".MuiLinearProgress-bar":{backgroundColor:s.palette.secondary.main}}),o.sx)})}function A(o){const{value:s}=o;return e.jsxs(i,{sx:{display:"flex",alignItems:"center",mt:2},children:[e.jsx(i,{style:{overflow:"hidden"},sx:{width:"100%",mr:1},children:e.jsx(Ee,{variant:"determinate",...o})}),e.jsx(i,{sx:{minWidth:35},children:e.jsx(k,{variant:"body2",color:"textSecondary",children:`${Math.round(s)}%`})})]})}A.propTypes={value:l.number.isRequired};function Z({disk:o={used:0,free:0,total:1,device:""}}){const{t:s}=a.useContext(P),m=[{id:1,className:"used",title:s("system.used"),metric:M(o.used)},{id:2,className:"free",title:s("system.free"),metric:M(o.free)},{id:3,className:"total",title:s("system.total"),metric:M(o.total)}];return e.jsx($,{title:`${s("common.disk")} (${o.device})`,value:M(o.used),graph:e.jsx(i,{sx:{mt:3},children:e.jsx(A,{value:o.used/o.total*100})}),description:m.map((c,p)=>e.jsxs(i,{sx:{marginLeft:p===0?0:2},children:[c.title,": ",c.metric]},c.title))})}Z.propTypes={disk:l.shape({used:l.number,free:l.number,total:l.number,device:l.string})};const w={uptime:0,pid:-1,cpuUsage:0,memoryUsage:0},z="Blocklet Server";function _({initialBlocklets:o}){const{t:s,locale:m}=se(),{api:c,info:p}=D(),[f,E]=Ce("runtime-view-interval",6),[x,j]=a.useState(null),[g,I]=a.useState([]),H=a.useCallback(t=>{j(t)},[]);a.useEffect(()=>{const t=[];t.push({type:"server",groupId:"server",groupName:z,id:"server:daemon",name:"Server (Daemon)",runtimeInfo:w}),t.push({type:"server",groupId:"server",groupName:z,id:"server:service",name:"Server (Service)",runtimeInfo:w}),o.forEach(r=>{v.forEachBlockletSync(r,(n,{id:u,ancestors:d})=>{n.runtimeInfo&&t.push({type:"blocklet",groupId:r.meta.did,groupName:v.getDisplayName(r),id:u,name:v.getDisplayName(n,!0),blocklet:r,component:n,runtimeInfo:n.runtimeInfo,ancestors:d})})}),I(t)},[!!o?.[0]?.appRuntimeInfo]);const[y,F]=a.useState({os:{platform:""},mem:{used:0,free:0,total:1},cpu:{cpus:[],currentLoad:1},disks:[],daemon:{},service:{}}),[N,O]=a.useState({cpu:[],mem:[],daemonMem:[],serviceMem:[]});h(T.EVENTS.NODE_RUNTIME_INFO,t=>{t.mem.total=t.mem.total||0,t.mem.used=t.mem.total-(t.mem.available||0),F(t),I(r=>r.map(n=>n.id==="server:daemon"?{...n,runtimeInfo:{...n.runtimeInfo,...t.daemon}}:n.id==="server:service"?{...n,runtimeInfo:{...n.runtimeInfo,...t.service}}:n))}),h(T.EVENTS.BLOCKLETS_RUNTIME_INFO,t=>{if(!t||!t.length){console.error("incorrect blocklets runtime info format",t);return}I(r=>r.map(n=>{const u=t.find(d=>d.componentId===n.id);return u?{...n,runtimeInfo:{...n.runtimeInfo,...u.runtimeInfo}}:n}))});const B=t=>{I(r=>r.filter(n=>n.groupId!==t.meta.did))},S=async t=>{try{const{blocklet:r}=await c.getBlocklet({input:{did:t.meta.did,attachRuntimeInfo:!0}});r.status!=="running"&&B(r),I(n=>{const u=n.filter(d=>d.groupId!==r.meta.did);return v.forEachBlockletSync(r,(d,{id:K,ancestors:J})=>{d.runtimeInfo&&u.push({type:"blocklet",groupId:r.meta.did,groupName:v.getDisplayName(r),id:K,name:v.getDisplayName(d,!0),blocklet:r,component:d,runtimeInfo:d.runtimeInfo,ancestors:J})}),u})}catch(r){R.error(r.message)}};h(b.BlockletEvents.removed,B),h(b.BlockletEvents.startFailed,B),h(b.BlockletEvents.statusChange,t=>{if(t.status!=="running"){B(t);return}S(t)}),h(b.BlockletEvents.updated,S),h(b.BlockletEvents.started,S);const G=()=>{c.getNodeRuntimeHistory({input:{hours:f}}).then(t=>{const r=t.history||[];O({cpu:r.map(n=>({date:n.date,value:n.cpu})),mem:r.map(n=>({date:n.date,value:n.mem})),daemonMem:r.map(n=>({date:n.date,value:n.daemonMem})),serviceMem:r.map(n=>({date:n.date,value:n.serviceMem}))})}).catch(t=>{R.error(t.message)})};a.useEffect(()=>{G()},[f]);const W=t=>ce(Number(t||0),{locale:ue(m)}),q=[{label:s("common.group"),name:"groupName",options:{customBodyRenderLite(t){const{type:r,blocklet:n,groupName:u}=g[t];return r==="server"?e.jsxs(i,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(oe,{width:"14",height:"14"}),e.jsx(i,{sx:{ml:1},children:u})]}):e.jsxs(i,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(ie,{size:14,blocklet:n}),e.jsx(i,{sx:{ml:1},children:u})]})}}},{label:s("common.name"),name:"name",options:{customBodyRenderLite(t){const{type:r,name:n,component:u,ancestors:d}=g[t];return r==="server"?e.jsxs(i,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(be,{width:"14",height:"14"}),e.jsx(i,{sx:{ml:1},children:n})]}):e.jsxs(i,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(ae,{size:14,blocklet:u,ancestors:d}),e.jsx(i,{sx:{ml:1},children:n})]})}}},{label:s("common.uptime"),name:"runtimeInfo.uptime",options:{customBodyRenderLite(t){const{runtimeInfo:r}=g[t];return W(r.uptime)}}},{label:s("blocklet.runtimeInfo.memoryUsage"),name:"runtimeInfo.memoryUsage",options:{customBodyRenderLite(t){const{runtimeInfo:r}=g[t];return M(r?.memoryUsage||0)},sortDirection:"asc"}},{label:s("blocklet.runtimeInfo.cpuUsage"),name:"runtimeInfo.cpuUsage",options:{customBodyRenderLite(t){const{runtimeInfo:r}=g[t];return`${(r.cpuUsage||0).toFixed(1)}%`}}},{label:s("analytics.runtime"),name:"runtimeInfo.runtime",options:{customBodyRenderLite(t){const{runtimeInfo:r}=g[t];return r?.uptime?e.jsxs(i,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(le,{icon:r?.runningDocker?"catppuccin:docker-ignore":"logos:nodejs-icon"}),e.jsx(i,{sx:{ml:1},children:r?.runningDocker?"Docker":"Nodejs"})]}):null}}},{label:s("blocklet.runtimeInfo.processId"),name:"runtimeInfo.pid"},{label:s("blocklet.runtimeInfo.port"),name:"runtimeInfo.port"}];return e.jsxs("div",{children:[e.jsxs(i,{sx:{display:"flex",justifyContent:"space-between",flexDirection:"row",mb:2},children:[e.jsx(k,{component:"h3",variant:"h5",color:"textPrimary",style:{fontSize:18,fontWeight:"bold"},children:s("analytics.trend")}),e.jsx(je,{size:"small",exclusive:!0,value:f,onChange:(t,r)=>{me(r)&&E(r)},children:[1,3,6,12,24].map(t=>e.jsxs(Ie,{value:t,children:[t,"H"]},t))})]}),e.jsxs(C,{container:!0,spacing:4,sx:{mb:4},children:[e.jsx(C,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(ye,{...y.cpu,history:N.cpu,onHover:H,hoverIndex:x})},"cpu"),e.jsx(C,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(L,{...y.mem,history:N.mem,onHover:H,hoverIndex:x})},"memory"),e.jsx(C,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(L,{title:`Daemon ${s("common.memory")}`,total:V.parseSize(`${p.runtimeConfig.daemonMaxMemoryLimit}MiB`),used:y.daemon.memoryUsage||0,history:N.daemonMem,onHover:H,hoverIndex:x})},"memory-daemon"),e.jsx(C,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(L,{title:`Service ${s("common.memory")}`,total:V.parseSize(`${p.runtimeConfig.blockletMaxMemoryLimit}MiB`),instanceCount:y.service.instanceCount||0,used:y.service.memoryUsage||0,history:N.serviceMem,onHover:H,hoverIndex:x})},"memory-service"),y.disks.map(t=>e.jsx(C,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(Z,{disk:t})},t.device||"disk"))]}),e.jsx(he,{className:"runtime-insight-list",title:s("analytics.detail"),locale:m,data:g,columns:q,options:{download:!1,filter:!1,print:!1,pagination:!1,rowsPerPage:100}})]})}_.propTypes={initialBlocklets:l.array.isRequired};function He(){const{data:o,externalData:s,initialized:m}=te();if(!m)return e.jsx(re,{relative:"parent",children:e.jsx(ne,{})});const c=[...o,...s];return e.jsx(_,{initialBlocklets:c})}function it(){const o=de(),{t:s}=a.useContext(P),{tab:m="traffic"}=pe(),c=j=>{o(`/analytics/${j}`)},p=[{label:s("common.traffic"),value:"traffic"},{label:s("common.runtime"),value:"runtime"}],f=fe(p.find(j=>j.value===m),s("common.analytics")),E={traffic:Me,runtime:He},x=E[m]||E.traffic;return e.jsxs(Ne,{children:[f,e.jsx(k,{component:"h2",variant:"h4",className:"page-header",color:"textPrimary",children:s("common.analytics")}),e.jsx(xe,{tabs:p,current:m,onChange:c}),e.jsx("div",{className:"page-content",children:a.isValidElement(x)?x:e.jsx(x,{})})]})}const Ne=U.main`
  .page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .page-content {
    margin-top: 16px;
  }
`;export{it as default};
