侧边栏壁纸
博主头像
SeaDream乄造梦

Dream,Don't stop a day of hard and don't give up a little hope。 ——不停止一日努力&&不放弃一点希望。

  • 累计撰写 39 篇文章
  • 累计创建 20 个标签
  • 累计收到 13 条评论

目 录CONTENT

文章目录

go_zero之健康监测&&健康指标信息

SeaDream乄造梦
2023-07-19 / 2 评论 / 1 点赞 / 966 阅读 / 7,276 字
温馨提示:
亲爱的,如果觉得博主很有趣就留下你的足迹,并收藏下链接在走叭

go-zero短从需求到上线的距离,是一个集成了各种工程实践的 web 和 rpc 框架。通过弹性设计保障了大并发服务端的稳定性,经受了充分的实战检验。
然而我们使用框架的时候,怎么才能知道我们启动的服务的健康状态和资源使用情况,当然框架给我们已经想好了解决方案。下面跟着me一起看看吧···


第一步:对应配置信息打开

Name: user-api
Host: 0.0.0.0
Port: 8002
......

DevServer:
  Enabled: true
  Port: 6470
  HealthPath: "/healthz"
#健康指标信息访问:http://ip:6470/metrics   健康监测访问:http://ip:6470/healthz

下面我们就可以直接使用了,让me给大家讲讲里面的内容叭

健康监测

打开浏览器访问http://ip:6470/healthz,可以看到浏览器回复ok。

健康指标信息

打开浏览器访问http://ip:6470/metrics,可以看到如下关于Prometheus监控系统的指标信息展示

# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0.0010216
go_gc_duration_seconds{quantile="1"} 0.0010216
go_gc_duration_seconds_sum 0.0010216 
go_gc_duration_seconds_count 4
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 24
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.20.6"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 7.167184e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 1.1871328e+07
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 1.4556e+06
# HELP go_memstats_frees_total Total number of frees.
# TYPE go_memstats_frees_total counter
go_memstats_frees_total 43378
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.
# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 7.84408e+06
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.
# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 7.167184e+06
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.
# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 6.627328e+06
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.
# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 9.527296e+06
# HELP go_memstats_heap_objects Number of allocated objects.
# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 30878
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS.
# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 6.127616e+06
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.
# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 1.6154624e+07
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.
# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 1.6897467896680956e+09
# HELP go_memstats_lookups_total Total number of pointer lookups.
# TYPE go_memstats_lookups_total counter
go_memstats_lookups_total 0
# HELP go_memstats_mallocs_total Total number of mallocs.
# TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 74256
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures.
# TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 14016
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system.
# TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 16352
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures.
# TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 178240
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system.
# TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 179520
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place.
# TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 1.0298032e+07
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations.
# TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 1.579064e+06
# HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator.
# TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 622592
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator.
# TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 622592
# HELP go_memstats_sys_bytes Number of bytes obtained from system.
# TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 2.7851832e+07
# HELP go_threads Number of OS threads created.
# TYPE go_threads gauge
go_threads 16
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.03125
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 1.6777216e+07
# HELP process_open_fds Number of open file descriptors.
# TYPE process_open_fds gauge
process_open_fds 176
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 3.5299328e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.689746668e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 3.3103872e+07
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.
# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 3
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0

解释

  1. go_gc_duration_seconds: 这是垃圾回收周期的暂停持续时间的摘要。它展示了垃圾回收在不同百分位数下的暂停时间。其中,quantile表示百分位数,取值为0、0.25、0.5、0.75和1,分别代表最小值、25分位数、中位数、75分位数和最大值。
  2. go_goroutines: 当前存在的goroutine数量。goroutine是Go语言并发编程的执行单元。
  3. go_info: 关于Go环境的信息。其中version字段表示Go的版本号。
  4. go_memstats_alloc_bytes: 已分配且仍在使用的字节数。
  5. go_memstats_alloc_bytes_total: 分配的总字节数,即使已被释放。
  6. go_memstats_buck_hash_sys_bytes: 用于分析桶哈希表的字节数。
  7. go_memstats_frees_total: 释放的总次数。
  8. go_memstats_gc_sys_bytes: 用于垃圾回收系统元数据的字节数。
  9. go_memstats_heap_alloc_bytes: 堆中已分配且仍在使用的字节数。
  10. go_memstats_heap_idle_bytes: 等待使用的堆字节数。
  11. go_memstats_heap_inuse_bytes: 正在使用的堆字节数。
  12. go_memstats_heap_objects: 已分配对象的数量。
  13. go_memstats_heap_released_bytes: 释放给操作系统的堆字节数。
  14. go_memstats_heap_sys_bytes: 从系统获取的堆字节数。
  15. go_memstats_last_gc_time_seconds: 自1970年以来上次垃圾回收的秒数。
  16. go_memstats_lookups_total: 指针查找的总次数。
  17. go_memstats_mallocs_total: 分配的总次数。
  18. go_memstats_mcache_inuse_bytes: mcache结构正在使用的字节数。
  19. go_memstats_mcache_sys_bytes: 从系统获取的用于mcache结构的字节数。
  20. go_memstats_mspan_inuse_bytes: mspan结构正在使用的字节数。
  21. go_memstats_mspan_sys_bytes: 从系统获取的用于mspan结构的字节数。
  22. go_memstats_next_gc_bytes: 下次垃圾回收时的堆字节数。
  23. go_memstats_other_sys_bytes: 用于其他系统分配的字节数。
  24. go_memstats_stack_inuse_bytes: 栈分配器正在使用的字节数。
  25. go_memstats_stack_sys_bytes: 从系统获取的用于栈分配器的字节数。
  26. go_memstats_sys_bytes: 从系统获取的总字节数。
  27. go_threads: 创建的操作系统线程数。
  28. process_cpu_seconds_total: 在用户和系统CPU上消耗的总时间,以秒为单位。
  29. process_max_fds: 最大打开文件描述符数。
  30. process_open_fds: 打开的文件描述符数。
  31. process_resident_memory_bytes: 占用物理内存的大小,以字节为单位。
  32. process_start_time_seconds: 进程自Unix纪元以来的启动时间,以秒为单位。
  33. process_virtual_memory_bytes: 虚拟内存大小,以字节为单位。
  34. promhttp_metric_handler_requests_in_flight: 当前正在提供的抓取数。
  35. promhttp_metric_handler_requests_total: 根据HTTP状态码的抓取总数。
1

评论区