import{r as a,b as D,j as e,J as C,U as Q,B as i,q as P,R as Y,o as m,p as $,bs as M,c_ as Z,ac as ee,bE as te,b3 as re,C as ne,V as se,aU as v,c6 as g,c$ as R,am as k,d0 as oe,bM as ie,aV as ae,X as me,bv as le,bu as j,H as T,bw as ce,bx as ue,u as de,a as pe}from"./index-DR3HTfO6.js";import{u as fe,T as he}from"./html-title-CwN7G8hd.js";import{T as xe}from"./traffic-CR6qa0E0.js";import{H as ge}from"./index-DX1Rg408.js";import{x as w}from"./index-D29L5UKE.js";import{C as ye,M as L}from"./memory-Dhi3FllC.js";import{C as ve}from"./CardContent-DogoRcwj.js";import{u as je}from"./useLocalStorage-BUDMB9ci.js";import{T as Ie,a as be}from"./ToggleButtonGroup-BoFHMmWO.js";import"./iframe-BiyRZfrc.js";import"./ChevronLeft-CT2ZnLgQ.js";import"./ChevronRight-CY1_GtAD.js";import"./index-CVhk080O.js";import"./typeof-QjJsDpFa.js";import"./base-chart-BH9wHgTE.js";import"./index-D5lfhyUN.js";import"./AdapterDayjs-D2AGsg5m.js";import"./useThemeProps-DDoTrY7o.js";import"./visuallyHidden-Dan1xhjv.js";import"./CSSTransition--PBqXHt0.js";import"./FilterList-BduCnH7c.js";import"./emotion-cache.browser.esm-DHWVBIJA.js";import"./index-n5-asI58.js";import"./redux-Ab4buSXY.js";import"./depsEqual-CJ8pX2dq.js";import"./index-BlSr9ZCo.js";import"./TableSearch-BCTie1Ve.js";import"./Search-DY52i3Q9.js";import"./Clear-DKF2FhrE.js";import"./MoreVert-B7vfcAq6.js";import"./getValidReactChildren-DB5-GZmu.js";const ke=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.083 3.2c0-.619.501-1.12 1.12-1.12h25.6c.619 0 1.12.501 1.12 1.12v10.24a1.12 1.12 0 0 1-1.12 1.12h-25.6a1.12 1.12 0 0 1-1.12-1.12V3.2zm2.24 1.12v8h23.36v-8H4.323zm-2.24 14.24c0-.619.501-1.12 1.12-1.12h25.6c.619 0 1.12.501 1.12 1.12V28.8a1.12 1.12 0 0 1-1.12 1.12h-25.6a1.12 1.12 0 0 1-1.12-1.12V18.56zm2.24 1.12v8h23.36v-8H4.323z",fill:"currentColor"}),a.createElement("path",{d:"M8.963 7.04h-1.28a.64.64 0 0 0-.64.64v1.28a.64.64 0 0 0 .64.64h1.28a.64.64 0 0 0 .64-.64V7.68a.64.64 0 0 0-.64-.64zm0 15.36h-1.28a.64.64 0 0 0-.64.64v1.28a.64.64 0 0 0 .64.64h1.28a.64.64 0 0 0 .64-.64v-1.28a.64.64 0 0 0-.64-.64zm5.12-15.36h-1.28a.64.64 0 0 0-.64.64v1.28a.64.64 0 0 0 .64.64h1.28a.64.64 0 0 0 .64-.64V7.68a.64.64 0 0 0-.64-.64zm0 15.36h-1.28a.64.64 0 0 0-.64.64v1.28a.64.64 0 0 0 .64.64h1.28a.64.64 0 0 0 .64-.64v-1.28a.64.64 0 0 0-.64-.64z",fill:"currentColor"}));function Me(){const{api:o,info:s}=D();return e.jsx(xe,{client:o,did:s.did})}function V({style:o={},title:s=null,value:l=null,graph:c=null,description:p=null,empty:f=null}){return e.jsx(Ce,{children:e.jsxs(ve,{style:{...o},children:[e.jsx(C,{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(C,{variant:"h5",component:"div",sx:{mt:1},children:l}),c,!!p&&e.jsx(i,{sx:{display:"flex",color:"text.secondary",fontSize:12,marginTop:3},children:p})]})]})})}V.propTypes={style:m.object,title:m.node,value:m.node,graph:m.node,description:m.any,empty:m.node};const Ce=P(Y)`
  .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(Z,{...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 _(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(C,{variant:"body2",color:"textSecondary",children:`${Math.round(s)}%`})})]})}_.propTypes={value:m.number.isRequired};function A({disk:o={used:0,free:0,total:1,device:""}}){const{t:s}=a.useContext($),l=[{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(V,{title:`${s("common.disk")} (${o.device})`,value:M(o.used),graph:e.jsx(i,{sx:{mt:3},children:e.jsx(_,{value:o.used/o.total*100})}),description:l.map((c,p)=>e.jsxs(i,{sx:{marginLeft:p===0?0:2},children:[c.title,": ",c.metric]},c.title))})}A.propTypes={disk:m.shape({used:m.number,free:m.number,total:m.number,device:m.string})};const H={uptime:0,pid:-1,cpuUsage:0,memoryUsage:0},U="Blocklet Server";function F({initialBlocklets:o}){const{t:s,locale:l}=se(),{api:c,info:p}=D(),[f,E]=je("runtime-view-interval",6),[h,I]=a.useState(null),[x,b]=a.useState([]),N=a.useCallback(t=>{I(t)},[]);a.useEffect(()=>{const t=[];t.push({type:"server",groupId:"server",groupName:U,id:"server:daemon",name:"Server (Daemon)",runtimeInfo:H}),t.push({type:"server",groupId:"server",groupName:U,id:"server:service",name:"Server (Service)",runtimeInfo:H}),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})})}),b(t)},[!!o?.[0]?.appRuntimeInfo]);const[y,O]=a.useState({os:{platform:""},mem:{used:0,free:0,total:1},cpu:{cpus:[],currentLoad:1},disks:[],daemon:{},service:{}}),[B,G]=a.useState({cpu:[],mem:[],daemonMem:[],serviceMem:[]});g(R.NODE_RUNTIME_INFO,t=>{t.mem.total=t.mem.total||0,t.mem.used=t.mem.total-(t.mem.available||0),O(t),b(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))}),g(R.BLOCKLETS_RUNTIME_INFO,t=>{if(!t||!t.length){console.error("incorrect blocklets runtime info format",t);return}b(r=>r.map(n=>{const u=t.find(d=>d.componentId===n.id);return u?{...n,runtimeInfo:{...n.runtimeInfo,...u.runtimeInfo}}:n}))});const S=t=>{b(r=>r.filter(n=>n.groupId!==t.meta.did))},z=async t=>{try{const{blocklet:r}=await c.getBlocklet({input:{did:t.meta.did,attachRuntimeInfo:!0}});r.status!=="running"&&S(r),b(n=>{const u=n.filter(d=>d.groupId!==r.meta.did);return v.forEachBlockletSync(r,(d,{id:K,ancestors:X})=>{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:X})}),u})}catch(r){T.error(r.message)}};g(k.BlockletEvents.removed,S),g(k.BlockletEvents.startFailed,S),g(k.BlockletEvents.statusChange,t=>{if(t.status!=="running"){S(t);return}z(t)}),g(k.BlockletEvents.updated,z),g(k.BlockletEvents.started,z);const W=()=>{c.getNodeRuntimeHistory({input:{hours:f}}).then(t=>{const r=t.history||[];G({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=>{T.error(t.message)})};a.useEffect(()=>{W()},[f]);const q=t=>ce(Number(t||0),{locale:ue(l)}),J=[{label:s("common.group"),name:"groupName",options:{customBodyRenderLite(t){const{type:r,blocklet:n,groupName:u}=x[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}=x[t];return r==="server"?e.jsxs(i,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(ke,{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}=x[t];return q(r.uptime)}}},{label:s("blocklet.runtimeInfo.memoryUsage"),name:"runtimeInfo.memoryUsage",options:{customBodyRenderLite(t){const{runtimeInfo:r}=x[t];return M(r?.memoryUsage||0)},sortDirection:"asc"}},{label:s("blocklet.runtimeInfo.cpuUsage"),name:"runtimeInfo.cpuUsage",options:{customBodyRenderLite(t){const{runtimeInfo:r}=x[t];return`${(r.cpuUsage||0).toFixed(1)}%`}}},{label:s("analytics.runtime"),name:"runtimeInfo.runtime",options:{customBodyRenderLite(t){const{runtimeInfo:r}=x[t];return r?.uptime?e.jsxs(i,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(me,{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(C,{component:"h3",variant:"h5",color:"textPrimary",style:{fontSize:18,fontWeight:"bold"},children:s("analytics.trend")}),e.jsx(Ie,{size:"small",exclusive:!0,value:f,onChange:(t,r)=>{le(r)&&E(r)},children:[1,3,6,12,24].map(t=>e.jsxs(be,{value:t,children:[t,"H"]},t))})]}),e.jsxs(j,{container:!0,spacing:4,sx:{mb:4},children:[e.jsx(j,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(ye,{...y.cpu,history:B.cpu,onHover:N,hoverIndex:h})},"cpu"),e.jsx(j,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(L,{...y.mem,history:B.mem,onHover:N,hoverIndex:h})},"memory"),e.jsx(j,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(L,{title:`Daemon ${s("common.memory")}`,total:w.parseSize(`${p.runtimeConfig.daemonMaxMemoryLimit}MiB`),used:y.daemon.memoryUsage||0,history:B.daemonMem,onHover:N,hoverIndex:h})},"memory-daemon"),e.jsx(j,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(L,{title:`Service ${s("common.memory")}`,total:w.parseSize(`${p.runtimeConfig.blockletMaxMemoryLimit}MiB`),instanceCount:y.service.instanceCount||0,used:y.service.memoryUsage||0,history:B.serviceMem,onHover:N,hoverIndex:h})},"memory-service"),y.disks.map(t=>e.jsx(j,{size:{lg:3,md:6,sm:6,xs:12},children:e.jsx(A,{disk:t})},t.device||"disk"))]}),e.jsx(ge,{className:"runtime-insight-list",title:s("analytics.detail"),locale:l,data:x,columns:J,options:{download:!1,filter:!1,print:!1,pagination:!1,rowsPerPage:100}})]})}F.propTypes={initialBlocklets:m.array.isRequired};function Ne(){const{data:o,externalData:s,initialized:l}=te();if(!l)return e.jsx(re,{relative:"parent",children:e.jsx(ne,{})});const c=[...o,...s];return e.jsx(F,{initialBlocklets:c})}function it(){const o=de(),{t:s}=a.useContext($),{tab:l="traffic"}=pe(),c=I=>{o(`/analytics/${I}`)},p=[{label:s("common.traffic"),value:"traffic"},{label:s("common.runtime"),value:"runtime"}],f=fe(p.find(I=>I.value===l),s("common.analytics")),E={traffic:Me,runtime:Ne},h=E[l]||E.traffic;return e.jsxs(Be,{children:[f,e.jsx(C,{component:"h2",variant:"h4",className:"page-header",color:"textPrimary",children:s("common.analytics")}),e.jsx(he,{tabs:p,current:l,onChange:c}),e.jsx("div",{className:"page-content",children:a.isValidElement(h)?h:e.jsx(h,{})})]})}const Be=P.main`
  .page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

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