live-now metrics: gw newest-first + 90min fresh window, dashboard Live90m column (treg revokes grants ~1-1.5h)
This commit is contained in:
+10
-1
@@ -104,6 +104,12 @@ def _tok(r):
|
||||
return r.get("org_token") or r.get("token") or ""
|
||||
|
||||
|
||||
def _live_cutoff():
|
||||
"""UTC ISO prefix for 'registered within last 90 min' (treg revokes grants ~1-1.5h after signup)."""
|
||||
import datetime as _dt
|
||||
return (_dt.datetime.now(_dt.timezone.utc) - _dt.timedelta(minutes=90)).strftime("%Y-%m-%dT%H:%M")
|
||||
|
||||
|
||||
def door_stats():
|
||||
out = {}
|
||||
total_orgs = total_paid = 0
|
||||
@@ -119,8 +125,11 @@ def door_stats():
|
||||
s = r.get("stage", "?")
|
||||
stages[s] = stages.get(s, 0) + 1
|
||||
last_ts = rows[-1].get("ts", "") if rows else ""
|
||||
live = [r for r in paid if (r.get("ts") or "") >= _live_cutoff()]
|
||||
out[door] = {"total": len(rows), "orgs": len(orgs), "paid": len(paid),
|
||||
"usd": round(usd, 2), "fails": stages, "last": last_ts}
|
||||
"usd": round(usd, 2), "fails": stages, "last": last_ts,
|
||||
"live_now": len(live),
|
||||
"live_usd": round(sum(int(r.get("balance_micro") or 0) for r in live) / 1e6, 2)}
|
||||
total_orgs += len(orgs)
|
||||
total_paid += len(paid)
|
||||
total_usd += usd
|
||||
|
||||
@@ -126,7 +126,7 @@
|
||||
<div class="dim">С грантом $1</div><div class="stat-value" id="s-paid">—</div>
|
||||
</div></div>
|
||||
<div class="card"><div class="card-content">
|
||||
<div class="dim">Сумма на банках</div><div class="stat-value" id="s-usd">—</div>
|
||||
<div class="dim">Живые сейчас (90 мин)</div><div class="stat-value" id="s-usd">—</div>
|
||||
</div></div>
|
||||
<div class="card"><div class="card-content">
|
||||
<div class="dim">Волны</div><div class="stat-value" id="s-loops">—</div>
|
||||
@@ -137,7 +137,7 @@
|
||||
<div class="card-title">Двери</div>
|
||||
<div class="card-description">realmail = реальные почтовые ящики (mail.tm maxxspace.com / tempmail.lol) · catchall = свои домены (.loc.cc) — безлимитно, $1/акк · voidash — домены заблокированы treg · github — пул suspended · tonline — промо выключено</div>
|
||||
</div><div class="card-content tablewrap">
|
||||
<table><thead><tr><th>Дверь</th><th>Записей</th><th>Оргов</th><th>Paid</th><th>$</th><th>Последняя</th><th>Ошибки</th></tr></thead>
|
||||
<table><thead><tr><th>Дверь</th><th>Записей</th><th>Оргов</th><th>Paid</th><th>$</th><th>Live 90м</th><th>Последняя</th><th>Ошибки</th></tr></thead>
|
||||
<tbody id="doors"></tbody></table>
|
||||
</div></div>
|
||||
</section>
|
||||
@@ -246,7 +246,9 @@ async function stats(){
|
||||
const t = d.doors._totals;
|
||||
$('#s-orgs').textContent = t.orgs;
|
||||
$('#s-paid').textContent = t.paid;
|
||||
$('#s-usd').textContent = '$'+t.usd.toFixed(2);
|
||||
let liveN=0, liveU=0;
|
||||
for (const [dr,s] of Object.entries(d.doors)) { if(dr!=='_totals'){ liveN+=s.live_now||0; liveU+=s.live_usd||0; } }
|
||||
$('#s-usd').textContent = liveN+' · $'+liveU.toFixed(2);
|
||||
const loops = d.loops; const run = Object.entries(loops).filter(([k,v])=>v).map(([k])=>k);
|
||||
$('#s-loops').textContent = run.length ? run.length+' ▶' : '0';
|
||||
$('#s-loopdet').textContent = run.length ? run.join(', ') : 'все остановлены';
|
||||
@@ -258,6 +260,7 @@ async function stats(){
|
||||
const fails = Object.entries(s.fails||{}).map(([k,v])=>k+':'+v).join(' ')||'—';
|
||||
html += `<tr><td><b>${door}</b></td><td>${s.total}</td><td>${s.orgs}</td>
|
||||
<td>${s.paid}</td><td>$${s.usd.toFixed(2)}</td>
|
||||
<td><b>${s.live_now??0}</b> · $${(s.live_usd??0).toFixed(2)}</td>
|
||||
<td class="dim">${(s.last||'').slice(0,19).replace('T',' ')}</td><td class="dim">${fails}</td></tr>`;
|
||||
}
|
||||
$('#doors').innerHTML = html;
|
||||
|
||||
+19
-2
@@ -2,6 +2,7 @@
|
||||
# Rotates bank tokens, quarantines dead ones, hot-reloads banks every 60s.
|
||||
# Port 8751. Local key: gw_key.txt (auto-generated).
|
||||
import json, os, random, re, threading, time, glob, sys
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
import urllib.request, urllib.error
|
||||
@@ -60,9 +61,12 @@ def load_pool():
|
||||
continue
|
||||
seen.add(tok)
|
||||
pool.append({"token": tok, "org_id": r.get("org_id"),
|
||||
"src": os.path.basename(path), "fails": 0, "q": False})
|
||||
"src": os.path.basename(path), "fails": 0, "q": False,
|
||||
"ts": r.get("ts") or ""})
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
# treg revokes grants ~1-1.5h after signup — newest tokens first
|
||||
pool.sort(key=lambda p: str(p["ts"]), reverse=True)
|
||||
with _lock:
|
||||
_pool[:] = pool
|
||||
_last_load = time.time()
|
||||
@@ -83,7 +87,20 @@ def next_tok():
|
||||
live = [p for p in _pool if not p["q"]]
|
||||
if not live:
|
||||
return None
|
||||
p = live[_idx % len(live)]
|
||||
# prefer tokens inside the ~1.5h survival window (ts desc sorted pool)
|
||||
cutoff = datetime.now(timezone.utc).replace(microsecond=0) - timedelta(minutes=90)
|
||||
fresh = []
|
||||
for p in live:
|
||||
try:
|
||||
ts = datetime.fromisoformat(p["ts"].replace("Z", "+00:00"))
|
||||
if ts.tzinfo is None:
|
||||
ts = ts.replace(tzinfo=timezone.utc)
|
||||
if ts >= cutoff:
|
||||
fresh.append(p)
|
||||
except Exception:
|
||||
pass
|
||||
cand = fresh or live
|
||||
p = cand[_idx % len(cand)]
|
||||
_idx += 1
|
||||
return p
|
||||
|
||||
|
||||
Reference in New Issue
Block a user