Montray - a tray icon for systemd service health
Montray - a tray icon for systemd service health
Montray - 用于监控 systemd 服务健康状态的托盘图标工具
Mr. Montray is watching your services. Montray is a lightweight tray-icon monitoring utility for systemd services and anything else you can check from the command line, on both local and remote machines. Montray 先生正在监视你的服务。Montray 是一款轻量级的托盘图标监控工具,用于监控 systemd 服务以及任何可以通过命令行检查的内容,支持本地和远程机器。
Project history
项目背景
Problem: Linux doesn’t tell me loudly enough when a systemd service breaks. Back in 2021 my Syncthing service had been broken for weeks, and I only figured that out later, after noticing that my files got badly out of sync, and it wasn’t fun to reconcile. Systemd knew it was broken, yet it didn’t tell me. That’s not good enough. I also had a Certbot service silently stop working and fail to refresh certificates, and other similar cases. And I didn’t want some enterprisey monitoring for this simple task: I just wanted a simple icon, always present in the system tray: green means it’s all good, blinking yellow/red means something’s broken. That’s it. 问题:当 systemd 服务崩溃时,Linux 系统给出的提醒不够明显。早在 2021 年,我的 Syncthing 服务中断了数周,直到后来我发现文件严重不同步才意识到这一点,而修复这些同步问题非常麻烦。Systemd 虽然知道服务已崩溃,但并没有通知我。这显然不够好。此外,我的 Certbot 服务也曾静默停止工作,导致证书无法刷新,还有其他类似的情况。对于这种简单的任务,我不想使用那些企业级的监控方案:我只需要一个简单的图标,始终显示在系统托盘中:绿色表示一切正常,闪烁的黄色/红色表示有东西坏了。仅此而已。
Soon after, I wanted to reuse the same icon not only for systemd services, but also for arbitrary command-line checks, e.g. to check that there’s enough disk space, or that a RAID is healthy, or anything else really. So, meet Montray: a lightweight system-tray app that watches your services, runs command-line checks, and lets you know when something goes wrong. 不久之后,我希望不仅能用这个图标监控 systemd 服务,还能执行任意的命令行检查,例如检查磁盘空间是否充足、RAID 是否健康,或者其他任何事项。因此,向你介绍 Montray:一款轻量级的系统托盘应用,它能监控你的服务、运行命令行检查,并在出现问题时及时通知你。
Overview
概览
This project has two main parts: montray-server, a background service written in Go: runs on a machine, checks its health, and serves the current incidents via simple read-only WebSocket API; montray-ui, a desktop app written in Rust + Slint: connects to one or more montray-servers, receives data from them, shows a tray icon, sends desktop notifications, and provides a native GUI.
该项目主要由两部分组成:montray-server,一个用 Go 编写的后台服务,运行在机器上,负责检查健康状态,并通过简单的只读 WebSocket API 提供当前事件信息;montray-ui,一个用 Rust + Slint 编写的桌面应用,连接到一个或多个 montray-server,接收数据,显示托盘图标,发送桌面通知,并提供原生图形界面。
So montray-server is a server (which can run locally too), and montray-ui is a client which runs on e.g. a laptop. If we have a laptop and two servers, a typical setup looks like this:
因此,montray-server 是服务端(也可以在本地运行),而 montray-ui 是客户端(例如运行在笔记本电脑上)。如果我们有一台笔记本电脑和两台服务器,典型的架构如下:
(Flowchart omitted for brevity)
Loading
加载
Montray Server reports incidents, each of them has: A key, like systemd.my-service or free-space.exec-result; A state: warning or error. These incidents are generated according to the Montray Server configuration. For details, see Configuring Montray Server.
Montray Server 会报告事件,每个事件包含:一个键(Key),例如 systemd.my-service 或 free-space.exec-result;以及一个状态:警告(warning)或错误(error)。这些事件根据 Montray Server 的配置生成。详情请参阅“配置 Montray Server”。
Montray UI combines these incidents. For each incident, it also prefixes the keys with the ID for that particular server, such as my-server (which you specify in the Montray UI config), so the key becomes my-server.systemd.myservice. For details, see Configuring Montray UI. If an incident happens and we want to just acknowledge it but worry about it later, we can snooze it in the UI, so the icon stops being annoying but it’ll get unsnoozed again later.
Montray UI 会汇总这些事件。对于每个事件,它还会为键添加特定服务器的 ID 前缀,例如 my-server(你在 Montray UI 配置中指定),因此键会变为 my-server.systemd.myservice。详情请参阅“配置 Montray UI”。如果发生了事件,而我们只想先确认一下、稍后再处理,可以在 UI 中将其“静音”(snooze),这样图标就不会一直闪烁提醒,但稍后它会自动解除静音。
The tray icon shows the worst current non-snoozed state: 托盘图标会显示当前最严重的未静音状态:
- Gray: the initial state isn’t known yet;
- 灰色:初始状态未知;
- Green: everything is OK;
- 绿色:一切正常;
- Magenta blinking: Montray UI itself has an internal connection or tunnel error;
- 洋红色闪烁:Montray UI 本身存在内部连接或隧道错误;
- Yellow blinking: at least one warning;
- 黄色闪烁:至少有一个警告;
- Red blinking: at least one error.
- 红色闪烁:至少有一个错误。
Installation
安装
Quick Start (Linux)
快速入门 (Linux)
Monitoring local machine 监控本地机器
The easiest way to install both montray-server and montray-ui to monitor local machine health is as follows: First, download the latest prebuilt binaries from GitHub, like montray-server-x.y.z_linux_amd64.tar.gz and montray-ui-x.y.z_linux_amd64.tar.gz, and unpack them. You’ll get two binaries: montray-server and montray-ui. Then:
安装 montray-server 和 montray-ui 以监控本地机器健康状态的最简单方法如下:首先,从 GitHub 下载最新的预编译二进制文件(如 montray-server-x.y.z_linux_amd64.tar.gz 和 montray-ui-x.y.z_linux_amd64.tar.gz)并解压。你将获得两个二进制文件:montray-server 和 montray-ui。然后执行:
# Set up the monitoring service and start it. This also installs montray-server
# under /usr/local/bin when not already there.
sudo ./montray-server setup
# Install the desktop application system-wide:
sudo install -m 755 montray-ui /usr/local/bin/montray-ui
# Let the desktop application create its default config, autostart entry,
# and application launcher:
montray-ui setup
# Start the desktop application (Montray Server is already running):
montray-ui
You should now see a tray icon, and if you click on it, you’ll see the UI. When you reboot, it will start automatically. 现在你应该能看到一个托盘图标,点击它即可打开 UI。重启系统后,它会自动启动。
Monitoring remote machines 监控远程机器
If you have e.g. a personal server which you also want to monitor using the same interface on your desktop, then on each such remote machine follow the same steps as above, but only for montray-server (no need to install montray-ui on the servers).
如果你有一台个人服务器,也想在桌面上通过同一个界面进行监控,那么在每台远程机器上执行上述相同的步骤,但只需安装 montray-server(无需在服务器上安装 montray-ui)。
Having montray-server running on your server, we need to point our local montray-ui to it. By default, Montray Server only listens on 127.0.0.1, so we can’t reach it directly from a laptop. Presumably you have ssh access to your server with public key authentication (i.e. you can ssh there without a password), so the easiest way forward here is to establish an ssh tunnel, and Montray UI has convenient support for it: open the config file ~/.config/montray-ui/montray-ui.yml, and add one more entry to the wsClient.servers array, like that (adjusting at least your server hostname and username).
在服务器上运行 montray-server 后,我们需要将本地的 montray-ui 指向它。默认情况下,Montray Server 仅监听 127.0.0.1,因此我们无法从笔记本电脑直接访问它。假设你已通过公钥认证配置了 SSH 访问(即无需密码即可 SSH 登录),那么最简单的方法是建立 SSH 隧道,Montray UI 对此提供了便捷支持:打开配置文件 ~/.config/montray-ui/montray-ui.yml,并在 wsClient.servers 数组中添加一个条目(至少需要调整你的服务器主机名和用户名)。
(Configuration example omitted for brevity)
And restart Montray UI (montray-ui) by right-clicking the tray icon and selecting “Restart and reload configuration.” Open the UI and verify that the list of servers now includes your newly added remote server as well.
然后右键点击托盘图标并选择“Restart and reload configuration”来重启 Montray UI。打开 UI,确认服务器列表中现在包含了你刚添加的远程服务器。
SSH tunnel is not the only way to access remote servers; Montray UI also supports TLS and bearer token authentication. For details, see docs on Security. SSH 隧道并不是访问远程服务器的唯一方式;Montray UI 还支持 TLS 和 Bearer Token 认证。详情请参阅安全文档。
Configuration
配置
The default config (which sudo montray-server setup writes to /etc/montray-server.yml) is as follows: if any systemd service is…
默认配置(sudo montray-server setup 会将其写入 /etc/montray-server.yml)如下:如果任何 systemd 服务……