Files
urutau/internal/server/web/errors.js
T
Lucas RayanandClaude Opus 5.5 2ebda1e4d7
Release / Plan (reuse the published image?) (push) Successful in 3s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 20s
CI / Tests (Linux, race detector) (push) Successful in 1m10s
Release / ci (push) Successful in 1m10s
Release / Build image (arm64) (push) Successful in 55s
Release / Build image (amd64) (push) Successful in 1m16s
Release / Publish tags (push) Successful in 14s
Release / Gitea release (push) Skipped
feat: 1.3.0 thirteen new pages, charts, tooltips and error analysis
New pages grouped in the rail (Monitor, Investigate, Analyze, Operate,
Reports): Services (SLO, Apdex, latency app vs proxy), Sessions (stage
funnel), Campaigns, Event search, MITRE ATT&CK matrix, Evolution,
Concentration (Pareto, Gini), Survival (Kaplan-Meier per attack
episode, recidivists), Where errors come from (application vs failed
attack vs proxy vs client), Protocols and TLS, Defense (fail2ban, SSH,
blocklist), Integrity, and a printable executive report.

Chart library (donut, radar, stacked area, bars, heatmap, gauge),
glossary with accessible "?" tooltips, self-explanatory category names
(nonexistent page 404), page loader through pages.json.

Unique visitors fixed: real browsers opening a page, one per IP per day,
deduplicated across domains, with non-human clients counted apart.
Anonymous legitimate visits on the Live page (?visits=1, no IP).
Traefik origin, service, protocol and TLS fields parsed. Paths and
Referer paths drop e-mail and token segments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:39:33 -03:00

147 lines
11 KiB
JavaScript

/* Urutau - page ERRORS ("where do the errors come from"): splits every 4xx/5xx into
frustrated attacks, proxy trouble, real application errors, bots and client mistakes.
Data: /api/v1/errors. Log data is hostile: textContent only. */
(function () {
'use strict';
var U = window.Urutau;
if (!U || !U.registerPage) return;
var el = U.el, t = U.t;
var ORDER = ['app', 'proxy', 'blocked', 'attack', 'bot', 'client_broken', 'client_auth', 'client_other'];
var COLOR = { app: '--danger', proxy: '--warn', blocked: '--info', attack: '--cat-exploit', bot: '--viz-6', client_broken: '--viz-2', client_auth: '--viz-4', client_other: '--ink-muted' };
U.registerI18n({
en: {
'hl.er.title': 'Where errors come from',
'hl.er.lead': '{n} errors; {atk} frustrated attacks, {app} real application errors',
'hl.er.lead.body': 'Of {req} requests {range}, {proxy} of the errors are proxy trouble and {bot} come from crawlers. Server error rate (application + proxy over legitimate requests, client cancellations excluded): {rate}. Data from this instance ({inst}) only.',
'hl.er.lead.empty': 'No errors recorded',
'hl.er.lead.empty.body': 'No 4xx or 5xx answers {range}, or the log has no origin fields yet.',
'hl.cls.app': 'Application', 'hl.cls.proxy': 'Proxy / network', 'hl.cls.blocked': 'Blocked by rule', 'hl.cls.attack': 'Attack',
'hl.cls.bot': 'Crawlers', 'hl.cls.client_broken': 'Broken links', 'hl.cls.client_auth': 'Authentication', 'hl.cls.client_other': 'Other client errors',
'hl.er.donut': 'Error classes', 'hl.er.donut.hint': 'Application and proxy errors are yours to fix; attacks and blocks mean the defences worked.',
'hl.er.total': 'errors',
'hl.er.time': 'Errors over time', 'hl.er.time.hint': 'Hourly, stacked by class.',
'hl.er.heat': 'Application errors by service and hour', 'hl.er.heat.hint': 'Only answers the backend itself failed (5xx from the origin).',
'hl.er.broken': 'Broken links', 'hl.er.broken.hint': 'Pages that answered 404 to a visitor who clicked a link. Fix the link or add a redirect.',
'hl.er.routes': 'Routes with the most errors', 'hl.er.routes.hint': 'Method and path (ids folded), by service and class.',
'hl.er.col.path': 'Missing path', 'hl.er.col.ref': 'Came from', 'hl.er.col.n': 'Hits', 'hl.er.col.last': 'Last',
'hl.er.col.svc': 'Service', 'hl.er.col.route': 'Route', 'hl.er.col.class': 'Class',
'hl.er.err': 'Could not load the error breakdown.', 'hl.er.retry': 'Try again',
'hl.er.empty': 'Nothing to show for this range.'
},
'pt-BR': {
'hl.er.title': 'De onde vêm os erros',
'hl.er.lead': '{n} erros; {atk} ataques frustrados, {app} erros reais de aplicação',
'hl.er.lead.body': 'De {req} requisições {range}, {proxy} dos erros são problema de proxy e {bot} vêm de rastreadores. Taxa de erro do servidor (aplicação + proxy sobre as requisições legítimas, sem cancelamentos do cliente): {rate}. Dados só desta instância ({inst}).',
'hl.er.lead.empty': 'Nenhum erro registrado',
'hl.er.lead.empty.body': 'Nenhuma resposta 4xx ou 5xx {range}, ou o log ainda não tem os campos de origem.',
'hl.cls.app': 'Aplicação', 'hl.cls.proxy': 'Proxy / rede', 'hl.cls.blocked': 'Bloqueado por regra', 'hl.cls.attack': 'Ataque',
'hl.cls.bot': 'Rastreadores', 'hl.cls.client_broken': 'Links quebrados', 'hl.cls.client_auth': 'Autenticação', 'hl.cls.client_other': 'Outros erros do cliente',
'hl.er.donut': 'Classes de erro', 'hl.er.donut.hint': 'Erros de aplicação e de proxy são seus para corrigir; ataques e bloqueios mostram que a defesa funcionou.',
'hl.er.total': 'erros',
'hl.er.time': 'Erros no tempo', 'hl.er.time.hint': 'Por hora, empilhados por classe.',
'hl.er.heat': 'Erros de aplicação por serviço e hora', 'hl.er.heat.hint': 'Só respostas em que o próprio backend falhou (5xx da origem).',
'hl.er.broken': 'Links quebrados', 'hl.er.broken.hint': 'Páginas que deram 404 para quem clicou num link. Corrija o link ou crie um redirecionamento.',
'hl.er.routes': 'Rotas com mais erros', 'hl.er.routes.hint': 'Método e caminho (ids agrupados), por serviço e classe.',
'hl.er.col.path': 'Caminho ausente', 'hl.er.col.ref': 'Veio de', 'hl.er.col.n': 'Acessos', 'hl.er.col.last': 'Último',
'hl.er.col.svc': 'Serviço', 'hl.er.col.route': 'Rota', 'hl.er.col.class': 'Classe',
'hl.er.err': 'Não foi possível carregar o detalhamento dos erros.', 'hl.er.retry': 'Tentar de novo',
'hl.er.empty': 'Nada para mostrar neste período.'
}
});
function clear(n) { while (n.firstChild) n.removeChild(n.firstChild); }
function pctOf(a, b) { return b > 0 ? U.fmt.pct(a / b) : '0%'; }
function table(cols, rows) {
var tb = el('tbody');
rows.forEach(function (r) { tb.appendChild(el('tr', null, r.map(function (c, i) { return el('td', { class: cols[i].cls || '' }, c); }))); });
return el('div', { class: 'hl-scroll' }, el('table', { class: 'hl-table' },
el('thead', null, el('tr', null, cols.map(function (c) { return el('th', { class: c.cls || '' }, c.label); }))), tb));
}
function clock(ts) { return U.fmt.clock ? U.fmt.clock(ts) : String(ts); }
var inst = null;
function create(root, ctx) {
var seq = 0, alive = true, data = null, c = ctx;
var grid = el('div', { class: 'grid-12 hl-page' });
var lead = el('div', { class: 'span-12' });
var pd = U.ui.panel({ title: t('hl.er.donut'), hint: t('hl.er.donut.hint'), loading: true, cls: 'span-4' });
var pt = U.ui.panel({ title: t('hl.er.time'), hint: t('hl.er.time.hint'), variant: 'chart', loading: true, cls: 'span-8' });
var ph = U.ui.panel({ title: t('hl.er.heat'), hint: t('hl.er.heat.hint'), variant: 'chart', loading: true, cls: 'span-12' });
var pb = U.ui.panel({ title: t('hl.er.broken'), hint: t('hl.er.broken.hint'), variant: 'list', loading: true, cls: 'span-6' });
var pr = U.ui.panel({ title: t('hl.er.routes'), hint: t('hl.er.routes.hint'), variant: 'list', loading: true, cls: 'span-6' });
[lead, pd, pt, ph, pb, pr].forEach(function (n) { grid.appendChild(n); });
root.appendChild(grid);
function chart(fn, args, host) {
if (U.charts && U.charts[fn]) host.appendChild(U.charts[fn].apply(null, args));
else host.appendChild(U.ui.empty(t('hl.er.empty')));
}
function paint() {
clear(lead); [pd, pt, ph, pb, pr].forEach(function (p) { clear(p.body); });
if (!data) return;
var d = data, cl = d.classes || {}, range = U.rangeLabel({ inline: true });
if (!d.errors) {
lead.appendChild(U.ui.lead(t('hl.er.lead.empty'), t('hl.er.lead.empty.body', { range: range }), 'neutral'));
[pd, pt, ph, pb, pr].forEach(function (p) { p.body.appendChild(U.ui.empty(t('hl.er.empty'))); });
return;
}
lead.appendChild(U.ui.lead(t('hl.er.lead', { n: U.fmt.num(d.errors), atk: pctOf(cl.attack, d.errors), app: pctOf(cl.app, d.errors) }),
t('hl.er.lead.body', { req: U.fmt.num(d.requests), range: range, proxy: pctOf(cl.proxy, d.errors), bot: pctOf(cl.bot, d.errors), rate: U.fmt.pct(d.app_error_rate || 0), inst: d.instance || '' }),
(cl.app || 0) > (cl.attack || 0) ? 'warn' : 'neutral'));
var main = ['app', 'proxy', 'blocked', 'attack', 'bot'].map(function (k) { return { key: k, label: t('hl.cls.' + k), value: cl[k] || 0 }; });
main.push({ key: 'client', label: t('hl.cls.client_other'), value: cl.client || 0 });
chart('donut', [main, { title: t('hl.er.donut'), centerLabel: t('hl.er.total') }], pd.body);
if (U.help && U.glossary) {
var lis = pd.body.querySelectorAll('.vz-legend li');
['app', 'proxy', 'blocked', 'attack', 'bot', 'client'].forEach(function (k, i) {
if (lis[i] && U.glossary.has('term.error_class.' + k)) U.help(lis[i], 'term.error_class.' + k);
});
}
var series = ORDER.map(function (k) { return { key: k, label: t('hl.cls.' + k), values: (d.timeline.series[k] || []) }; });
chart('stackedArea', [series, d.timeline.step, { start: d.timeline.start, title: t('hl.er.time') }], pt.body);
var hm = d.heatmap || {};
if ((hm.svcs || []).length && (hm.hours || []).length) {
var xl = hm.hours.map(function (h) { return new Date(h * 1000).getHours() + 'h'; });
var seen = {}, yl = hm.svcs.map(function (n) {
var b = String(n).split('.')[0].slice(0, 8) || n; seen[b] = (seen[b] || 0) + 1;
return seen[b] > 1 ? b + seen[b] : b;
});
chart('heatmap', [hm.err, xl, yl, { title: t('hl.er.heat') }], ph.body);
} else ph.body.appendChild(U.ui.empty(t('hl.er.empty')));
var br = d.broken || [];
if (U.help && U.glossary && U.glossary.has('term.broken_link')) U.help(pb.querySelector('h2'), 'term.broken_link');
if (br.length) pb.body.appendChild(table([{ label: t('hl.er.col.path'), cls: 'mono' }, { label: t('hl.er.col.ref'), cls: 'mono' }, { label: t('hl.er.col.n'), cls: 'num' }, { label: t('hl.er.col.last') }],
br.map(function (b) { return [b.path, b.ref, U.fmt.num(b.n), b.last ? U.fmt.ago(b.last) : '']; })));
else pb.body.appendChild(U.ui.empty(t('hl.er.empty')));
var tr = d.top_routes || [];
if (tr.length) pr.body.appendChild(table([{ label: t('hl.er.col.svc') }, { label: t('hl.er.col.route'), cls: 'mono' }, { label: t('hl.er.col.class') }, { label: t('hl.er.col.n'), cls: 'num' }],
tr.map(function (r) { return [r.svc, r.route, (/^(app|proxy|blocked|attack|bot)$/.test(r.class) ? t('hl.cls.' + r.class) : t('hl.cls.client_other')), U.fmt.num(r.n)]; })));
else pr.body.appendChild(U.ui.empty(t('hl.er.empty')));
}
function load() {
var my = ++seq;
var p = Object.assign({}, U.rangeParams());
if (c.host && c.host !== 'all') p.host = c.host;
if (c.domain && c.domain !== 'all') p.host = c.domain;
U.api('/api/v1/errors', p).then(function (r) { if (alive && my === seq) { data = r; paint(); } }, function () {
if (!alive || my !== seq || data) return;
clear(lead);
var b = el('button', { type: 'button', class: 'btn' }, t('hl.er.retry'));
b.addEventListener('click', load);
lead.appendChild(el('div', { class: 'state-error' }, el('strong', null, t('hl.er.err')), b));
});
}
load();
return { update: function (cx) { c = cx; load(); }, destroy: function () { alive = false; seq++; clear(root); } };
}
U.registerPage({
id: 'errors', group: 'analyze', titleKey: 'hl.er.title',
icon: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M12 3l9 16H3z"/><path d="M12 10v4"/><path d="M12 17h.01"/></svg>',
mount: function (node, ctx) { if (inst) inst.destroy(); inst = create(node, ctx || {}); },
update: function (ctx) { if (inst) inst.update(ctx); },
unmount: function () { if (inst) { inst.destroy(); inst = null; } }
});
})();