Monitor
This chapter introduces Go-Sail's monitoring.
Introduction
For running application services, service monitoring is of critical importance; it renders the operational status of applications more transparent and clear, while also contributing significantly to performance optimization and—in a microservices environment—elastic scaling.
Currently, Go-Sail utilizes two approaches—Prometheus and PProf—to implement telemetry and observability.
Metrics
Go-Sail utilizes Prometheus to monitor various service metrics. You can collect this data via the metrics endpoint for subsequent use. The following metrics are currently being collected:
- HTTP Request Latency
- HTTP Status Code Counts
- CPU Utilization
- Memory Utilization
- Disk Utilization
- Network Traffic
Configuration
If you need to enable metric monitoring, configuration is required. We have excerpted the specific sections that need to be configured.
http_conf:
debug: false
addr: ""
swagger_conf:
enable: false
redoc_ui_path: ""
json_path: ""
favicon_path: ""
prometheus_conf:
enable: true
addr: ""
access_path: ""
disable_system_sample: false
disk_path: ""
sample_interval: ""
Collection
Once the configuration is complete, Go-Sail will enable Prometheus monitoring. However, please note that this monitoring does not actively push data; instead, it exposes an access_path for external access, allowing you to collect metrics using tools such as Grafana.
PProf
Configuration
PProf configuration is tied to the HTTP configuration; simply set the debug parameter within the HTTP configuration section to true.The access URL is /debug/pprof.
http_conf:
debug: true
addr: ""
swagger_conf:
enable: false
redoc_ui_path: ""
json_path: ""
favicon_path: ""
prometheus_conf:
enable: false
addr: ""
access_path: ""
disable_system_sample: false
disk_path: ""
sample_interval: ""
Usage
PProf supports viewing the following:
-
memory usage
/debug/pprof/heap -
CPU profiling
/debug/pprof/profile -
goroutine status
/debug/pprof/goroutine -
blocking analysis
/debug/pprof/block -
lock contention
/debug/pprof/mutex
You can use the go tool command to perform a detailed analysis. For example:
go tool pprof http://localhost:8080/debug/pprof/heap