一:Gatus简介:
Gatus 提供一个轻量级的监控健康,让开发者通过服务的简单 HTTP、ICMP 等协议来监控情况,并根据网页监控 TCP 的状态码或响应时间及正文来决定网站是否健康,如果发生的话异常,可以设置不同的 Alert 像是 Slack、Email、Teams、 Discord这个链接查看Dashboard 实际情况。它是Go语言写出来的,非常轻量。
官方github:https://github.com/TwiN/gatus
界面显示:
功能单一,但是非常实用的工具,设置简单,zabbix也可以监控网站,但是没有zabbix那么庞大。
二:docker-compose编写启动
通过 Docker 安装方式是最快的,搭配 Postgres,当然也可以用 SQLite 轻量数据库。
mkdir gatus
#创建gatus目录
cd gatus
#进入目录
vim docker-compose.yml
#编写docker-compose文件
内容如下:
version: '3.9'services:gatus:image: twinproduction/gatus:latestvolumes:- ./config:/configrestart: alwaysstop_signal: SIGINTstop_grace_period: 10sports: - 80:8080networks:- webpostgres:image: postgres:12volumes:- /data/monitor/database:/var/lib/postgresql/dataenvironment:- POSTGRES_DB=gatus- POSTGRES_USER=gatus- POSTGRES_PASSWORD=gatusnetworks:- webnetworks:web:external: true
启动docker-compose,第一次会报错,ERROR: Network web declared as external, but could not be found. Please create the network manually using docker network create web
and try again,所以需要手动创建docker network先。
如下:
ubuntu@ubuntu:~/gatus$ sudo docker-compose up -d
ERROR: Network web declared as external, but could not be found. Please create the network manually using `docker network create web` and try again.
ubuntu@ubuntu:~$ sudo docker network create web
8a7841b0c8cfacc29f0253872fa5a40918c4c0be2d79ed682afe3e61c079ad25
ubuntu@ubuntu:~$ sudo docker-compose up -d
启动以后,发现gatus为Restarting,不是up状态,原因时缺少配置文件
三:编写config.yaml配置文件
启动会生成config文件夹,进入config文件夹,创建配置文件
cd config
#进入配置文件夹
sudo vim config.yaml
#编写创建配置文件 config.yaml
内容如下,监控ywbj.cc这个网站,正常返回值200,延迟设置500毫秒,每60秒检测一次。
storage:type: postgrespath: "postgres://gatus:gatus@postgres:5432/gatus?sslmode=disable"endpoints:- name: ywbj.ccgroup: ywbjurl: "https://ywbj.cc"interval: 60sconditions:- "[STATUS] == 200"- "[RESPONSE_TIME] < 500"
创建完成后,gatus为up正常状态,浏览器打开IP本机地址。可正常观看
四:监控多个网站,并设置报警媒介
支持多种实时报警,具体可查阅官方官方github:https://github.com/TwiN/gatus
本人常用telegram作为报警媒介,设置如下,将telegram的token和id填入即可。
storage:type: postgrespath: "postgres://gatus:gatus@postgres:5432/gatus?sslmode=disable"alerting:telegram: token: "524123771617:AAHSLuaM3GndmYg1Jf1iBed0St0O7RBYigo"id: "-72563123001"endpoints:- name: ywbj.ccgroup: ywbjurl: "https://ywbj.cc"interval: 60sconditions:- "[STATUS] == 200"- "[RESPONSE_TIME] < 500"alerts:- type: telegramenabled: truesend-on-resolved: true- name: chinkh.comgroup: chinkhurl: "http://chinkh.com"interval: 60sconditions:- "[STATUS] == 200"- "[RESPONSE_TIME] < 500"alerts:- type: telegramenabled: truesend-on-resolved: true
报存退出,刷新页面
当检测网站状态不是200的正常值,或者响应速度在500毫秒以上,就会报警发送至telegram。
显示如下:
到这里,gatus网站监控设置完成。