自定义监控 Go 服务器运行的各项操作耗时

2015-08-15 14:59:32 +08:00
 zhengji

github地址: https://github.com/zheng-ji/gosvr-monitor

在线上每秒170多次请求的项目中投入使用,希望也能帮到大家

编译和运行

go get github.com/zheng-ji/gosvr-monitor

How To Use

import (
    "github.com/zheng-ji/gosvr-monitor"
)
func fun_test() {
    timeStart := time.Now()
    defer func() {
        //defer 的时候统计监控, 用goroutine 使得不影响性能
        go monitor.StatByAction("WRITE", timeStart)
    }()
    ....
}

func main() {
    //初始化monitor, 自定义监控的命令,如READ,WRITE, 以及每次统计的法值
    // 启动监控服务
    monitor.InitMonitor([]string{"WRITE", "READ"}, 1)
    monitor.StartMonitorServer("0.0.0.0:7070")
    fun_test
    ...
}

Output

curl "http://127.0.0.1:7070/info"
WRITE (ms):500.000000
READ (ms):300.000000
3008 次点击
所在节点    分享创造
3 条回复
Comdex
2015-08-15 15:28:21 +08:00
同时自自荐一个自己的golang图像处理工具库 https://github.com/Comdex/imgo
Comdex
2015-08-15 15:28:42 +08:00
golang爱好者多多交流哈
scys
2015-08-15 18:10:21 +08:00
刚好正在用golang~多谢~

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

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

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

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

© 2021 V2EX