Files
wevads-platform/scripts/api_n8n-stats.php
2026-02-26 04:53:11 +01:00

24 lines
800 B
PHP
Executable File

<?php
header('Content-Type: application/json');
try {
$dbfile = '/opt/n8n/.n8n/database.sqlite';
if (!file_exists($dbfile)) {
throw new Exception("Database not found");
}
$total = trim(shell_exec("sqlite3 '$dbfile' 'SELECT COUNT(*) FROM workflow_entity;'"));
$active = trim(shell_exec("sqlite3 '$dbfile' 'SELECT COUNT(*) FROM workflow_entity WHERE active=1;'"));
$workflows = shell_exec("sqlite3 -json '$dbfile' 'SELECT id, name, active FROM workflow_entity ORDER BY name;'");
echo json_encode([
'success' => true,
'total' => (int)$total,
'active' => (int)$active,
'workflows' => json_decode($workflows) ?: []
]);
} catch(Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}