logo NodeSeekbeta

【哪吒监控】网络延迟 Y 轴限制

众所周知,当前版本哪吒不支持设置延迟上限,容易出现爆Y值导致数据可读性下降。
研究发现可以用自定义代码限制。

优点:仅前端抑制,不影响通知
缺点:无法查看超过上限的真实值

image
抑制后
image

添加在自定义代码,刷新即可生效,根据实际情况设置上限。

<script>
  // 固定延迟上限(毫秒)。>0 生效;设为 0 可关闭
  window.LatencyCapMs = 1500;

  (function () {
    if (window.__LC) return; window.__LC = true;

    const cap = () => { const n = +window.LatencyCapMs; return Number.isFinite(n) && n > 0 ? n : 0; };
    const clamp = (n) => (typeof n === 'number' && Number.isFinite(n) ? Math.min(n, cap() || n) : n);
    const hit = (u) => { try { u = typeof u === 'string' ? u : (u && u.url) || ''; return /\/api\/v1\/service(\/|$|\?)/i.test(u); } catch { return false; } };

    const fix = (d) => {
      if (!cap() || d == null) return d;
      if (Array.isArray(d)) return d.map(fix);
      if (typeof d === 'object') {
        const o = Array.isArray(d) ? [] : {};
        for (const k in d) {
          const v = d[k];
          if (k === 'avg_delay' || k === 'delay') {
            o[k] = Array.isArray(v) ? v.map(clamp) : clamp(v);
          } else {
            o[k] = fix(v);
          }
        }
        return o;
      }
      return d;
    };

    const of = window.fetch;
    window.fetch = async (...a) => {
      const r = await of(...a);
      try {
        if (!cap() || !hit(r.url || a[0]) || !r.ok || !((r.headers.get('content-type') || '').includes('json'))) return r;
        const j = await r.clone().json(), p = fix(j);
        if (p !== j) {
          return new Response(JSON.stringify(p), {
            status: r.status,
            statusText: r.statusText,
            headers: { 'content-type': 'application/json; charset=utf-8' },
          });
        }
      } catch {}
      return r;
    };
  })();
</script>

你好啊,陌生人!

我的朋友,看起来你是新来的,如果想参与到讨论中,点击下面的按钮!

📈用户数目📈

目前论坛共有60112位seeker

🎉欢迎新用户🎉