commit
8c4d463f1e
96 files changed
+3319
No files matched your search
@@ -0,0 +1,55 @@
|
||||
/* Small, dependency-free canvas telemetry renderer.
|
||||
* Draws only measured, non-synthetic EasyDNS API sample history.
|
||||
* A 15-second backend poll stores samples in process memory. */
|
||||
(() => {
|
||||
'use strict';
|
||||
const COLORS={cyan:'#72cfe1',amber:'#f1b42b',red:'#ec8588',grid:'#303a34',muted:'#8d9d91',text:'#dce6df'};
|
||||
const chartTypes={
|
||||
queries:{series:[['queryRate','Queries / s','cyan']],unit:'/s'},
|
||||
cache:{series:[['cacheHitRate','Cache hit %','cyan']],unit:'%',range:[0,100]},
|
||||
latency:{series:[['p50ms','p50','cyan'],['p95ms','p95','amber'],['p99ms','p99','red']],unit:'ms'},
|
||||
blocked:{series:[['blocked','Blocked / s','amber']],unit:'/s'},
|
||||
responses:{series:[['noerror','NOERROR','cyan'],['nxdomain','NXDOMAIN','amber'],['servfail','SERVFAIL','red']],unit:'/s'}
|
||||
};
|
||||
let samples=[];let lastPoll='';
|
||||
function render(c){
|
||||
const type=chartTypes[c.dataset.dnsChart];if(!type)return;
|
||||
const dpr=Math.min(2,window.devicePixelRatio||1);
|
||||
const box=c.getBoundingClientRect();if(box.width<30)return;
|
||||
const width=box.width,height=box.height;
|
||||
c.width=Math.round(width*dpr);c.height=Math.round(height*dpr);
|
||||
const ctx=c.getContext('2d');if(!ctx)return;ctx.setTransform(dpr,0,0,dpr,0,0);ctx.clearRect(0,0,width,height);
|
||||
const pad={left:49,right:12,top:10,bottom:25};const pw=Math.max(5,width-pad.left-pad.right),ph=Math.max(5,height-pad.top-pad.bottom);
|
||||
const series=type.series.map(([key,label,color])=>({key,label,color:COLORS[color],vals:samples.map(s=>typeof s[key]==='number'&&Number.isFinite(s[key])?s[key]:null)}));
|
||||
const observed=series.flatMap(x=>x.vals.filter(v=>v!==null));
|
||||
ctx.font='10px ui-monospace,Consolas,monospace';ctx.textBaseline='middle';
|
||||
if(samples.length<2||observed.length<2){ctx.fillStyle=COLORS.muted;ctx.textAlign='center';ctx.fillText('Collecting live samples…',width/2,height/2-2);ctx.fillText('First rate after 2 successful polls',width/2,height/2+15);return;}
|
||||
let min=type.range?type.range[0]:0,max=type.range?type.range[1]:Math.max(...observed,0.001)*1.16;
|
||||
if(!Number.isFinite(max)||max===min)max=min+1;
|
||||
const x=i=>pad.left+pw*(i/Math.max(1,samples.length-1));
|
||||
const y=v=>pad.top+ph*(1-(v-min)/(max-min));
|
||||
ctx.textAlign='right';ctx.lineWidth=1;for(let tick=0;tick<=4;tick++){
|
||||
const value=min+(max-min)*tick/4,py=y(value);
|
||||
ctx.strokeStyle=COLORS.grid;ctx.setLineDash([2,4]);ctx.beginPath();ctx.moveTo(pad.left,py);ctx.lineTo(width-pad.right,py);ctx.stroke();
|
||||
ctx.fillStyle=COLORS.muted;const label=max<=10?value.toFixed(1):Math.round(value).toString();ctx.fillText(label+type.unit,pad.left-8,py);
|
||||
}
|
||||
ctx.setLineDash([]);ctx.textAlign='center';ctx.fillStyle=COLORS.muted;
|
||||
[0,.25,.5,.75,1].forEach(p=>{const idx=Math.min(samples.length-1,Math.round(p*(samples.length-1)));const t=new Date(samples[idx].time);if(!Number.isNaN(t.getTime()))ctx.fillText(t.toLocaleTimeString(undefined,{hour:'2-digit',minute:'2-digit'}),x(idx),height-9);});
|
||||
series.forEach(s=>{ctx.beginPath();ctx.strokeStyle=s.color;ctx.lineWidth=1.65;ctx.lineJoin='round';let connected=false;
|
||||
s.vals.forEach((v,i)=>{if(v===null){connected=false;return;}const px=x(i),py=y(v);if(!connected){ctx.moveTo(px,py);connected=true;}else{ctx.lineTo(px,py);}});ctx.stroke();
|
||||
});
|
||||
}
|
||||
async function poll(){
|
||||
try{
|
||||
const r=await fetch('/ui/telemetry',{credentials:'same-origin',cache:'no-store',headers:{Accept:'application/json'}});
|
||||
if(!r.ok||!(r.headers.get('content-type')||'').includes('json'))return;
|
||||
const data=await r.json();samples=Array.isArray(data.samples)?data.samples:[];lastPoll=data.lastPoll;
|
||||
document.querySelectorAll('canvas[data-dns-chart]').forEach(render);
|
||||
}catch(_){/* Missing data stays empty; never fabricate data. */}
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded',()=>{
|
||||
const canvases=document.querySelectorAll('canvas[data-dns-chart]');if(!canvases.length)return;
|
||||
const observer=new ResizeObserver(()=>canvases.forEach(render));canvases.forEach(c=>observer.observe(c));
|
||||
poll();setInterval(poll,15000);
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user