gin web 框架的监控指标

2020-09-23 20:35:01 +08:00
 Lpl

最近写了一个 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

1661 次点击
所在节点    Go 编程语言
1 条回复
richzhu
2020-09-24 10:39:45 +08:00
正好需要,start 了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/709900

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX