一: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:latest volumes: - ./config:/config restart: always stop_signal: SIGINT stop_grace_period: 10s ports: - 80:8080 networks: - web postgres: image: postgres:12 volumes: - /data/monitor/database:/var/lib/postgresql/data environment: - POSTGRES_DB=gatus - POSTGRES_USER=gatus - POSTGRES_PASSWORD=gatus networks: - 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 -dERROR: 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 web8a7841b0c8cfacc29f0253872fa5a40918c4c0be2d79ed682afe3e61c079ad25ubuntu@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秒检测一次。
不仅仅只有这两个参数,还有许多参数,可自行参考官方github文档即可。
storage: type: postgres path: "postgres://gatus:gatus@postgres:5432/gatus?sslmode=disable"endpoints: - name: ywbj.cc group: ywbj url: "https://ywbj.cc" interval: 60s conditions: - "[STATUS] == 200" - "[RESPONSE_TIME] < 500"
创建完成后,gatus为up正常状态,浏览器打开IP本机地址。可正常观看
四:监控多个网站,并设置报警媒介
支持多种实时报警方式,具体可查阅官方官方github:https://github.com/TwiN/gatus
本人常用telegram作为报警媒介,设置如下,将telegram的token和id填入即可。
storage: type: postgres path: "postgres://gatus:gatus@postgres:5432/gatus?sslmode=disable"alerting: telegram: token: "524123771617:AAHSLuaM3GndmYg1Jf1iBed0St0O7RBYigo" id: "-72563123001"endpoints: - name: ywbj.cc group: ywbj url: "https://ywbj.cc" interval: 60s conditions: - "[STATUS] == 200" - "[RESPONSE_TIME] < 500" alerts: - type: telegram enabled: true send-on-resolved: true - name: chinkh.com group: chinkh url: "http://chinkh.com" interval: 60s conditions: - "[STATUS] == 200" - "[RESPONSE_TIME] < 500" alerts: - type: telegram enabled: true send-on-resolved: true
保存退出,刷新页面
当检测网站状态不是200的正常值,或者响应速度在500毫秒以上,就会报警发送至telegram。
显示如下:
到这里,gatus网站监控设置完成。
版权声明:内容来源于互联网和用户投稿 如有侵权请联系删除