使用状态文件+vigil 监控系统状态

vigil 是一个不错的系统可用性报告系统,具有还不错的ui 界面,同时也有通知配置,以下是一个简单的
demo 使用状态文件,以及http body 匹配的模式进行web 应用状态的监控,只是简单的demo,状态的
会写可能是其他任务操作的,这个只是演示一种可行的方法

环境准备

  • docker-compose 文件
version: "3"
services: 
  app:
    image: valeriansaliou/vigil:v1.9.0
    volumes: 
    - "./config.cfg:/etc/vigil.cfg"
    ports: 
    - "9090:9090"
  web:
    image: openresty/openresty:alpine-fat
    volumes: 
    - "./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf"
    - "./53c2e115-da65-47fd-8e6c-13bb95d3f2c6:/opt/53c2e115-da65-47fd-8e6c-13bb95d3f2c6"
    ports: 
    - "8080:8080"
  • config.cfg 配置
    使用基于http body 匹配的模式,进行状态检测
# Vigil
# Microservices Status Page
# Configuration file
# Example: https://github.com/valeriansaliou/vigil/blob/master/config.cfg


[server]

log_level = "error"
inet = "0.0.0.0:9090"
workers = 4
reporter_token = "appkey"

[assets]

path = "./res/assets/"

[branding]

page_title = "服务监控状态"
page_url = "https://www.badi.com/"
company_name = "demo"
icon_color = "#3C82E7"
icon_url = "https://help.sonatype.com/repomanager3/_/7F0000010161B31F409A4915783C449A/1555428150908/assets/img/SON_logo_main_small@2x.png"
logo_color = "#3C82E7"
logo_url = "https://help.sonatype.com/repomanager3/_/7F0000010161B31F409A4915783C449A/1555428150908/assets/img/SON_logo_main_small@2x.png"
website_url = "https://www.badi.com"
support_url = "mailto:1141591465@qq.com"
custom_html = ""

[metrics]

poll_interval = 20
poll_retry = 2

poll_http_status_healthy_above = 200
poll_http_status_healthy_below = 400

poll_delay_dead = 20
poll_delay_sick = 10

push_delay_dead = 20

push_system_cpu_sick_above = 0.90
push_system_ram_sick_above = 0.90

[notify]
reminder_interval = 300

[notify.email]

from = "notify-email@email.com"
to = "to email user"
smtp_host = "smtp server"
smtp_port = 587
smtp_username = "emailaccount"
smtp_password = "accountpassword"
smtp_encrypt = true

[probe]

[[probe.service]]

id = "nginx_web"
label = "nginx_web"

[[probe.service.node]]

id = "nginx_web"
label = "nginx_web"
mode = "poll"
replicas = ["http://web:8080/53c2e115-da65-47fd-8e6c-13bb95d3f2c6"]
http_body_healthy_match ="ok"

原理说明

检测任务回写状态信息到53c2e115-da65-47fd-8e6c-13bb95d3f2c6 文件,vigil 通过http_body_healthy_match 进行
状体识别,是了方便nginx 使用了精准匹配

  • nginx 配置文件
worker_processes 1;
user root;
events {
    worker_connections 1024;
}
http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    gzip on;
    gzip_min_length 2k;
    gzip_buffers 4 16k;
    gzip_comp_level 4;
    gzip_types text/plain text/css image/png application/javascript image/jpeg image/gif;
    server {
        listen 8080;
        ## 修改为实际的主机信息
        server_name localhost; 
        charset utf-8;
        default_type text/html;
        root html;
        location / {
          index index.html index.htm;
        }
        location =/53c2e115-da65-47fd-8e6c-13bb95d3f2c6 {
            root /opt;
            default_type text/plain;
        }
    }
}

启动&&测试

  • 启动
docker-compose up -d
  • 效果

    修改状态文件,模式故障
    修改53c2e115-da65-47fd-8e6c-13bb95d3f2c6 内容为error

说明

这个简单demo 只是演示一种可行的基于http body 匹配以及状态文件检测的方法进行系统监控的方法,实际还需要自己编写一个状体
检查的脚本

参考资料

https://crates.io/crates/vigil-server
https://github.com/rongfengliang/vigil-http-body-match-probe-demo

posted on   荣锋亮  阅读(323)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2018-04-30 ambassador kubernetes native api gateway
2015-04-30 morris.js 简单学习
2015-04-30 查看 activex 组件的方法
2014-04-30 SQL Server用户自定义函数
2014-04-30 ORACLE配置tnsnames.ora文件实例
2014-04-30 转 AngularJS 2.0将面向移动应用并放弃旧浏览器
2014-04-30 Oracle connect resource权限

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示