監控

在 Prometheus 與 Grafana 看伺服器的狀況,數據中不含人名或檔案名稱。

本頁內容
  1. 開啟
  2. 在 Prometheus 中
  3. 有哪些數據
  4. Grafana
  5. 儀表板
  6. 不在其中的東西

開啟

開啟 控制台 › 監控。建立一個 權杖:它只會顯示一次,伺服器只保留它的指紋,請現在複製。然後開啟 回應指標請求。數據在網站的 /metrics,只有帶著 Authorization: Bearer <權杖> 的請求才拿得到。關閉時這個網址不存在。

可以列出允許請求的位址或網段(203.0.113.7、10.1.0.0/16);其他位址的請求會在檢查權杖之前就被拒絕。不列的話,任何位址都可以,但要有權杖。新的權杖會立即取代舊的。錯誤的權杖和錯誤的密碼一樣會記在該位址上,連續 20 次後要等一段時間。建立和更換權杖需要輸入你的密碼,也會記在活動紀錄。

在 Prometheus 中

新增一個抓取工作,把權杖當作憑證:

scrape_configs:
  - job_name: thirtyfile
    scheme: https
    authorization:
      credentials: tfm_…
    static_configs:
      - targets: ["files.example.com"]

警示規則的範例:

groups:
  - name: thirtyfile
    rules:
      - alert: ThirtyFileDown
        expr: up{job="thirtyfile"} == 0
        for: 5m
      - alert: ThirtyFileLocationDown
        expr: thirtyfile_storage_location_up == 0
        for: 5m
      - alert: ThirtyFileDiskNearlyFull
        expr: thirtyfile_disk_free_bytes / thirtyfile_disk_total_bytes < 0.1
        for: 15m
      - alert: ThirtyFileBackupOverdue
        expr: thirtyfile_backup_last_complete_age_seconds > 2 * 86400
      - alert: ThirtyFileBackgroundLoopStuck
        expr: time() - thirtyfile_background_last_success_timestamp_seconds{job="maintenance"} > 3 * 3600
      - alert: ThirtyFileCertificateEnds
        expr: thirtyfile_ftps_certificate_expiry_seconds < 14 * 86400

有哪些數據

每個名稱都以 thirtyfile_ 開頭。發佈過的名稱不會更改;新版本可能增加數據。

名稱標籤意義
thirtyfile_build_infoversion版本;值固定為 1
thirtyfile_process_start_time_seconds伺服器何時啟動
thirtyfile_process_uptime_seconds啟動後經過的秒數
thirtyfile_process_resident_memory_bytes佔用的記憶體(Linux)
thirtyfile_process_open_files開啟的檔案與連線(Linux)
thirtyfile_process_threads執行緒數(Linux)
thirtyfile_http_requests_totalmethod, code已回應的請求,依方法和狀態類別
thirtyfile_http_request_duration_seconds從請求到開始回應的秒數(直方圖)
thirtyfile_http_requests_in_flight正在處理的請求
thirtyfile_sign_in_events_totalevent登入紀錄所用名稱的登入事件:login、bad_password、locked、2fa_failed…
thirtyfile_sessions尚未結束的登入階段
thirtyfile_accountsstate帳號,active 或 disabled
thirtyfile_storage_operations_totallocation, op, outcome儲存位置的操作,依結果:ok、error、timeout
thirtyfile_storage_bytes_totallocation, op從儲存位置讀取與寫入的位元組
thirtyfile_storage_operation_duration_secondslocation, op儲存操作花的時間(直方圖)
thirtyfile_storage_location_uplocation位置可使用為 1,不能用為 0
thirtyfile_storage_location_live_bytes, _trash_bytes, _version_byteslocation位置上各空間的檔案位元組:現有、垃圾桶、較早版本
thirtyfile_storage_location_disk_free_bytes, _disk_total_byteslocation位置所在磁碟的可用與總位元組
thirtyfile_disk_free_bytes, thirtyfile_disk_total_bytesvolume資料資料夾與儲存資料夾所在磁碟的可用與總位元組(data、storage)
thirtyfile_database_size_bytes, thirtyfile_database_wal_size_bytes資料庫及其預寫日誌的大小
thirtyfile_tasks_runningkind正在執行的工作(壓縮、解壓縮、複製、移動…)
thirtyfile_tasks_finished_totalkind, outcome結束的工作,done 或 failed
thirtyfile_background_last_success_timestamp_secondsjob背景迴圈上次完成工作的時間(maintenance、usage_sampler、location_checks、backup_jobs、replica_jobs、space_moves)
thirtyfile_backup_last_complete_age_secondspolicy已開啟的政策上次完成快照至今的秒數;從未完成則沒有
thirtyfile_backup_policiessnapshot已開啟的政策,有或沒有完成過快照
thirtyfile_replica_sync_age_secondspolicy副本政策的每個目標都同步到最新後經過的秒數;有目標從未同步則沒有
thirtyfile_content_search_queue, thirtyfile_content_search_failed等待讀取內容以供搜尋的檔案,以及讀取失敗的檔案
thirtyfile_alert_deliveries_pending, thirtyfile_alert_deliveries_failed等待寄出的警示訊息(email、webhook),以及已放棄的
thirtyfile_alerts_firingkind目前正在發出的管理員警示,依種類
thirtyfile_ftps_certificate_expiry_secondsFTPS 憑證到期前的秒數(過期後為負數)
thirtyfile_emails_totaloutcome寄出的 email,sent 或 failed
thirtyfile_metrics_requests_totaloutcome對這些數據的請求:ok、unauthorized、forbidden、too_many

Grafana

匯入 thirtyfile-grafana.json(Dashboards › New › Import)並選擇你的 Prometheus。畫面會顯示請求與回應時間、登入、儲存操作、磁碟、工作、備份和正在發出的警示。

儀表板

控制台 › 儀表板 不需要 Prometheus。它會告訴你伺服器是否正常(與 /api/health 相同的檢查,並附上原因)、目前發出的管理員警示、登入與活躍的人數、工作、上傳和可用磁碟空間,以及最近 24 小時或 7 天的圖表:請求與伺服器錯誤、回應時間、使用者與工作、儲存操作、登入失敗和可用磁碟空間。也會列出最近的伺服器錯誤與登入失敗,並連到 活動紀錄。圖表由伺服器每五分鐘記下一次、保存八天的數據畫成,不論是否開啟 /metrics;沒有數據的區段表示當時伺服器沒有在執行。

不在其中的東西

沒有人名、檔案名稱、訪客位址或路徑:標籤只有固定的詞(請求方法、工作種類、事件種類),以及管理員自己取的儲存位置和備份政策名稱。名稱中若含引號或換行,會依格式要求跳脫。

伺服器重新啟動時計數會從零開始,這是 Prometheus 預期的行為(rate() 和 increase() 會處理)。需要查詢才知道的數據(登入階段、帳號、磁碟、資料庫、備份)在監控開啟期間每 15 秒查看一次並放在記憶體:讀取指標不會鎖定、也不讀磁碟,所以頻繁抓取不會有負擔。記憶體、開啟的檔案和執行緒數只在 Linux 上提供。