V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Lpl
V2EX  ›  Go 编程语言

gin web 框架的监控指标

  •  
  •   Lpl ·
    penglongli · 2020-09-23 20:35:01 +08:00 · 1657 次点击
    这是一个创建于 1311 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近写了一个 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 条回复    2020-09-24 10:39:45 +08:00
    richzhu
        1
    richzhu  
       2020-09-24 10:39:45 +08:00
    正好需要,start 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2965 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 13:29 · PVG 21:29 · LAX 06:29 · JFK 09:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.