提交 18da83b0 authored 作者: 陈泽健's avatar 陈泽健

feat(service): 添加Nginx/Nacos/FastDFS深度检测功能并优化EMQX监测

- 新增Nginx深度检测脚本,实现连接统计、进程监控、配置检查等功能
- 新增Nacos深度检测脚本,实现服务实例统计、健康状态、Raft集群检测
- 新增FastDFS深度检测脚本,实现存储状态、同步状态、文件统计检测
- 优化EMQX最大连接数检测逻辑,修正集群模式识别算法
- 更新PowerShell主脚本,添加新的检测模块映射和结果显示配置
- 扩展系统阈值配置,为新增服务添加相应的告警规则定义
上级 658711d3
...@@ -349,9 +349,9 @@ function Get-ModuleCategory { ...@@ -349,9 +349,9 @@ function Get-ModuleCategory {
"^2[67]_" { return "EMQX消息队列" } "^2[67]_" { return "EMQX消息队列" }
"^28_" { return "Java应用" } "^28_" { return "Java应用" }
"^29_" { return "Python应用" } "^29_" { return "Python应用" }
"^30_" { return "Nginx应用" } "^3[04]_" { return "Nginx应用" }
"^31_" { return "Nacos应用" } "^3[15]_" { return "Nacos应用" }
"^32_" { return "FastDFS应用" } "^3[26]_" { return "FastDFS应用" }
"^33_" { return "应用日志" } "^33_" { return "应用日志" }
"^40_" { return "综合诊断" } "^40_" { return "综合诊断" }
default { return "其他" } default { return "其他" }
...@@ -488,6 +488,69 @@ function Get-DisplayName { ...@@ -488,6 +488,69 @@ function Get-DisplayName {
"PYTHON_VERSION" = "Python版本" "PYTHON_VERSION" = "Python版本"
"NGINX_VERSION" = "Nginx版本" "NGINX_VERSION" = "Nginx版本"
"NACOS_VERSION" = "Nacos版本" "NACOS_VERSION" = "Nacos版本"
# Nginx深度检测
"NGINX_ACTIVE_CONNECTIONS" = "Nginx活跃连接数"
"NGINX_ACCEPTED_CONNECTIONS" = "Nginx已接受连接数"
"NGINX_HANDLED_CONNECTIONS" = "Nginx已处理连接数"
"NGINX_REQUESTS_TOTAL" = "Nginx总请求数"
"NGINX_PROCESSES" = "Nginx进程数"
"NGINX_LISTENING_PORTS" = "Nginx监听端口"
"NGINX_CONFIG_STATUS" = "Nginx配置状态"
"NGINX_CONFIG_LEVEL" = "Nginx配置等级"
"NGINX_WORKER_PROCESSES" = "Nginx工作进程数"
"NGINX_WORKER_CONNECTIONS" = "Nginx工作连接数"
"NGINX_ACCESS_LOG_SIZE" = "Nginx访问日志大小"
"NGINX_ERROR_LOG_SIZE" = "Nginx错误日志大小"
"NGINX_RECENT_ERRORS" = "Nginx最近错误数"
"NGINX_SSL_ENABLED" = "Nginx SSL启用"
"NGINX_CACHE_ENABLED" = "Nginx缓存启用"
"NGINX_UPSTREAM_COUNT" = "Nginx上游数量"
"NGINX_SERVER_BLOCKS" = "Nginx服务器块数量"
"NGINX_UPTIME_DAYS" = "Nginx运行天数"
# Nacos深度检测
"NACOS_NAMESPACES" = "Nacos命名空间数"
"NACOS_SERVICES_COUNT" = "Nacos服务数量"
"NACOS_INSTANCES_COUNT" = "Nacos实例数量"
"NACOS_HEALTHY_INSTANCES" = "Nacos健康实例数"
"NACOS_HEALTH_RATE" = "Nacos健康率"
"NACOS_CONFIGS_COUNT" = "Nacos配置数量"
"NACOS_GRPC_CONNECTIONS" = "Nacos gRPC连接数"
"NACOS_RAFT_MODE" = "Nacos Raft模式"
"NACOS_RAFT_ROLE" = "Nacos Raft角色"
"NACOS_RAFT_NODES" = "Nacos Raft节点数"
"NACOS_HEALTH_STATUS" = "Nacos健康状态"
"NACOS_HEALTH_LEVEL" = "Nacos健康等级"
"NACOS_HEAP_USAGE" = "Nacos堆内存使用率"
"NACOS_THREAD_COUNT" = "Nacos线程数"
"NACOS_MAIN_PORT" = "Nacos主端口状态"
"NACOS_RAFT_PORT" = "Nacos Raft端口状态"
"NACOS_LOG_SIZE" = "Nacos日志大小"
"NACOS_RECENT_ERRORS" = "Nacos最近错误数"
"NACOS_UPTIME_DAYS" = "Nacos运行天数"
# FastDFS深度检测
"FASTDFS_VERSION" = "FastDFS版本"
"FASTDFS_TRACKER_STATUS" = "FastDFS Tracker状态"
"FASTDFS_TRACKER_PROCESSES" = "FastDFS Tracker进程数"
"FASTDFS_STORAGE_STATUS" = "FastDFS Storage状态"
"FASTDFS_STORAGE_PROCESSES" = "FastDFS Storage进程数"
"FASTDFS_STORE_PATH_COUNT" = "FastDFS存储路径数"
"FASTDFS_DISK_USAGE" = "FastDFS磁盘使用率"
"FASTDFS_SYNC_ENABLED" = "FastDFS同步启用"
"FASTDFS_FILE_COUNT" = "FastDFS文件数量"
"FASTDFS_DIR_COUNT" = "FastDFS目录数量"
"FASTDFS_TOTAL_SIZE" = "FastFS总大小"
"FASTDFS_TRUNK_ENABLED" = "FastDFS Trunk启用"
"FASTDFS_TRACKER_CONNECTION" = "FastDFS Tracker连接状态"
"FASTDFS_LOG_SIZE" = "FastDFS日志大小"
"FASTDFS_RECENT_ERRORS" = "FastDFS最近错误数"
"FASTDFS_HTTP_ENABLED" = "FastDFS HTTP启用"
"FASTDFS_HTTP_PORT" = "FastDFS HTTP端口"
"FASTDFS_HTTP_STATUS" = "FastDFS HTTP状态"
"FASTDFS_STORAGE_UPTIME_DAYS" = "FastDFS Storage运行天数"
"FASTDFS_GROUP_NAME" = "FastDFS组名"
} }
if ($displayNames.ContainsKey($Key)) { if ($displayNames.ContainsKey($Key)) {
...@@ -722,6 +785,26 @@ function Get-Threshold { ...@@ -722,6 +785,26 @@ function Get-Threshold {
# ==================== 证书检测阈值 ==================== # ==================== 证书检测阈值 ====================
"SSL_CERT_DAYS_LEFT" = "<30天" "SSL_CERT_DAYS_LEFT" = "<30天"
"EMQX_CERT_DAYS_LEFT" = "<30天" "EMQX_CERT_DAYS_LEFT" = "<30天"
# ==================== Nginx应用阈值 ====================
"NGINX_ACTIVE_CONNECTIONS" = ">1000"
"NGINX_CONFIG_LEVEL" = "严重"
"NGINX_RECENT_ERRORS" = ">10"
"NGINX_HEAP_USAGE" = ">80%"
# ==================== Nacos应用阈值 ====================
"NACOS_HEALTH_RATE" = "<90%"
"NACOS_HEALTH_LEVEL" = "严重"
"NACOS_HEAP_USAGE" = ">80%"
"NACOS_RECENT_ERRORS" = ">20"
"NACOS_THREAD_COUNT" = ">500"
# ==================== FastDFS应用阈值 ====================
"FASTDFS_DISK_USAGE" = ">80%"
"FASTDFS_TRACKER_CONNECTION" = "INACTIVE"
"FASTDFS_RECENT_ERRORS" = ">10"
"FASTDFS_FILE_COUNT" = ">100000"
"FASTDFS_HTTP_STATUS" = "0"
} }
if ($thresholds.ContainsKey($Key)) { if ($thresholds.ContainsKey($Key)) {
...@@ -841,8 +924,9 @@ function Invoke-AllChecks { ...@@ -841,8 +924,9 @@ function Invoke-AllChecks {
"20_docker_basic.sh", "21_docker_deep.sh", "22_mysql_basic.sh", "20_docker_basic.sh", "21_docker_deep.sh", "22_mysql_basic.sh",
"23_mysql_depth.sh", "24_redis_basic.sh", "25_redis_depth.sh", "23_mysql_depth.sh", "24_redis_basic.sh", "25_redis_depth.sh",
"26_emqx_basic.sh", "27_emqx_deep.sh", "28_java_check.sh", "26_emqx_basic.sh", "27_emqx_deep.sh", "28_java_check.sh",
"29_python_check.sh", "30_nginx_check.sh", "31_nacos_check.sh", "29_python_check.sh", "30_nginx_check.sh", "34_nginx_deep.sh",
"32_fastdfs_check.sh", "33_app_logs.sh" "31_nacos_check.sh", "35_nacos_deep.sh", "32_fastdfs_check.sh",
"36_fastdfs_deep.sh", "33_app_logs.sh"
) )
$totalModules = $systemModules.Count + $serviceModules.Count + $comprehensiveModules.Count $totalModules = $systemModules.Count + $serviceModules.Count + $comprehensiveModules.Count
......
...@@ -82,12 +82,17 @@ check_emqx_clients_detail() { ...@@ -82,12 +82,17 @@ check_emqx_clients_detail() {
output_result "EMQX_CLIENTS_DISCONNECTED" "$clients_disconnected" output_result "EMQX_CLIENTS_DISCONNECTED" "$clients_disconnected"
fi fi
# 检查最大连接数 # 获取最大客户端连接数配置
local max_clients local max_clients_config
max_clients=$(emqx_exec emqx_ctl listeners list 2>/dev/null | grep -c "running" || echo "0") max_clients_config=$(emqx_exec emqx_ctl listeners list 2>/dev/null | grep -E "max_connections" | awk '{print $NF}' | head -1)
if [ -n "$max_clients" ]; then if [ -z "$max_clients_config" ] || [ "$max_clients_config" = "0" ]; then
output_result "EMQX_MAX_CLIENTS" "$max_clients" # 如果无法获取配置,使用默认值infinity(或1024)
max_clients_config="infinity"
fi
if [ -n "$max_clients_config" ]; then
output_result "EMQX_MAX_CLIENTS" "$max_clients_config"
fi fi
} }
...@@ -202,24 +207,25 @@ check_emqx_cluster_detail() { ...@@ -202,24 +207,25 @@ check_emqx_cluster_detail() {
cluster_status=$(emqx_exec emqx_ctl cluster status 2>/dev/null) cluster_status=$(emqx_exec emqx_ctl cluster status 2>/dev/null)
if [ -n "$cluster_status" ]; then if [ -n "$cluster_status" ]; then
# 检查是否为集群模式 # 检查是否为集群模式(查找停止的节点或运行中的节点)
local is_cluster local is_running_cluster
is_cluster=$(echo "$cluster_status" | grep -c "Cluster" || echo "0") is_running_cluster=$(echo "$cluster_status" | grep -c "is running" || echo "0")
local is_stopped_cluster
if [ "$is_cluster" -gt 0 ]; then is_stopped_cluster=$(echo "$cluster_status" | grep -c "is stopped" || echo "0")
local total_nodes=$((is_running_cluster + is_stopped_cluster))
if [ "$total_nodes" -gt 1 ]; then
output_result "EMQX_CLUSTER_MODE" "是" output_result "EMQX_CLUSTER_MODE" "是"
output_result "EMQX_CLUSTER_NODES" "$total_nodes"
# 获取集群节点数量
local node_count
node_count=$(echo "$cluster_status" | grep -c "Node" || echo "0")
if [ -n "$node_count" ]; then
output_result "EMQX_CLUSTER_NODES" "$node_count"
fi
else else
output_result "EMQX_CLUSTER_MODE" "否" # 单节点模式
output_result "EMQX_CLUSTER_MODE" "否(单节点)"
output_result "EMQX_CLUSTER_NODES" "1" output_result "EMQX_CLUSTER_NODES" "1"
fi fi
else
# 无法获取集群状态,默认为单节点
output_result "EMQX_CLUSTER_MODE" "否(单节点)"
output_result "EMQX_CLUSTER_NODES" "1"
fi fi
} }
......
...@@ -251,6 +251,7 @@ calculate_change() { ...@@ -251,6 +251,7 @@ calculate_change() {
trend = "持平" trend = "持平"
if (type == "percent") { if (type == "percent") {
# 百分比类型:直接显示变化值
abs_change = (change < 0 ? -change : change) abs_change = (change < 0 ? -change : change)
if (abs_change > 5) { if (abs_change > 5) {
if (change > 0) { if (change > 0) {
...@@ -261,12 +262,22 @@ calculate_change() { ...@@ -261,12 +262,22 @@ calculate_change() {
} }
printf "%.1f%%|%s", change, trend printf "%.1f%%|%s", change, trend
} else { } else {
if (change > 0) { # 计数类型:计算相对变化的百分比
trend = "🔴 增加" if (last != 0) {
} else if (change < 0) { percent_change = (change / last) * 100
trend = "🟢 减少" } else {
percent_change = 0
} }
printf "%.0f%%|%s", change, trend
abs_percent = (percent_change < 0 ? -percent_change : percent_change)
if (abs_percent > 5) {
if (change > 0) {
trend = "🔴 增加"
} else if (change < 0) {
trend = "🟢 减少"
}
}
printf "%.1f%%|%s", percent_change, trend
} }
}') }')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论