# monitor 使用手冊 :::success 程式: [Google drive](https://drive.google.com/drive/folders/19g9s76xS5ijomnbElTFJdpnp5560Q4lA?usp=sharing) ::: ## 使用前注意 1. 全部程式由 python3 撰寫,建議可以在 venv 環境中,執行此程式 2. 注意先安裝 requirements.txt 中所需的 library `pip install -r requirements.txt` ## 參數介紹 - 主要模式有兩項: 1. 監控特定 process 的使用資源(使用 [-r 或 --resource]),有以下四種參數可以進行設定 - (1) [-pro 或 --process] 監控的 process 名稱 - (2) [-m 或 --memory] 監控的 process 使用大於多少 MB 的記憶體屬於異常 - (3) [-han 或 --handle] 監控的 process 使用大於多少數量的 handle 屬於異常 (由於 -h 預設為 help 功能) - (4) [-c 或 --cpu] 監控的 process 使用大於多少 CPU 使用率屬於異常 - (5) [-t 或 --time] 每次檢查完,會間隔幾秒 - 例如 input command: `python .\monitor_ResourceOrFile.py -r -pro "chrome.exe" -m 52000 -han 10000 -c 10 -t 600` 2. 監控特定 file_path(C:\ProgramData\Task\Sonar.log) , 當有特定 "檔案內容" 出現 , 例如 ErrorLog 字樣, 就寫 log 告警 (使用 [-f 或 --file]),有以下兩種參數可以進行設定 - (1) [-p 或 --path] 監控特定資料夾或檔案,由於 Windows commandline 處理不夠規範,會導致參數 parse 失敗,結尾請勿有/或\ [參考資料](https://stackoverflow.com/questions/71283820/directory-parameter-on-windows-has-trailing-backslash-replaced-with-double-quote) - (2) [-str 或 --string] 監控特定字串 - (3) [-t 或 --time] 每次檢查完,會間隔幾秒 - 例如 input command: `python .\monitor_ResourceOrFile.py -f -p "D:\" -str "firefox.exe -t 600"`