Skip to content

Commit d682eff

Browse files
committed
fix: add the doc and fix util runtime bug
1 parent 055ada2 commit d682eff

File tree

2 files changed

+82
-7
lines changed

2 files changed

+82
-7
lines changed

gmicro/core/metric/doc.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package metric
2+
3+
/*
4+
监控
5+
1. 业务监控(上层概念 - 领导层):
6+
需求方:老板、运营
7+
开发方: 大数据库 ,都会访问业务库,大数据库会从同步库, 宽表
8+
QPS、DAU日活、访问状态(http code)、业务接口(登录、注册、聊天、上传、留言、搜索、投诉)、 产品转换率、充值额度
9+
2. 系统监控
10+
需求方: 运维
11+
开发方: 运维
12+
操作系统相关: cpu使用率、内存使用、磁盘使用率、磁盘空间(非常常见)、TCP(上W的链接),流量
13+
组件: mysql、redis、kafka
14+
15+
3. 日志监控
16+
需求方:运维、开发
17+
开发方:开发
18+
两种日志:业务日志(大数据, 普通日志)、 系统日志(操作系统日志、mysql组件日志、kakfa的日志)
19+
监控中的重头戏,一般我们都会对单独针对日志设计日志管理系统, ELK日志系统, loki
20+
21+
4. 网络监控:
22+
需求方:机房管理
23+
开放方:服务器管理
24+
IDC 交换机、路由器、防火墙、负载均衡、服务器、机柜、电源、UPS、空调、网络设备、机房环境监控,
25+
网络:内部网络(物理内网,虚拟内网(VPN))监控
26+
27+
5. 程序监控:
28+
需求方:开发
29+
开发方:开发
30+
比如产生了 500 ErrUserNotFound
31+
一般要运维和开发人员配合,开发人员在程序中提供监控接口,运维人员通过接口获取监控数据
32+
33+
prometheus的数据格式: metrics
34+
metrics是一种对采样数据的总称
35+
36+
guages
37+
最简单的度量指标,只是一个简单的返回值,或者叫瞬时状态,我们想要知道一个队列中的个数
38+
比如:当前的内存使用率、当前的CPU使用率、当前的磁盘使用率、当前的磁盘空间、当前的TCP连接数、当前的流量、当前的QPS、当前的DAU、当前的访问状态、当前的业务接口、当前的产品转换率、当前的充值额度、当前的业务日志、当前的系统日志、当前的网络设备、当前的服务器、当前的机柜、当前的电源、当前的UPS、当前的空调、当前的网络设备、当前的机房环境监控、当前的程序监控
39+
随着时间的推移, 这个值是不断变化的, 这个值有可能增加,有可能减少
40+
41+
Counter
42+
是计数器, 这个值是从0开始累积,在理想状态下,这个值不可能减少
43+
在理想状态下:如果我的服务器重启,同时这个数是放在内存中的
44+
45+
guages和counter是最主要的类型 70%
46+
47+
Histograms
48+
http_res_time 表示http请求的响应时间
49+
nginx
50+
51+
如果我要统计一天的所有访问的平均耗时
52+
如果我们统计下来平均耗时是50ms 但是, 现在中午有一段时间系统卡住了, 1W个请求 平均耗时是在5s,
53+
但是由于我们每天的访问量很大, 1000W访问量,这个5s耗时的请求就被平均掉了
54+
越早发现越好, 有可能是程序的bug,也有可能是系统的bug
55+
56+
50ms以内有多少请求, 50-200ms有多少请求 200ms-500ms有多少请求 500ms-1s有多少请求 1s-5s有多少请求 5s以上有多少请求
57+
分布式图
58+
59+
60+
*/

pkg/common/util/runtime/runtime.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package runtime
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"net/http"
2223
"runtime"
@@ -85,15 +86,29 @@ func logPanic(r interface{}) {
8586
// should be packaged up into a testable and reusable object.
8687
var ErrorHandlers = []func(error){
8788
logError,
88-
(&rudimentaryErrorBackoff{
89-
lastErrorTime: time.Now(),
90-
// 1ms was the number folks were able to stomach as a global rate limit.
91-
// If you need to log errors more than 1000 times a second you
92-
// should probably consider fixing your code instead. :)
93-
minPeriod: time.Millisecond,
94-
}).OnError,
89+
func(err error) {
90+
(&rudimentaryErrorBackoff{
91+
lastErrorTime: time.Now(),
92+
// 1ms was the number folks were able to stomach as a global rate limit.
93+
// If you need to log errors more than 1000 times a second you
94+
// should probably consider fixing your code instead. :)
95+
minPeriod: time.Millisecond,
96+
}).OnError(errors.New("error occurred ErrorHandlers"))
97+
},
9598
}
9699

100+
//备用:
101+
//var ErrorHandlers = []func(error){
102+
// logError,
103+
// (&rudimentaryErrorBackoff{
104+
// lastErrorTime: time.Now(),
105+
// // 1ms was the number folks were able to stomach as a global rate limit.
106+
// // If you need to log errors more than 1000 times a second you
107+
// // should probably consider fixing your code instead. :)
108+
// minPeriod: time.Millisecond,
109+
// }).OnError,
110+
//}
111+
97112
// HandlerError is a method to invoke when a non-user facing piece of code cannot
98113
// return an error and needs to indicate it has been ignored. Invoking this method
99114
// is preferable to logging the error - the default behavior is to log but the

0 commit comments

Comments
 (0)