使用状态文件+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