使用狀態文件+vigil 監控系統狀態

使用狀態文件+vigil 監控系統狀態

vigil 是一個不錯的系統可用性報告系統,具備還不錯的ui 界面,同時也有通知配置,如下是一個簡單的
demo 使用狀態文件,以及http body 匹配的模式進行web 應用狀態的監控,只是簡單的demo,狀態的
會寫多是其餘任務操做的,這個只是演示一種可行的方法javascript

環境準備

  • 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 使用了精準匹配css

  • 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
  • 效果
    watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=
    修改狀態文件,模式故障
    修改53c2e115-da65-47fd-8e6c-13bb95d3f2c6 內容爲error
    watermark,size_14,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=

說明

這個簡單demo 只是演示一種可行的基於http body 匹配以及狀態文件檢測的方法進行系統監控的方法,實際還須要本身編寫一個狀體
檢查的腳本html

參考資料

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

相關文章
相關標籤/搜索