<?php require_once __DIR__.'/lib/v7_bootstrap.php';
$since=time()-86400;$s=$pdo->prepare('SELECT event_name,COUNT(*) c FROM itz_v7_events WHERE created_at>=:t GROUP BY event_name ORDER BY c DESC LIMIT 20');$s->execute([':t'=>$since]);$events24=$s->fetchAll(PDO::FETCH_ASSOC)?:[];
$s=$pdo->prepare('SELECT metric_name,COUNT(*) samples,AVG(metric_value) avg_v,MAX(metric_value) max_v,SUM(metric_value) sum_v FROM itz_v7_metrics WHERE created_at>=:t GROUP BY metric_name ORDER BY samples DESC LIMIT 30');$s->execute([':t'=>$since]);$metrics=$s->fetchAll(PDO::FETCH_ASSOC)?:[];
$timeline=$pdo->query('SELECT * FROM itz_v7_events ORDER BY id DESC LIMIT 60')->fetchAll(PDO::FETCH_ASSOC)?:[];$audits=$pdo->query('SELECT * FROM itz_v7_audit ORDER BY id DESC LIMIT 40')->fetchAll(PDO::FETCH_ASSOC)?:[];
?>
<!doctype html><html lang="fa" dir="rtl"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Observability | iTzAYDiN-BOT</title><link rel="stylesheet" href="css/theme.css"><link rel="stylesheet" href="css/admin-extra.css"><link rel="stylesheet" href="css/ay-controls.css"><script src="js/theme.js" defer></script><style>.ogrid{display:grid;grid-template-columns:1fr 1fr;gap:12px}.mono{font-family:monospace;font-size:11px;direction:ltr}.event-pill{display:inline-flex;padding:4px 7px;border-radius:999px;background:color-mix(in srgb,var(--accent) 10%,transparent);color:var(--accent)}@media(max-width:900px){.ogrid{grid-template-columns:1fr}}</style></head><body><section id="container"><?php include 'header.php';?><section id="main-content"><div class="wrapper"><div class="page-head"><div><div class="page-head__title">📡 Observability</div><div class="page-head__sub">Event Timeline، Metrics و Audit Trail در یک نقطه</div></div><a class="btn btn-outline btn-sm" href="architecture.php">Architecture OS</a></div><div class="ogrid"><div class="card"><div class="card__head"><div class="card__title">Events · 24h</div></div><?php foreach($events24 as $e):?><div style="display:flex;justify-content:space-between;padding:7px;border-bottom:1px solid var(--border-soft)"><span class="event-pill"><?=itz_v7_h($e['event_name'])?></span><b><?=number_format((int)$e['c'])?></b></div><?php endforeach;?></div><div class="card"><div class="card__head"><div class="card__title">Metrics · 24h</div></div><div class="table-wrap"><table class="display app-table"><thead><tr><th>Metric</th><th>Samples</th><th>Avg</th><th>Max</th></tr></thead><tbody><?php foreach($metrics as $m):?><tr><td class="mono"><?=itz_v7_h($m['metric_name'])?></td><td><?=intval($m['samples'])?></td><td><?=round((float)$m['avg_v'],2)?></td><td><?=round((float)$m['max_v'],2)?></td></tr><?php endforeach;?></tbody></table></div></div></div>
<div class="ogrid" style="margin-top:12px"><div class="card"><div class="card__head"><div class="card__title">Live Event Timeline</div></div><div class="table-wrap"><table class="display app-table"><thead><tr><th>Event</th><th>Actor</th><th>Payload</th><th>Time</th></tr></thead><tbody><?php foreach($timeline as $e):?><tr><td><?=itz_v7_h($e['event_name'])?></td><td><?=itz_v7_h(($e['actor_type']??'').':'.($e['actor_id']??''))?></td><td class="mono"><?=itz_v7_h(function_exists('mb_strimwidth')?mb_strimwidth((string)$e['payload_json'],0,120,'…','UTF-8'):substr((string)$e['payload_json'],0,120))?></td><td><?=date('H:i:s',(int)$e['created_at'])?></td></tr><?php endforeach;?></tbody></table></div></div><div class="card"><div class="card__head"><div class="card__title">Audit Trail</div></div><div class="table-wrap"><table class="display app-table"><thead><tr><th>Category</th><th>Action</th><th>Target</th><th>Time</th></tr></thead><tbody><?php foreach($audits as $a):?><tr><td><?=itz_v7_h($a['category'])?></td><td><?=itz_v7_h($a['action_name'])?></td><td><?=itz_v7_h($a['target'])?></td><td><?=date('Y-m-d H:i',(int)$a['created_at'])?></td></tr><?php endforeach;?></tbody></table></div></div></div>
</div></section></section></body></html>
