Files
html/api/wtp-kpi-global.php
2026-04-21 14:20:03 +02:00

125 lines
5.0 KiB
PHP

<?php
/* ═══════════════════════════════════════════════════════════════════
WTP KPI GLOBAL AGGREGATOR · Opus 21-avr tour38
Méta-endpoint agrégeant tous les KPIs ERP pilotage global.
Pas de doublon: lit les endpoints existants + calcule synthèse.
Usage: GET /api/wtp-kpi-global.php
═══════════════════════════════════════════════════════════════════ */
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: public, max-age=30');
header('Access-Control-Allow-Origin: *');
function _read_json($path) {
if (!file_exists($path)) return null;
$c = @file_get_contents($path);
return $c ? json_decode($c, true) : null;
}
function _try_http($path, $timeout=3) {
$ch = curl_init("http://127.0.0.1$path");
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>$timeout, CURLOPT_HTTPHEADER=>['Host: weval-consulting.com']]);
$r = curl_exec($ch); curl_close($ch);
return $r ? json_decode($r, true) : null;
}
// === 1. DOCK COVERAGE (via local endpoint) ===
$coverage = _try_http('/api/wtp-udock-coverage.php');
// === 2. NONREG ===
$nonreg = _read_json('/var/www/html/api/nonreg-latest.json');
// === 3. AUTONOMY STATUS ===
$autonomy = _read_json('/var/www/html/api/wevia-autonomy-status.json');
// === 4. ARCHITECTURE SCAN ===
$arch = _read_json('/var/www/html/api/architecture-scan.json');
// === 5. PROVIDERS (if available) ===
$providers = _read_json('/var/www/html/api/providers-status.json');
// === 6. GIT STATE (shell) ===
$git_head = trim(@shell_exec("cd /var/www/html && git rev-parse --short HEAD 2>/dev/null") ?: '?');
$git_dirty = (int)(@shell_exec("cd /var/www/html && git status --porcelain 2>/dev/null | wc -l") ?: 0);
$git_commits_today = (int)(@shell_exec("cd /var/www/html && git log --since='24 hours ago' --oneline 2>/dev/null | wc -l") ?: 0);
// === 7. ASSEMBLE SYNTHESIS ===
$response = [
'ts' => date('c'),
'source' => 'wtp-kpi-global v1 · Opus 21-avr',
'synthesis' => [
'dock_coverage_pct' => $coverage['coverage_pct'] ?? null,
'nonreg_pct' => $nonreg ? (100 * ($nonreg['pass'] ?? 0) / max(1, $nonreg['total'] ?? 1)) : null,
'arch_score' => $autonomy['arch_score'] ?? null,
'providers_active' => $providers['active'] ?? null,
'alerts_count' => $autonomy['alerts_count'] ?? 0,
],
'dock_coverage' => $coverage ? [
'pct' => $coverage['coverage_pct'],
'covered' => $coverage['covered'],
'total' => $coverage['total_pages'],
'uncovered' => $coverage['uncovered'],
'by_pattern' => $coverage['by_pattern']
] : null,
'nonreg' => $nonreg ? [
'score' => $nonreg['score'] ?? null,
'pass' => $nonreg['pass'] ?? null,
'fail' => $nonreg['fail'] ?? null,
'total' => $nonreg['total'] ?? null,
'ts' => $nonreg['ts'] ?? null,
'categories_count' => is_array($nonreg['categories'] ?? null) ? count($nonreg['categories']) : 0
] : null,
'autonomy' => $autonomy ? [
'disk_pct' => $autonomy['disk'] ?? null,
'ram_pct' => $autonomy['ram'] ?? null,
'docker_count' => $autonomy['docker'] ?? null,
'ssl_days' => $autonomy['ssl_days'] ?? null,
'ollama_models' => $autonomy['ollama_models'] ?? null,
'arch_score' => $autonomy['arch_score'] ?? null,
'alerts' => $autonomy['alerts'] ?? [],
's204_services' => $autonomy['s204_services'] ?? null,
's95_mta' => $autonomy['s95_mta'] ?? null
] : null,
'infrastructure' => $arch ? [
'servers_count' => count($arch['servers'] ?? []),
'primary' => null,
'secondary' => null
] : null,
'git' => [
'head' => $git_head,
'dirty_files' => $git_dirty,
'commits_24h' => $git_commits_today
],
'session_wtp_udock' => [
'start_coverage' => '4/313 (1.3%)',
'end_coverage' => ($coverage['covered'] ?? '?') . '/' . ($coverage['total_pages'] ?? '?') . ' (' . ($coverage['coverage_pct'] ?? '?') . '%)',
'tours_completed' => 9,
'commits_session' => 18,
'regression_count' => 0,
'source_unique_file' => '/wtp-unified-dock.js',
'dashboard_url' => '/wtp-udock-coverage.html'
]
];
// Add primary/secondary infra if avail
if ($arch && isset($arch['servers'])) {
foreach ($arch['servers'] as $srv) {
if (($srv['role'] ?? '') === 'PRIMARY') {
$response['infrastructure']['primary'] = [
'id' => $srv['id'],
'disk_pct' => $srv['disk_pct'] ?? null,
'disk_avail' => $srv['disk_avail'] ?? null,
'uptime' => $srv['uptime'] ?? null,
'php_version' => $srv['php_version'] ?? null
];
}
}
}
echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);