import{p as r,c as Et,s as Tt,e as d,z as t,j as R,f as s,g as c,F as J,h as g,k as It,w as At,A as ht,o as u,n as V,N as Bt}from"./vue-CSzJdJby.js";import{U as Nt}from"./index-ncPPdFzC.js";import{u as Rt}from"./index-C25aB_MX.js";import{P as Lt}from"./bootstrap.esm-BOBBXxos.js";import{$ as Z}from"./jquery-BALIvAru.js";import"./highlight.js-CWp04Ajj.js";/**
 * filesize
 *
 * @copyright 2024 Jason Mulligan <jason.mulligan@avoidwork.com>
 * @license BSD-3-Clause
 * @version 10.1.2
 */const Mt="array",St="bit",_t="bits",Dt="byte",pt="bytes",P="",Pt="exponent",jt="function",mt="iec",Ht="Invalid number",Ut="Invalid rounding method",X="jedec",zt="object",vt=".",Ft="round",Ot="s",Gt="si",Yt="kbit",Kt="kB",Vt=" ",Zt="string",$t="0",tt={symbol:{iec:{bits:["bit","Kibit","Mibit","Gibit","Tibit","Pibit","Eibit","Zibit","Yibit"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["bit","Kbit","Mbit","Gbit","Tbit","Pbit","Ebit","Zbit","Ybit"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},fullform:{iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]}};function Wt(j,{bits:l=!1,pad:m=!1,base:v=-1,round:x=2,locale:E=P,localeOptions:H={},separator:L=P,spacer:T=Vt,symbols:$={},standard:_=P,output:M=Zt,fullform:W=!1,fullforms:U=[],exponent:z=-1,roundingMethod:S=Ft,precision:I=0}={}){let n=z,f=Number(j),i=[],b=0,D=P;_===Gt?(v=10,_=X):_===mt||_===X?v=2:v===2?_=mt:(v=10,_=X);const A=v===10?1e3:1024,q=W===!0,F=f<0,O=Math[S];if(typeof j!="bigint"&&isNaN(j))throw new TypeError(Ht);if(typeof O!==jt)throw new TypeError(Ut);if(F&&(f=-f),(n===-1||isNaN(n))&&(n=Math.floor(Math.log(f)/Math.log(A)),n<0&&(n=0)),n>8&&(I>0&&(I+=8-n),n=8),M===Pt)return n;if(f===0)i[0]=0,D=i[1]=tt.symbol[_][l?_t:pt][n];else{b=f/(v===2?Math.pow(2,n*10):Math.pow(1e3,n)),l&&(b=b*8,b>=A&&n<8&&(b=b/A,n++));const w=Math.pow(10,n>0?x:0);i[0]=O(b*w)/w,i[0]===A&&n<8&&z===-1&&(i[0]=1,n++),D=i[1]=v===10&&n===1?l?Yt:Kt:tt.symbol[_][l?_t:pt][n]}if(F&&(i[0]=-i[0]),I>0&&(i[0]=i[0].toPrecision(I)),i[1]=$[i[1]]||i[1],E===!0?i[0]=i[0].toLocaleString():E.length>0?i[0]=i[0].toLocaleString(E,H):L.length>0&&(i[0]=i[0].toString().replace(vt,L)),m&&Number.isInteger(i[0])===!1&&x>0){const w=L||vt,y=i[0].toString().split(w),p=y[1]||P,C=p.length,B=x-C;i[0]=`${y[0]}${w}${p.padEnd(C+B,$t)}`}return q&&(i[1]=U[n]?U[n]:tt.fullform[_][n]+(l?St:Dt)+(i[0]===1?P:Ot)),M===Mt?i:M===zt?{value:i[0],symbol:i[1],exponent:n,unit:D}:i.join(T)}const qt={class:"position-absolute",style:{"z-index":"2"}},Jt=t("i",{class:"fa fa-expand"},null,-1),Qt=[Jt],Xt={class:"row d-fullscreen"},te={class:"col d-flex justify-content-center"},ee={class:"bg-secondary p-2 border-radius-2 rounded text-white"},se={key:0,class:"row mb-3"},oe={class:"col-xl-4 col-12 mb-3 mb-xl-0"},ae={class:"row"},ne={class:"col-xl-12 col mb-xl-2"},ie=t("div",{class:"small text-body-secondary text-center"},"System",-1),le={class:"small text-center"},ce={id:"os_version"},re={class:"row mt-2"},de={class:"col-6 small text-center"},ue={class:"chart-title"},he=["title"],_e=["innerHTML"],pe={class:"card-body p-2 chart-small"},me={class:"col-6 small text-center"},ve=t("div",{class:"chart-title"},"Memory",-1),be=["innerHTML"],ge={id:"memory",class:"fw-bold"},fe={class:"card-body p-2 chart-small"},ye={class:"row"},xe={class:"col-xl-12 col mb-xl-2"},we={class:"small text-body-secondary text-center"},Ce=["title"],ke={key:1,class:"badge badge-primary"},Ee={class:"small text-center"},Te={key:0,id:"nb_db"},Ie={key:0,id:"size"},Ae=t("br",null,null,-1),Be=["title"],Ne={id:"pg_start_time"},Re={class:"row mt-2 position-relative"},Le={class:"col-6 small text-center"},Me=t("div",{class:"chart-title"},"Cache Hit Ratio",-1),Se={id:"total-hit",class:"fw-bold"},De={class:"card-body p-2 chart-small"},Pe={class:"col-6 small text-center"},je=t("div",{class:"chart-title"},"Sessions",-1),He={id:"total-sessions",class:"fw-bold"},Ue={class:"card-body p-2 chart-small"},ze=t("div",{id:"postgres-stopped-msg",style:{position:"absolute",width:"100%",height:"100%",top:"0",display:"flex","align-items":"center","justify-content":"center",opacity:"0.9"},class:"alert alert-warning border border-warning d-none"},[t("div",{class:"text-center"},[t("i",{class:"fa fa-exclamation-triangle fa-2x"}),s(),t("br"),s(`
                  PostgreSQL instance
                  `),t("br"),s(`
                  is unreachable
                `)])],-1),Fe={class:"col-xl-8 col-12"},Oe={class:"h-50 pb-3"},Ge={class:"card h-100"},Ye={class:"text-center small p-0"},Ke=t("span",{class:"chart-title"}," Loadaverage ",-1),Ve={class:"position-absolute top-0 right-0 pe-1"},Ze={id:"loadaverage",class:"badge text-bg-primary"},$e={class:"card-body p-2"},We={id:"canvas-loadaverage-holder",class:"canvas-wrapper chart-h-min chart-h-min-xl-0"},qe={class:"h-50"},Je={class:"card h-100"},Qe={class:"text-center small p-0"},Xe=t("span",{class:"chart-title"}," TPS ",-1),ts={class:"position-absolute top-0 right-0 pe-1"},es={id:"tps_commit",class:"badge text-bg-success"},ss={id:"tps_rollback",class:"badge text-bg-danger"},os={class:"card-body p-2"},as={id:"canvas-tps-holder",class:"canvas-wrapper chart-h-min chart-h-min-xl-0"},ns={key:1,class:"row"},is={class:"col-8 position-relative"},ls=t("div",{class:"text-center small"},[s(`
          Current status
          `),t("div",{class:"position-absolute top-0 right-0 pe-2"},[t("a",{href:"alerting",class:"small text-body-secondary"},"More…")])],-1),cs={class:"row small mb-2"},rs={key:0,class:"col-3 col-xxl-2 p-1 text-center"},ds=["href"],us=["title"],hs={class:"text-center"},_s={class:"col-4"},ps=t("div",{class:"text-center small"},"Last alerts",-1),ms={class:"small",style:{"max-height":"300px","overflow-y":"auto"}},vs={key:0,class:"text-center"},bs=t("div",{class:"progress"},[t("div",{class:"progress-bar progress-bar-striped",style:{width:"100%"}},"Please wait ...")],-1),gs=[bs],fs={key:1,class:"text-body-secondary text-center"},ys=["data-bs-toggle-popover"],xs={class:"p-1"},ws={class:"float-end text-body-secondary text-end"},Cs=t("br",null,null,-1),ks=["href"],Es=t("i",{class:"fa fa-square"},null,-1),Ts=[Es],Is={key:0},As={key:0,class:"popover-content text-body-secondary d-none"},Bs=t("br",null,null,-1),Ns=t("br",null,null,-1),Rs={class:"fw-bold"},Ls=t("br",null,null,-1),Ms={__name:"Dashboard",props:["config","instance","discover","jdataHistory","initialData"],setup(j){const l=j;r(l.initialData);const m=r(l.discover),v=r(l.initialData.memory.total),x=l.initialData.databases,E=r(x?x.total_size:null),H=r(x?x.databases:null),L=r(l.initialData.loadaverage),T=r(null),$=r(0),_=r(" "),M=r(" "),W=r(0),U=r(0),z=r(0),S=r([]),I=r([]),n=window.moment,f=r(null),i=r(null),b=r(null),D=r(null),A=r(null),q=r(null),F=r(null),O=r(null);r(null);const{toggle:w}=Rt(O);let y,p,C,B,et,st,Q,ot=[];const bt=Et(()=>{const e=m.value.system.cpu_count,a=m.value.system.cpu_model;return`${e} × ${a}`});function at(){window.clearError(),Z.ajax({url:"/proxy/"+l.instance.agentAddress+"/"+l.instance.agentPort+"/dashboard",type:"GET",async:!0,contentType:"application/json",success:function(e){T.value=e.status,gt(e),rt([e]),lt([e])},error:function(e){(e.status==401||e.status==302)&&(location.href=location.href),window.showError(chr)}})}function gt(e){v.value=Wt(e.memory.total*1e3);const a=e.databases;E.value=a?a.total_size:null,H.value=a?a.databases:null,y.data.datasets[0].data[0]=e.memory.active,y.data.datasets[0].data[1]=e.memory.cached,y.data.datasets[0].data[2]=e.memory.free,y.update(),yt(),p.data.datasets[0].data[0]=e.cpu.iowait,p.data.datasets[0].data[1]=e.cpu.steal,p.data.datasets[0].data[2]=e.cpu.user,p.data.datasets[0].data[3]=e.cpu.system,p.data.datasets[0].data[4]=e.cpu.idle,p.update(),ft(),C.data.datasets[0].data[0]=e.hitratio,C.data.datasets[0].data[1]=100-e.hitratio,C.update(),xt();const o=e.active_backends,h=o?o.nb:null;B.data.datasets[0].data[0]=h,B.data.datasets[0].data[1]=m.value.postgres.max_connections-h,B.update(),nt()}function ft(){const e=p.data.datasets[0].data.slice(0);e.pop(),M.value=parseInt(e.reduce(function(a,o){return a+o},0))+" %"}function yt(){const e=y.data.datasets[0].data.slice(0);e.pop(),$.value=parseInt(e.reduce(function(a,o){return a+o},0))+" %"}function xt(){const e=C.data.datasets[0].data[0];_.value=e?e+" %":"N/A"}function nt(){const e=B.data.datasets[0].data;let a=e[0];e[1]&&(a+=" / "+(e[0]+e[1])),W.value=a}function it(e){const a=e.options.scales.xAxes[0].time,o=n();a.min=o.clone().subtract(Q,"s"),a.max=o;const h=e.data.datasets;for(let k=0;k<h.length;k++){const N=h[k];N.data=N.data.filter(function(Y){return Y.x>n(e.options.scales.xAxes[0].time.min).unix()*1e3})}e.update()}function lt(e){const a=st;it(a);for(let o=0;o<e.length;o++)a.data.datasets[0].data.push({x:e[o].timestamp*1e3,y:e[o].loadaverage});L.value=e[e.length-1].loadaverage,a.update()}function ct(e,a,o){return Math.ceil((e-a)/o)}let G={};function rt(e){const a=et;it(a);const o=a.data.datasets,h=o[0].data,k=o[1].data;e.length>1&&(G=e[0],e.shift());let N;for(let Y=0;Y<e.length;Y++){const K=e[Y],ut=K.databases;if(N=K.timestamp-G.timestamp,N===0)continue;const Ct=ct(ut.total_commit,G.databases.total_commit,N),kt=ct(ut.total_rollback,G.databases.total_rollback,N);h.push({x:K.timestamp*1e3,y:Ct}),k.push({x:K.timestamp*1e3,y:kt}),G=K}U.value=h[h.length-1].y,z.value=k[k.length-1].y,a.update(),Z("#postgres-stopped-msg").toggleClass("d-none",!!e[e.length-1].databases)}function wt(e){return e!="OK"&&e!="UNDEF"?"border border-2 border-"+e.toLowerCase():"border border-light"}function dt(){window.clearError(),Z.ajax({url:"/server/"+l.instance.agentAddress+"/"+l.instance.agentPort+"/alerting/alerts.json",success:function(e){ot.forEach(a=>a.dispose()),S.value=e,window.setTimeout(function(){ot=[...F.value.querySelectorAll("[data-bs-toggle-popover]")].map(o=>new Lt(o,{placement:"top",container:"body",boundary:"window",content:function(h){return Z(h).find(".popover-content")[0].outerHTML.replace("d-none","")},html:!0}))},1)},error:function(e){window.showError(e)}}),window.clearError(),Z.ajax({url:"/server/"+l.instance.agentAddress+"/"+l.instance.agentPort+"/alerting/checks.json",success:function(e){I.value=e},error:function(e){window.showError(e)}})}return Tt(()=>{if(m.value===null){window.showError("UI does not know this agent. Retry in 1 minute or check the logs.");return}const e={responsive:!0,maintainAspectRatio:!1,legend:!1,rotation:Math.PI,circumference:Math.PI};y=new Chart(f.value.getContext("2d"),{type:"doughnut",data:{labels:["Active","Cached","Free"],datasets:[{backgroundColor:["#cc2936","#29cc36","#eeeeee"]}]},options:e}),p=new Chart(i.value.getContext("2d"),{type:"doughnut",data:{labels:["IO Wait","Steal","User","System","IDLE"],datasets:[{backgroundColor:["#cc2936","#cbff00","#29cc36","#cbff00","#eeeeee"]}]},options:e}),C=new Chart(b.value.getContext("2d"),{type:"doughnut",data:{labels:["Hit","Read"],datasets:[{backgroundColor:["#29cc36","#cc2936"]}]},options:e}),B=new Chart(D.value.getContext("2d"),{type:"doughnut",data:{labels:["Active backends","Free"],datasets:[{backgroundColor:["#29cc36","#eeeeee"]}]},options:e}),nt();const a=n();Q=l.config.history_length*l.config.scheduler_interval;const o={responsive:!0,maintainAspectRatio:!1,animation:!1,legend:{display:!1},scales:{yAxes:[{ticks:{beginAtZero:!0}}],xAxes:[{type:"time",time:{min:a.clone().subtract(Q,"s"),max:a,displayFormats:{second:"h:mm a",minute:"h:mm a"}}}]},elements:{point:{radius:0,hoverRadius:0},line:{borderWidth:1}},tooltips:{enabled:!1}};et=new Chart(A.value.getContext("2d"),{type:"line",data:{datasets:[{label:"Commit",backgroundColor:"rgba(0,188,18,0.2)",borderColor:"rgba(0,188,18,1)"},{label:"Rollback",backgroundColor:"rgba(188,0,0,0.2)",borderColor:"rgba(188,0,0,1)"}]},options:o}),rt(l.jdataHistory),st=new Chart(q.value.getContext("2d"),{type:"line",data:{datasets:[{label:"Loadaverage",backgroundColor:"rgba(250, 164, 58, 0.2)",borderColor:"rgba(250, 164, 58, 1)"}]},options:o}),lt(l.jdataHistory);const h=l.config.scheduler_interval*1e3;window.setInterval(at,h),at(),l.instance.plugins.includes("monitoring")&&(window.setInterval(dt,6e4),dt())}),(e,a)=>(u(),d("div",{ref_key:"rootEl",ref:O},[t("div",qt,[t("button",{id:"fullscreen",class:"btn btn-link",onClick:a[0]||(a[0]=(...o)=>R(w)&&R(w)(...o))},Qt)]),s(),t("div",Xt,[t("div",te,[t("strong",ee,c(l.instance.hostname)+":"+c(l.instance.pgPort),1)])]),s(),l.discover?(u(),d("div",se,[t("div",oe,[t("div",ae,[t("div",ne,[ie,s(),t("div",le,[s(c(l.discover.system.distribution)+` /
              `,1),t("span",ce,c(l.discover.system.os_version),1)]),s(),t("div",re,[t("div",de,[t("div",ue,[s(`
                  CPU × `+c(m.value.system.cpu_count)+" ",1),t("i",{id:"cpu-info",class:"fa fa-info-circle text-body-secondary","data-bs-toggle":"tooltip",title:bt.value},null,8,he)]),s(),t("div",{id:"total-cpu",class:"fw-bold",innerHTML:M.value},null,8,_e),s(),t("div",pe,[t("canvas",{ref_key:"cpuChartEl",ref:i},null,512)])]),s(),t("div",me,[ve,s(),t("div",null,[t("span",{id:"total-memory",class:"fw-bold",innerHTML:$.value},null,8,be),s(`
                  of
                  `),t("span",ge,c(v.value),1)]),s(),t("div",fe,[t("canvas",{ref_key:"memoryChartEl",ref:f},null,512)])])])])]),s(),t("div",ye,[t("div",xe,[t("div",we,[s(c(m.value.postgres.version_summary)+" ",1),T.value?(u(),d(J,{key:0},[T.value.postgres.primary&&T.value.postgres.is_standby?(u(),d("span",{key:0,class:"badge badge-secondary",title:T.value.postgres.primary_conninfo},"secondary",8,Ce)):(u(),d("span",ke,"primary"))],64)):g("",!0)]),s(),t("div",Ee,[t("b",null,[H.value?(u(),d("span",Te,c(H.value),1)):g("",!0)]),s(`
              Databases -
              `),E.value?(u(),d("b",Ie,c(E.value),1)):g("",!0),s(),Ae,s(),t("span",{title:R(n)(m.value.postgres.start_time).format("LLLL")},[s(`
                Start Time:
                `),t("strong",Ne,[It(R(Nt),{time:R(n)(m.value.postgres.start_time)},{default:At(({timeAgo:o})=>[s(c(o),1)]),_:1},8,["time"])])],8,Be)]),s(),t("div",Re,[t("div",Le,[Me,s(),t("div",Se,c(_.value),1),s(),t("div",De,[t("canvas",{ref_key:"hitRatioChartEl",ref:b},null,512)])]),s(),t("div",Pe,[je,s(),t("div",He,c(W.value),1),s(),t("div",Ue,[t("canvas",{ref_key:"sessionsChartEl",ref:D},null,512)])]),s(),ze])])])]),s(),t("div",Fe,[t("div",Oe,[t("div",Ge,[t("div",Ye,[Ke,s(),t("div",Ve,[t("span",Ze,c(L.value),1)])]),s(),t("div",$e,[t("div",We,[t("canvas",{id:"chart-loadaverage",ref_key:"loadAverageChartEl",ref:q},null,512)])])])]),s(),t("div",qe,[t("div",Je,[t("div",Qe,[Xe,s(),t("div",ts,[s(`
                Commit: `),t("span",es,c(U.value),1),s(` Rollback:
                `),t("span",ss,c(z.value),1)])]),s(),t("div",os,[t("div",as,[t("canvas",{id:"chart-tps",ref_key:"tpsChartEl",ref:A},null,512)])])])])])])):g("",!0),s(),l.discover&&l.instance.plugins.includes("monitoring")?(u(),d("div",ns,[t("div",is,[ls,s(),t("div",cs,[(u(!0),d(J,null,ht(I.value,o=>(u(),d(J,null,[o.state!="UNDEF"?(u(),d("div",rs,[t("div",{class:V(["p-1 rounded",[wt(o.state),{"striped bg-light":!o.enabled}]])},[t("a",{href:"alerting/"+o.name,class:V({"text-body-secondary":!o.enabled})},[t("div",{class:"text-nowrap fw-bold",style:{overflow:"hidden","text-overflow":"ellipsis"},title:o.description},c(o.description),9,us),s(),t("div",hs,[t("span",{class:V(["badge","text-bg-"+o.state.toLowerCase()])},c(o.state),3)])],10,ds)],2)])):g("",!0)],64))),256))])]),s(),t("div",_s,[ps,s(),t("div",ms,[S.value?g("",!0):(u(),d("div",vs,gs)),s(),S.value.length==0?(u(),d("div",fs,"No alerts")):g("",!0),s(),t("div",{class:"mb-0",ref_key:"divAlertsEl",ref:F},[(u(!0),d(J,null,ht(S.value,o=>(u(),d("div",{class:"bg-light mb-1","data-bs-toggle-popover":o.state=="WARNING"||o.state=="CRITICAL","data-bs-trigger":"hover"},[t("div",xs,[t("div",ws,[s(c(R(n)(o.datetime).fromNow()),1),Cs]),s(),t("div",null,[t("a",{href:"alerting/"+o.name},[t("span",{class:V(["small text","text-"+o.state.toLowerCase()])},Ts,2),s(),t("span",null,c(o.description),1),s(),o.key?(u(),d("span",Is,`
                        -
                        `+c(o.key),1)):g("",!0)],8,ks)]),s(),o.state=="WARNING"||o.state=="CRITICAL"?(u(),d("div",As,[s(c(R(n)(o.datetime).format()),1),Bs,s(),t("span",{class:V("badge text-bg-"+o.state.toLowerCase())},c(o.state),3),s(),Ns,s(),t("span",Rs,c(o.value),1),s(),Ls,s(`
                    Thresholds: warning `+c(o.warning)+" / critical "+c(o.critical),1)])):g("",!0)])],8,ys))),256))],512)])])])):g("",!0)],512))}};Bt({components:{dashboard:Ms}}).mount("#app");
