客戶端運行於提供 Unix 服務的伺服器,負責讀取系統 wtmpx 日誌,解析用戶登入/登出記錄,配對生成完整會話日誌,經 Socket 上傳至服務端匯總存儲。
config.xml (客戶端)、server-config.xml (服務端)IOUtil (文件/二進制讀寫)、LogData/LogRec (業務實體)RandomAccessFile 讀取二進制 wtmpx,按固定長度解析 user、pid、type(7登入/8登出)、time、host,寫入文本文件 log.txt,記錄書簽位置 last-position.txt。user+pid 匹配 type 7/8 生成 LogRec,寫入 logrec.txt,未配對寫入 login.txt。logrec.txt 內容,結束發送 OVER,收到 OK 刪除本地文件。Executors.newFixedThreadPool) 處理客戶端連接。SaveLogHandler 從阻塞隊列消費日誌寫入 server-logs.txt。OVER → 服務端回 OK/ERROR。<config> <logfile>wtmpx</logfile> <textlogfile>log.txt</textlogfile> <lastpositionfile>last-position.txt</lastpositionfile> <batch>10</batch> <logrecfile>logrec.txt</logrecfile> <loginlogfile>login.txt</loginlogfile> <serverhost>localhost</serverhost> <serverport>8088</serverport> </config>
<config> <logrecfile>server-logs.txt</logrecfile> <threadsum>30</threadsum> <serverport>8088</serverport> </config>
RandomAccessFile 隨機讀取 + 書簽機制斷點續傳。loginMap/logoutMap) O(N) 配對算法。BlockingQueue) 解耦接收與落盤。