数据采集 采集源配置 go运行时指标采集
go运行时指标采集
简介
该采集器针对go语言实现的项目,进行指标采集,根据业务或需求,实现prometheus exporter,datakit 通过暴露的监控接口,进行指标采集
前置条件
- 在项目中引入
promhttp
包,实现prometheus exporter 参考如下示例
示例
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
http.Handle("/metrics", promhttp.Handler())
panic(http.ListenAndServe(":9090", nil))
}
- 已安装 DataKit(DataKit 安装文档)
配置
进入 DataKit 安装目录下的 conf.d/golang 目录,复制 goruntime.conf.sample 并命名为 goruntime.conf。示例如下:
[[inputs.prom]]
# Goruntime metrics from http(https)://HOST:PORT/metrics
# usually modify host and port
# required
url = "http://127.0.0.1:9090/metrics"
# valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h"
# required
interval = "10s"
## Optional TLS Config
tls_open = false
# tls_ca = "/tmp/ca.crt"
# tls_cert = "/tmp/peer.crt"
# tls_key = "/tmp/peer.key"
## Internal configuration. Don't modify.
name = "goruntime"
## ignore_measurement = []
# [inputs.prom.tags]
# from = "127.0.0.1:9090"
# tags1 = "value1"
说明:
- 如果 指标 接口需要使用 HTTPS 访问,需要在配置文件中将
tls_open
设置为true
,且配置3个证书和私钥文件路径 - 使用命令例如
curl 127.0.0.1:9090/metrics
根据返回内容判断是否需要使用 HTTPS - 使用命令例如
curl --cacert ca.crt --cert peer.crt --key peer.key -L https://127.0.0.1:9090/metrics
验证 tls 证书和私钥是否可用 - 证书和私钥码只支持 PEM 编码
- 以上示例代码提供了一种监控数据采集的思路,可以根据自己的业务,针对监控的指标进行扩展开发
采集指标
- goruntime 指标集
指标 | 类型 | 单位 |
---|---|---|
go_gc_duration_seconds_count | fields | float |
go_gc_duration_seconds_sum | fields | float |
go_goroutines | fields | float |
go_memstats_alloc_bytes | fields | float |
go_memstats_alloc_bytes_total | fields | float |
go_memstats_buck_hash_sys_bytes | fields | float |
go_memstats_frees_total | fields | float |
go_memstats_gc_cpu_fraction | fields | float |
go_memstats_gc_sys_bytes | fields | float |
go_memstats_heap_alloc_bytes | fields | float |
go_memstats_heap_idle_bytes | fields | float |
go_memstats_heap_inuse_bytes | fields | float |
go_memstats_heap_objects | fields | float |
go_memstats_heap_released_bytes | fields | float |
go_memstats_heap_sys_bytes | fields | float |
go_memstats_last_gc_time_seconds | fields | float |
go_memstats_lookups_total | fields | float |
go_memstats_mallocs_total | fields | float |
go_memstats_mcache_inuse_bytes | fields | float |
go_memstats_mcache_sys_bytes | fields | float |
go_memstats_mspan_inuse_bytes | fields | float |
go_memstats_mspan_sys_bytes | fields | float |
go_memstats_next_gc_bytes | fields | float |
go_memstats_other_sys_bytes | fields | float |
go_memstats_stack_inuse_bytes | fields | float |
go_memstats_stack_sys_bytes | fields | float |
go_memstats_sys_bytes | fields | float |
go_threads | fields | float |
promhttp_metric_handler_requests_in_flight | fields | float |
- goruntime_go_info 指标集
指标 | 类型 | 单位 |
---|---|---|
version | tags | string |
go_info | fields | float |
- goruntime_promhttp_metric 指标集
指标 | 类型 | 单位 |
---|---|---|
code | tags | string |
promhttp_metric_handler_requests_total | fields | float |