Linux开源软件Gatus - 自动化监控网站运行服务

一: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:
      - web

networks:
  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: 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网站监控设置完成。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值