Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add metrics module #220

Merged
merged 8 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import (
)

type Config struct {
DB DbConfig `toml:"db"`
JWT JWTConfig `toml:"jwt"`
Log LogConfig `toml:"log"`
API APIConfig `toml:"api"`
Node NodeConfig `toml:"node"`
MessageService MessageServiceConfig `toml:"messageService"`
MessageState MessageStateConfig `toml:"messageState"`
Gateway GatewayConfig `toml:"gateway"`
RateLimit RateLimitConfig `toml:"rateLimit"`
Trace metrics.TraceConfig `toml:"tracing"`
DB DbConfig `toml:"db"`
JWT JWTConfig `toml:"jwt"`
Log LogConfig `toml:"log"`
API APIConfig `toml:"api"`
Node NodeConfig `toml:"node"`
MessageService MessageServiceConfig `toml:"messageService"`
MessageState MessageStateConfig `toml:"messageState"`
Gateway GatewayConfig `toml:"gateway"`
RateLimit RateLimitConfig `toml:"rateLimit"`
Trace *metrics.TraceConfig `toml:"tracing"`
Metrics *metrics.MetricsConfig `toml:"metrics"`
}

type NodeConfig struct {
Expand Down Expand Up @@ -137,11 +138,7 @@ func DefaultConfig() *Config {
Cfg: gatewayTypes.Config{},
},
RateLimit: RateLimitConfig{Redis: ""},
Trace: metrics.TraceConfig{
JaegerEndpoint: "",
ProbabilitySampler: 1.0,
JaegerTracingEnabled: false,
ServerName: "venus-messenger",
},
Trace: metrics.DefaultTraceConfig(),
Metrics: metrics.DefaultMetricsConfig(),
}
}
74 changes: 74 additions & 0 deletions docs/zh/metrics-config-desc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# metrics 配置及使用说明

## 配置

`Metrics` 基本的配置样例如下:
```toml
[Metrics]
# 是否开启metrics指标统计,默认为false
Enabled = false

[Metrics.Exporter]
# 指标导出器类型,目前可选:prometheus或graphite,默认为prometheus
Type = "prometheus"

[Metrics.Exporter.Prometheus]
# multiaddr
EndPoint = "/ip4/0.0.0.0/tcp/4568"
# 命名规范: "a_b_c", 不能带"-"
Namespace = "messager01"
# 指标注册表类型,可选:default(默认,会附带程序运行的环境指标)或 define(自定义)
RegistryType = "define"
# prometheus 服务路径
Path = "/debug/metrics"
# 上报周期,单位为 秒(s)
ReportingPeriod = 10

[Metrics.Exporter.Graphite]
# 命名规范: "a_b_c", 不能带"-"
Namespace = "messager01"
# graphite exporter 收集器服务地址
Host = "127.0.0.1"
# graphite exporter 收集器服务监听端口
Port = 4568
# 上报周期,单位为 秒(s)
ReportingPeriod = 10
```
## 导出器

目前可以选择两类导出器(`exporter`):`Prometheus exporter` 或 `Graphite exporter`,默认是前者。

如果配置 `Prometheus exporter`,则在 `venus-messager` 服务启动时会附带启动 `Prometheus exporter` 的监听服务,可以通过以下方式快速查看指标:


```bash
$ curl http://localhost:4568/debug/metrics
# HELP messager01_chain_head_stable_dur_s Duration of chain head stabilization
# TYPE messager01_chain_head_stable_dur_s histogram
messager01_chain_head_stable_dur_s_bucket{le="8"} 0
messager01_chain_head_stable_dur_s_bucket{le="9"} 11
messager01_chain_head_stable_dur_s_bucket{le="10"} 27
messager01_chain_head_stable_dur_s_bucket{le="12"} 43
messager01_chain_head_stable_dur_s_bucket{le="14"} 48
messager01_chain_head_stable_dur_s_bucket{le="16"} 49
messager01_chain_head_stable_dur_s_bucket{le="18"} 49
messager01_chain_head_stable_dur_s_bucket{le="20"} 49
messager01_chain_head_stable_dur_s_bucket{le="25"} 49
messager01_chain_head_stable_dur_s_bucket{le="30"} 49
messager01_chain_head_stable_dur_s_bucket{le="60"} 50
messager01_chain_head_stable_dur_s_bucket{le="+Inf"} 50
messager01_chain_head_stable_dur_s_sum 503.99999999999983
messager01_chain_head_stable_dur_s_count 50
# HELP messager01_chain_head_stable_s Delay of chain head stabilization
# TYPE messager01_chain_head_stable_s gauge
messager01_chain_head_stable_s 9
... ...
```
> 如果遇到错误 `curl: (56) Recv failure: Connection reset by peer`, 请使用本机 `ip` 地址, 如下所示:
```bash
$ curl http://<ip>:4568/debug/metrics
```

如果配置 `Graphite exporter`,需要先启动 `Graphite exporter` 的收集器服务, `venus-messager` 服务启动时将指标上报给收集器。服务启动参考 [Graphite exporter](https://github.com/prometheus/graphite_exporter) 中的说明。

`Graphite exporter` 和 `Prometheus exporter` 自身都不带图形界面的,如果需要可视化监控及更高阶的图表分析,请到 `venus-docs` 项目中查找关于 `Prometheus+Grafana` 的说明文档。
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/filecoin-project/venus-messager
go 1.17

require (
contrib.go.opencensus.io/exporter/graphite v0.0.0-20200424223504-26b90655e0ce // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/fatih/color v1.13.0
github.com/filecoin-project/go-address v0.0.6
Expand All @@ -15,7 +16,7 @@ require (
github.com/gbrlsnchs/jwt/v3 v3.0.1
github.com/google/uuid v1.3.0
github.com/hunjixin/automapper v0.0.0-20191127090318-9b979ce72ce2
github.com/ipfs-force-community/metrics v1.0.1-0.20211228055608-9462dc86e157
github.com/ipfs-force-community/metrics v1.0.1-0.20220719063006-2c54bb379466
github.com/ipfs-force-community/venus-common-utils v0.0.0-20210924063144-1d3a5b30de87
github.com/ipfs-force-community/venus-gateway v1.6.0
github.com/ipfs/go-cid v0.1.0
Expand All @@ -36,6 +37,8 @@ require (
modernc.org/mathutil v1.1.1
)

require go.opencensus.io v0.23.0

require (
contrib.go.opencensus.io/exporter/jaeger v0.2.1 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect
Expand Down Expand Up @@ -163,10 +166,7 @@ require (
github.com/subosito/gotenv v1.2.0 // indirect
github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect
github.com/ugorji/go/codec v1.2.4 // indirect
github.com/warpfork/go-testmark v0.9.0 // indirect
github.com/whyrusleeping/go-logging v0.0.1 // indirect
github.com/xlab/c-for-go v0.0.0-20200718154222-87b0065af829 // indirect
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/dig v1.12.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
Expand Down
Loading