Пример #1
0
    reset($timeConnection);
    $maxConcurrentConnections = 0;
    $maxConcurrentConnectionsTime = 0;
    $concurrentConnections = 0;
    foreach ($timeConnection as $unixTime => $eventArray) {
        foreach ($eventArray as $event) {
            if ('C' === $event) {
                ++$concurrentConnections;
                if ($concurrentConnections > $maxConcurrentConnections) {
                    $maxConcurrentConnections = $concurrentConnections;
                    $maxConcurrentConnectionsTime = $unixTime;
                }
            } else {
                --$concurrentConnections;
            }
        }
    }
    $totalTraffic = 0;
    // convert the user list in unique user count for that day, rework array
    // key and determine total amount of traffic
    foreach ($statsData as $date => $entry) {
        $statsData[$date]['date'] = $date;
        $statsData[$date]['unique_user_count'] = count($entry['user_list']);
        unset($statsData[$date]['user_list']);
        $totalTraffic += $entry['traffic'];
    }
    FileIO::writeJsonFile($outFile, ['days' => array_values($statsData), 'total_traffic' => $totalTraffic, 'generated_at' => time(), 'max_concurrent_connections' => $maxConcurrentConnections, 'max_concurrent_connections_time' => $maxConcurrentConnectionsTime, 'first_entry' => $firstEntryTime, 'last_entry' => $lastEntryTime, 'unique_users' => count($uniqueUsers)], 0644);
} catch (Exception $e) {
    echo sprintf('ERROR: %s', $e->getMessage()) . PHP_EOL;
    exit(1);
}
Пример #2
0
                // XXX if an error occurred decoding the message, it was
                // probably a log error message, ignore them for now, but later we
                // will need them as well!
                continue;
            }
            if (!verifyMessage($messageData, 'disconnect')) {
                continue;
            }
            $instanceId = $messageData['INSTANCE_ID'];
            $poolId = $messageData['POOL_ID'];
            $logKey = sprintf('%s:%s:%s', $poolId, $messageData['common_name'], $messageData['time_unix']);
            // XXX what if instanceId key does not exist?
            if (!array_key_exists($logKey, $logData[$instanceId])) {
                // XXX we did not find a matching connect entry...
                // just ignore it
                continue;
            }
            $dataTransferred = $messageData['bytes_sent'] + $messageData['bytes_received'];
            $logData[$instanceId][$logKey] = array_merge($logData[$instanceId][$logKey], ['disconnect_time' => $messageData['time_unix'] + intval($messageData['time_duration']), 'traffic' => $dataTransferred]);
        }
    }
    foreach ($logData as $instanceId => $logEntries) {
        $logFile = sprintf('%s/data/%s/log.json', dirname(__DIR__), $instanceId);
        $logDir = dirname($logFile);
        FileIO::createDir($logDir, 0711);
        FileIO::writeJsonFile($logFile, ['entries' => array_values($logEntries)], 0644);
    }
} catch (Exception $e) {
    echo sprintf('ERROR: %s', $e->getMessage()) . PHP_EOL;
    exit(1);
}