监控
在 Prometheus 和 Grafana 查看服务器的状况,数据中不含人名或文件名。
开启
打开 控制台 › 监控。创建一个 令牌:它只显示一次,服务器只保留它的指纹,请现在复制。然后开启 响应指标请求。数据在网站的 /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_info | version | 版本;值固定为 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_total | method, code | 已响应的请求,按方法和状态类别 |
thirtyfile_http_request_duration_seconds | 从请求到开始响应的秒数(直方图) | |
thirtyfile_http_requests_in_flight | 正在处理的请求 | |
thirtyfile_sign_in_events_total | event | 登录日志所用名称的登录事件:login、bad_password、locked、2fa_failed… |
thirtyfile_sessions | 尚未结束的登录会话 | |
thirtyfile_accounts | state | 账号,active 或 disabled |
thirtyfile_storage_operations_total | location, op, outcome | 存储位置的操作,按结果:ok、error、timeout |
thirtyfile_storage_bytes_total | location, op | 从存储位置读取与写入的字节 |
thirtyfile_storage_operation_duration_seconds | location, op | 存储操作花的时间(直方图) |
thirtyfile_storage_location_up | location | 位置可使用为 1,不能用为 0 |
thirtyfile_storage_location_live_bytes, _trash_bytes, _version_bytes | location | 位置上各空间的文件字节:现有、回收站、较早版本 |
thirtyfile_storage_location_disk_free_bytes, _disk_total_bytes | location | 位置所在磁盘的可用与总字节 |
thirtyfile_disk_free_bytes, thirtyfile_disk_total_bytes | volume | 数据文件夹与存储文件夹所在磁盘的可用与总字节(data、storage) |
thirtyfile_database_size_bytes, thirtyfile_database_wal_size_bytes | 数据库及其预写日志的大小 | |
thirtyfile_tasks_running | kind | 正在运行的任务(压缩、解压、复制、移动…) |
thirtyfile_tasks_finished_total | kind, outcome | 结束的任务,done 或 failed |
thirtyfile_background_last_success_timestamp_seconds | job | 后台循环上次完成工作的时间(maintenance、usage_sampler、location_checks、backup_jobs、replica_jobs、space_moves) |
thirtyfile_backup_last_complete_age_seconds | policy | 已开启的策略上次完成快照至今的秒数;从未完成则没有 |
thirtyfile_backup_policies | snapshot | 已开启的策略,有或没有完成过快照 |
thirtyfile_replica_sync_age_seconds | policy | 副本策略的每个目标都同步到最新后经过的秒数;有目标从未同步则没有 |
thirtyfile_content_search_queue, thirtyfile_content_search_failed | 等待读取内容以供搜索的文件,以及读取失败的文件 | |
thirtyfile_alert_deliveries_pending, thirtyfile_alert_deliveries_failed | 等待发出的告警消息(邮件、webhook),以及已放弃的 | |
thirtyfile_alerts_firing | kind | 目前正在发出的管理员告警,按种类 |
thirtyfile_ftps_certificate_expiry_seconds | FTPS 证书到期前的秒数(过期后为负数) | |
thirtyfile_emails_total | outcome | 发出的邮件,sent 或 failed |
thirtyfile_metrics_requests_total | outcome | 对这些数据的请求:ok、unauthorized、forbidden、too_many |
Grafana
导入 thirtyfile-grafana.json(Dashboards › New › Import)并选择你的 Prometheus。画面会显示请求与响应时间、登录、存储操作、磁盘、任务、备份和正在发出的告警。
仪表板
控制台 › 仪表板 不需要 Prometheus。它会告诉你服务器是否正常(与 /api/health 相同的检查,并附上原因)、当前发出的管理员告警、登录与活跃的人数、任务、上传和可用磁盘空间,以及最近 24 小时或 7 天的图表:请求与服务器错误、响应时间、用户与任务、存储操作、登录失败和可用磁盘空间。也会列出最近的服务器错误与登录失败,并链接到 活动日志。图表由服务器每五分钟记下一次、保存八天的数据画成,不论是否开启 /metrics;没有数据的区段表示当时服务器没有在运行。
不在其中的东西
没有人名、文件名、访客地址或路径:标签只有固定的词(请求方法、任务种类、事件种类),以及管理员自己取的存储位置和备份策略名称。名称中若含引号或换行,会按格式要求转义。
服务器重启时计数会从零开始,这是 Prometheus 预期的行为(rate() 和 increase() 会处理)。需要查询才知道的数据(登录会话、账号、磁盘、数据库、备份)在监控开启期间每 15 秒查看一次并放在内存:读取指标不会加锁、也不读磁盘,所以频繁抓取不会有负担。内存、打开的文件和线程数只在 Linux 上提供。