在Debian系统中监控Golang应用可从进程监控、日志监控、性能监控三方面入手,具体方法如下:
top/htop
查看CPU/内存占用,ps aux | grep go
过滤Golang进程,pgrep -af go
获取进程ID及命令行。systemctl status your-service-name
查看状态,journalctl -u your-service-name -f
实时查看日志。ss -tuln | grep go
查看网络连接,lsof -p <PID>
查看进程打开的文件及端口。tail -f /path/to/logfile.log
实时跟踪。StandardOutput=syslog
,通过journalctl
查看结构化日志。net/http/pprof
,通过http://localhost:6060/debug/pprof/
访问,生成CPU/内存火焰图。prometheus/client_golang
),暴露指标端点(如/metrics
),结合Grafana可视化。根据需求选择工具:轻量级场景可用top+journalctl+pprof
,复杂系统建议结合Prometheus+Grafana+Loki/ELK。