Files
OpenVPN-Monitoring-Simple/deploy/ui-dist/assets/Analytics-wS3sZsf7.js
T
ayurishchevandClaude Sonnet 5.5 b3466f9c61 History and Analytics: average speed from bytes for periods over 24 hours
The aggregate tables (stats_*) keep only bytes, and the queries returned 0 as speed, so the Speed
mode was empty for 7d and 30d. Speed is now the bucket average: bytes * 8 / 1e6 / bucket seconds;
for the current incomplete bucket the duration is min(bucket length, time since its start), at least
1 s. Series are labelled "RX Mbps (avg)" / "TX Mbps (avg)" for ranges over 24h. One test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KC7BXv32Jwj8mY5sKX8u2F
2026-10-07 14:28:02 +03:00

2 lines
7.5 KiB
JavaScript

import{r as c,a as T,u as z,o as B,b as E,c as I,d as n,e as t,t as o,f as R,g as r,w as A,v as V,h as F,F as b,i as D,j as P,k as i,n as H}from"./index-BfAhXdi6.js";import{u as X,g as G,C as W,a as q}from"./useTrafficChart-69f2EcZB.js";import{u as J}from"./useFormatters-CKGG-YVI.js";import{C as K}from"./vendor-charts-Bcjh2pZL.js";const Q={class:"kpi-grid mb-4"},Y={class:"stat-item"},Z={class:"stat-content"},$={class:"stat-item"},tt={class:"stat-content"},et={class:"stat-item"},st={class:"stat-content"},at={class:"card mb-4"},lt={class:"card-header d-flex justify-content-between align-items-center flex-wrap"},ot={class:"chart-header-controls"},nt={class:"d-flex align-items-center"},it={class:"toggle-wrapper me-2"},rt={class:"toggle-switch"},dt={class:"card-body"},ct={class:"chart-container"},ut={class:"row"},ft={class:"col-lg-7"},mt={class:"card"},vt={class:"card-body p-0"},pt={class:"table-responsive"},_t={class:"table"},ht={key:0},gt={key:1},yt={class:"user-select-all fw-bold",style:{color:"var(--text-heading)"}},xt={class:"font-monospace text-muted"},bt={class:"d-flex align-items-center"},Ct={class:"progress flex-grow-1",style:{height:"6px"}},kt={class:"ms-2 small text-muted w-25 text-end"},wt={class:"col-lg-5"},St={class:"card mb-4"},Tt={class:"card-body p-3",style:{"min-height":"120px","max-height":"200px","overflow-y":"auto"}},Rt={key:0,class:"text-muted text-center py-3 mb-0"},At={key:1,class:"text-muted text-center py-3 mb-0"},Dt={key:2,class:"list-group list-group-flush"},Nt={class:"fw-bold small"},Lt={class:"text-muted",style:{"font-size":"0.75rem"}},Ot={class:"badge status-warning text-dark"},Ut={class:"card"},Mt={class:"card-body d-flex align-items-center justify-content-around p-4",style:{"min-height":"200px"}},jt={class:"pie-container",style:{width:"140px",height:"140px",flex:"0 0 auto"}},zt={class:"ms-3 flex-grow-1"},Bt={class:"mb-3"},Et={class:"h5 mb-0",style:{color:"var(--text-heading)"}},It={class:"h5 mb-0",style:{color:"var(--text-heading)"}},Gt={__name:"Analytics",setup(Vt){const{fetchAnalytics:N,fetchCertificates:L}=P(),{formatBytes:f}=J(),{config:O}=E(),C=c(null),v=c(null);let u=null;const U=X(C,{maxPoints:96}),d=T({analytics:!0,certs:!0}),m=c("24h"),p=c(!1),a=T({concurrentUsers:"-",totalTraffic:0,expiringCerts:"-",totalReceived:0,totalSent:0,totalReceivedString:"-",totalSentString:"-"}),_=c([]),h=c([]);let k=[];const g=async()=>{d.analytics=!0;try{const l=await N(m.value);l.success&&M(l.data)}catch(l){console.error(l)}finally{d.analytics=!1}},w=async()=>{d.certs=!0;try{const e=(await L()).filter(s=>!s.is_revoked&&!s.is_expired&&s.days_remaining!=null&&s.days_remaining<=45);a.expiringCerts=e.length,h.value=e.sort((s,j)=>s.days_remaining-j.days_remaining)}catch(l){console.error(l)}finally{d.certs=!1}},M=l=>{a.concurrentUsers=l.max_concurrent_24h||0;const e=l.traffic_distribution||{rx:0,tx:0};a.totalReceived=Number(e.rx||0),a.totalSent=Number(e.tx||0),a.totalTraffic=a.totalReceived+a.totalSent,a.totalReceivedString=f(a.totalReceived),a.totalSentString=f(a.totalSent),_.value=(l.top_clients_24h||[]).map(s=>({name:s.common_name,total:Number(s.total_traffic||0),percent:a.totalTraffic>0?(Number(s.total_traffic)/a.totalTraffic*100).toFixed(1):0})),k=(l.global_history_24h||[]).map(s=>({timestamp:s.timestamp,bytes_received:s.total_rx,bytes_sent:s.total_tx,rx_rate_mbps:s.total_rx_rate,tx_rate_mbps:s.total_tx_rate})),y(),S()},y=()=>{U.render(k,{range:m.value,speedMode:p.value})},S=()=>{if(!v.value)return;u&&u.destroy();const l=v.value.getContext("2d"),e=G().isDark?"#161b22":"#ffffff";u=new K(l,{type:"doughnut",data:{labels:["Received","Sent"],datasets:[{data:[a.totalReceived,a.totalSent],backgroundColor:[W,q],borderColor:e,borderWidth:2,hoverOffset:4}]},options:{responsive:!0,maintainAspectRatio:!1,cutout:"70%",plugins:{legend:{display:!1}}}})};let x;return z(()=>{y(),S()}),B(()=>{g(),w();const l=O.value?.refresh_interval||3e4;x=setInterval(()=>{g(),w()},l)}),I(()=>{x&&clearInterval(x),u&&u.destroy()}),(l,e)=>(i(),n(b,null,[t("div",Q,[t("div",Y,[t("div",Z,[t("h3",null,o(a.concurrentUsers),1),e[2]||(e[2]=t("p",{class:"stat-label"},"Concurrent Users (Peak)",-1))])]),t("div",$,[t("div",tt,[t("h3",null,o(R(f)(a.totalTraffic)),1),e[3]||(e[3]=t("p",{class:"stat-label"},"Traffic Volume (Total)",-1))])]),t("div",et,[t("div",st,[t("h3",null,o(a.expiringCerts),1),e[4]||(e[4]=t("p",{class:"stat-label"},"Expiring Soon (In 45 Days)",-1))])])]),t("div",at,[t("div",lt,[e[8]||(e[8]=t("span",null,[t("i",{class:"fas fa-chart-area me-2"}),r("Traffic Overview")],-1)),t("div",ot,[A(t("select",{class:"form-select form-select-sm",style:{width:"auto"},"onUpdate:modelValue":e[0]||(e[0]=s=>m.value=s),onChange:g},[...e[5]||(e[5]=[t("option",{value:"24h"},"Last 24 Hours",-1),t("option",{value:"7d"},"Last 7 Days",-1),t("option",{value:"30d"},"Last 1 Month",-1)])],544),[[V,m.value]]),t("div",nt,[t("div",it,[t("label",rt,[A(t("input",{type:"checkbox",id:"vizToggle","onUpdate:modelValue":e[1]||(e[1]=s=>p.value=s),onChange:y},null,544),[[F,p.value]]),e[6]||(e[6]=t("span",{class:"toggle-slider"},null,-1))])]),e[7]||(e[7]=t("label",{class:"small fw-bold user-select-none",style:{color:"var(--text-heading)",cursor:"pointer"},for:"vizToggle"}," Speed ",-1))])])]),t("div",dt,[t("div",ct,[t("canvas",{ref_key:"mainChartRef",ref:C},null,512)])])]),t("div",ut,[t("div",ft,[t("div",mt,[e[12]||(e[12]=t("div",{class:"card-header"},[t("i",{class:"fas fa-trophy me-2"}),r("TOP-10 Active Clients ")],-1)),t("div",vt,[t("div",pt,[t("table",_t,[e[11]||(e[11]=t("thead",null,[t("tr",null,[t("th",null,"Client Name"),t("th",null,"Total Data"),t("th",null,"Activity Share")])],-1)),t("tbody",null,[d.analytics?(i(),n("tr",ht,[...e[9]||(e[9]=[t("td",{colspan:"3",class:"text-center py-4 text-muted"},"Loading...",-1)])])):_.value.length===0?(i(),n("tr",gt,[...e[10]||(e[10]=[t("td",{colspan:"3",class:"text-center py-4 text-muted"},"No data available",-1)])])):(i(!0),n(b,{key:2},D(_.value,s=>(i(),n("tr",{key:s.name},[t("td",null,[t("span",yt,o(s.name),1)]),t("td",xt,o(R(f)(s.total)),1),t("td",null,[t("div",bt,[t("div",Ct,[t("div",{class:"progress-bar",role:"progressbar",style:H({width:s.percent+"%",backgroundColor:"#EC7C31"})},null,4)]),t("span",kt,o(s.percent)+"%",1)])])]))),128))])])])])])]),t("div",wt,[t("div",St,[e[14]||(e[14]=t("div",{class:"card-header d-flex justify-content-between align-items-center"},[t("span",null,[t("i",{class:"fas fa-exclamation-circle me-2"}),r("Certificate Alerts")]),t("span",{class:"badge bg-secondary",style:{"font-size":"0.7em"}},"Next 45 Days")],-1)),t("div",Tt,[d.certs?(i(),n("p",Rt,"Checking certificates...")):h.value.length===0?(i(),n("p",At,[...e[13]||(e[13]=[t("i",{class:"fas fa-check-circle text-success me-2"},null,-1),r("All Good ",-1)])])):(i(),n("div",Dt,[(i(!0),n(b,null,D(h.value,s=>(i(),n("div",{key:s.username,class:"list-group-item px-0 py-2 d-flex justify-content-between align-items-center border-0"},[t("div",null,[t("div",Nt,o(s.username),1),t("div",Lt,"Expires: "+o(s.expiration_date),1)]),t("span",Ot,o(s.days_remaining)+" days",1)]))),128))]))])]),t("div",Ut,[e[17]||(e[17]=t("div",{class:"card-header"},[t("i",{class:"fas fa-chart-pie me-2"}),r("Traffic Distribution ")],-1)),t("div",Mt,[t("div",jt,[t("canvas",{ref_key:"pieChartRef",ref:v},null,512)]),t("div",zt,[t("div",Bt,[e[15]||(e[15]=t("div",{class:"small text-muted mb-1"},[t("span",{class:"legend-dot",style:{background:"#1652B8"}}),r("Download ")],-1)),t("div",Et,o(a.totalReceivedString),1)]),t("div",null,[e[16]||(e[16]=t("div",{class:"small text-muted mb-1"},[t("span",{class:"legend-dot",style:{background:"#EC7C31"}}),r("Upload")],-1)),t("div",It,o(a.totalSentString),1)])])])])])])],64))}};export{Gt as default};