在Debian系統上監控Swagger服務可以通過以下幾種方法進行:
檢查服務狀態:
sudo systemctl status swagger.service
如果服務未運行,可以使用以下命令啟動它:
sudo systemctl start swagger.service
設置監控和警報:
編輯Swagger服務的systemd配置文件(通常位于 /etc/systemd/system/swagger.service
),添加以下內容:
[Service]
ExecStart=/usr/bin/swagger
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
[WatchdogSec=30s]
這將設置服務在停止后5秒內自動重啟,并且每30秒檢查一次服務狀態。
sudo apt install prometheus grafana
/etc/prometheus/prometheus.yml
),添加Swagger服務的抓取配置。sudo systemctl start prometheus
sudo systemctl enable prometheus
sudo systemctl start grafana-servers
sudo systemctl enable grafana-server
sudo apt-get install dstat
dstat -c -d -m -n
sudo apt-get install glances
glances
sudo apt-get install cadvisor
dotnet add package MiniProfiler.AspNetCore.Mvc
dotnet add package Swashbuckle.AspNetCore
Startup.cs
的 ConfigureServices
方法中添加MiniProfiler服務配置,并在 Configure
方法中啟用MiniProfiler中間件。Startup.cs
中的 UseSwaggerUI
中間件配置。通過以上方法,你可以在Debian系統上有效地監控Swagger服務的狀態和性能,并在服務出現問題時及時收到警報。