Skip to content

Commit 771c8c7

Browse files
authored
doc: improve metrics doc (#382)
* improve metrics doc * use image instead * use image instead
1 parent 4b0f55c commit 771c8c7

File tree

2 files changed

+108
-76
lines changed

2 files changed

+108
-76
lines changed

configs/runtime_config.json

+79-73
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,81 @@
11
{
2-
"servers":[
3-
{
4-
"default_log_path":"stdout",
5-
"default_log_level": "INFO",
6-
"listeners":[
7-
{
8-
"name":"grpc",
9-
"address": "0.0.0.0:34904",
10-
"bind_port": true,
11-
"filter_chains": [{
12-
"filters": [
13-
{
14-
"type": "grpc",
15-
"config": {
16-
"server_name":"runtime",
17-
"grpc_config": {
18-
"hellos": {
19-
"helloworld": {
20-
"hello": "greeting"
21-
}
22-
},
23-
"config_stores": {
24-
"etcd": {
25-
"address": ["127.0.0.1:2379"],
26-
"timeout": "10"
27-
}
28-
}
29-
}
30-
}
31-
}
32-
]
33-
}],
34-
"stream_filters": [
35-
{
36-
"type": "flowControlFilter",
37-
"config": {
38-
"global_switch": true,
39-
"limit_key_type": "PATH",
40-
"rules": [
41-
{
42-
"resource": "/spec.proto.runtime.v1.Runtime/SayHello",
43-
"grade": 1,
44-
"threshold": 5
45-
}
46-
]
47-
}
48-
},
49-
{
50-
"type": "grpc_metric"
51-
}
52-
]
53-
}
54-
]
55-
}
56-
],
57-
"tracing": {
58-
"enable": true,
59-
"driver": "SOFATracer",
60-
"config": {
61-
"generator": "mosntracing",
62-
"exporter": ["stdout"]
63-
}
64-
},
65-
"metrics": {
66-
"sinks": [
67-
{
68-
"type": "prometheus",
69-
"config": {
70-
"port": 34903
71-
}
72-
}
73-
]
74-
}
2+
"servers": [
3+
{
4+
"default_log_path": "stdout",
5+
"default_log_level": "INFO",
6+
"listeners": [
7+
{
8+
"name": "grpc",
9+
"address": "0.0.0.0:34904",
10+
"bind_port": true,
11+
"filter_chains": [
12+
{
13+
"filters": [
14+
{
15+
"type": "grpc",
16+
"config": {
17+
"server_name": "runtime",
18+
"grpc_config": {
19+
"hellos": {
20+
"helloworld": {
21+
"hello": "greeting"
22+
}
23+
},
24+
"config_stores": {
25+
"etcd": {
26+
"address": [
27+
"127.0.0.1:2379"
28+
],
29+
"timeout": "10"
30+
}
31+
}
32+
}
33+
}
34+
}
35+
]
36+
}
37+
],
38+
"stream_filters": [
39+
{
40+
"type": "flowControlFilter",
41+
"config": {
42+
"global_switch": true,
43+
"limit_key_type": "PATH",
44+
"rules": [
45+
{
46+
"resource": "/spec.proto.runtime.v1.Runtime/SayHello",
47+
"grade": 1,
48+
"threshold": 5
49+
}
50+
]
51+
}
52+
},
53+
{
54+
"type": "grpc_metric"
55+
}
56+
]
57+
}
58+
]
59+
}
60+
],
61+
"tracing": {
62+
"enable": true,
63+
"driver": "SOFATracer",
64+
"config": {
65+
"generator": "mosntracing",
66+
"exporter": [
67+
"stdout"
68+
]
69+
}
70+
},
71+
"metrics": {
72+
"sinks": [
73+
{
74+
"type": "prometheus",
75+
"config": {
76+
"port": 34903
77+
}
78+
}
79+
]
80+
}
7581
}

docs/zh/start/trace/trace.md

+29-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ Layotto中的tracing主要是对grpc调用进行记录,依赖于在grpc里添
138138
拦截器在每次grpc方法调用时都会开启一次tracing,生成traceId spanId、新的context,记录方法名、时间,并且会将tracing信息通过context透传下去,方法返回时将span信息导出。
139139

140140

141-
### Metric管理
141+
### Metrics管理
142142

143-
layotto的metric复用的mosn的metric,对接prometheus,[runtime_config.json](https://github.com/mosn/layotto/blob/main/configs/runtime_config.json) 中提供了metric配置的示例,按照上述步骤启动layotto后,可以通过以下指令读取metric信息:
143+
layotto的metrics复用的mosn的metrics,对接prometheus。
144+
145+
[runtime_config.json](https://github.com/mosn/layotto/blob/main/configs/runtime_config.json) 中提供了metric配置的示例,按照上述步骤启动layotto后,可以通过以下指令读取 metrics 信息:
144146

145147

146148
```shell
@@ -151,4 +153,28 @@ curl --location --request GET 'http://127.0.0.1:34903/metrics'
151153

152154
![img.png](../../../img/trace/metric.png)
153155

154-
mosn的metric原理可以参照[mosn官方文档](https://mosn.io/blog/code/mosn-log/)
156+
#### 配置解释
157+
解释一下[runtime_config.json](https://github.com/mosn/layotto/blob/main/configs/runtime_config.json) 里 metrics 相关配置
158+
##### 埋点、统计
159+
![](https://user-images.githubusercontent.com/26001097/151318373-632e93bc-108d-47ae-b401-6092ed66bcdc.png)
160+
图中标红的这段配置会启用mosn的"grpc_metric" filter。这个filter的作用是在每次处理完grpc请求后,统计服务名、成功还是失败等信息,存在内存中。
161+
162+
详见 [mosn代码](https://github.com/mosn/mosn/blob/70751eae7a13dd1b3ac84c31b1ba85c45945ef69/pkg/filter/stream/grpcmetric/metric.go#L54)
163+
164+
##### 展示metrics数据
165+
```json
166+
"metrics": {
167+
"sinks": [
168+
{
169+
"type": "prometheus",
170+
"config": {
171+
"port": 34903
172+
}
173+
}
174+
]
175+
}
176+
```
177+
这段其实也是mosn的配置,会打开34903端口,按 prometheus 的数据格式返回内存中的 metrics 指标。
178+
179+
#### 更多细节
180+
mosn的 metrics 原理可以参照 [mosn官方文档](https://mosn.io/blog/code/mosn-log/)

0 commit comments

Comments
 (0)