summaryrefslogtreecommitdiff
path: root/docs/locales/zh/advanced/metrics.md
blob: a9110bf91db30e7f02a0cda19e43071e487097cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 指标

GoToSocial 提供了基于 [OpenTelemetry][otel] 的指标。这些指标使用 [Prometheus 暴露格式][prom],通过 `/metrics` 路径展示。配置设置在 [可观察性配置参考][obs] 中有详细说明。

当前收集的指标包括:

* Go 性能和运行时指标
* Gin (HTTP) 指标
* Bun (数据库) 指标

可以通过以下配置启用指标:

```yaml
metrics-enabled: true
```

虽然指标不包含任何隐私敏感信息,但你可能不希望随便让任何人查看和抓取你的实例的运营指标。

## 启用基本身份验证

你可以为指标端点启用基本身份验证。在 GoToSocial 上,你需要以下配置:

```yaml
metrics-auth-enabled: true
metrics-auth-username: some_username
metrics-auth-password: some_password
```

你可以使用 Prometheus 实例通过以下 `scrape_configs` 配置抓取该端点:

```yaml
- job_name: gotosocial
  metrics_path: /metrics
  scheme: https
  basic_auth:
    username: some_username
    password: some_password
  static_configs:
  - targets:
    - example.org
```

## 屏蔽外部抓取

当使用反向代理运行时,可以利用它来屏蔽对指标的外部访问。如果你的 Prometheus 抓取器在与 GoToSocial 实例相同的机器上运行,并可以内部访问它,可以使用这种方法。

例如使用 nginx,通过返回 404 来屏蔽 `/metrics` 端点:

```nginx
location /metrics {
    return 404;
}
```

[otel]: https://opentelemetry.io/
[prom]: https://prometheus.io/docs/instrumenting/exposition_formats/
[obs]: ../configuration/observability.md