gin web 框架的监控指标
資深大佬 : Lpl 0
最近写了一个 metric exporter,基于 gin web 框架。抽出来了几个使用 gin 的时候可能会用到的监控指标:
| Metric | Type | Description | | ----------------------- | --------- | ------------------------------ | | gin_request_total | Counter | 服务接收到的请求总数 | | gin_request_uv | Counter | 服务接收到的 IP 总数 | | gin_uri_request_total | Counter | 每个 URI 接收到的服务请求数 | | gin_request_body_total | Counter | 服务接收到的请求量,单位: 字节 | | gin_response_body_total | Counter | 服务返回的请求量,单位: 字节 | | gin_request_duration | Histogram | 服务处理请求使用的时间 | | gin_slow_request_total | Counter | 服务接收到的慢请求计数 |
同时也支持在应用中自定义监控指标
gaugeMetric := &ginmetrics.Metric{ Type: ginmetrics.Counter, Name: "example_gauge_metric", Description: "an example of gauge type metric", Labels: []string{"label1"}, } // 将自定义的 Metric 添加进全局对象 _ = ginmetrics.GetMonitor().AddMetric(gaugeMetric) // 设置自定义 Metric 的监控值 _ = ginmetrics.GetMonitor().GetMetric("example_gauge_metric"). SetGaugeValue([]string{"label_value1"}, 0.1)
如果使用上有问题,或者有什么 feature 建议,欢迎提出~
仓库地址:https://github.com/penglongli/gin-metrics
大佬有話說 (1)