Prometheus 不会连接到 Synapse 指标

Prometheus won't connect to Synapse metrics

我尝试按照本指南使用突触指标配置普罗米修斯:https://github.com/matrix-org/synapse/blob/master/docs/metrics-howto.md

虽然我遇到了困难。这是我的设置方式:

$ sudo ufw 允许 9090

$ sudo nano /etc/matrix-synapse/homeserver.yaml

# in listeners: list
  - type: metrics
    port: 9000
    bind_addresses:
      - '0.0.0.0'

## Metrics ###

# Enable collection and rendering of performance metrics
#
enable_metrics: true

重新启动 Synapse,安装 Docker。

创建'/etc/prometheus/prometheus.yml' 像这样编辑它:

$ sudo nano /etc/prometheus/prometheus.yml

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

  - job_name: "synapse"
    metrics_path: "/_synapse/metrics"
    scheme: "https"
    static_configs:
      - targets: ["localhost:9000"]

尝试启动 Prometheus:

$ docker 运行 -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml --name prometheus prom/prometheus

level=info ts=2020-05-06T03:42:50.799Z caller=main.go:298 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2020-05-06T03:42:50.799Z caller=main.go:333 msg="Starting Prometheus" version="(version=2.17.2, branch=HEAD, revision=18254838fbe25dcc732c950ae05f78ed4db1292c)"
level=info ts=2020-05-06T03:42:50.799Z caller=main.go:334 build_context="(go=go1.13.10, user=root@9cb154c268a2, date=20200420-08:27:08)"
level=info ts=2020-05-06T03:42:50.800Z caller=main.go:335 host_details="(Linux 4.19.0-8-amd64 #1 SMP Debian 4.19.98-1+deb10u1 (2020-04-27) x86_64 0cf4549b1dcd (none))"
level=info ts=2020-05-06T03:42:50.800Z caller=main.go:336 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2020-05-06T03:42:50.800Z caller=main.go:337 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2020-05-06T03:42:50.802Z caller=main.go:667 msg="Starting TSDB ..."
level=info ts=2020-05-06T03:42:50.802Z caller=web.go:515 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2020-05-06T03:42:50.806Z caller=head.go:575 component=tsdb msg="replaying WAL, this may take awhile"
level=info ts=2020-05-06T03:42:50.806Z caller=head.go:624 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0
level=info ts=2020-05-06T03:42:50.807Z caller=head.go:627 component=tsdb msg="WAL replay completed" duration=403.999µs
level=info ts=2020-05-06T03:42:50.808Z caller=main.go:683 fs_type=9123683e
level=info ts=2020-05-06T03:42:50.808Z caller=main.go:684 msg="TSDB started"
level=info ts=2020-05-06T03:42:50.808Z caller=main.go:788 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
level=info ts=2020-05-06T03:42:50.809Z caller=main.go:816 msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml
level=info ts=2020-05-06T03:42:50.810Z caller=main.go:635 msg="Server is ready to receive web requests."

但它只是挂起,将控制台从我身边拿走。 :P 我至少可以在 运行 绑定它时将其分离。

我可以在 192.168.1.171:9090 看到普罗米修斯,但它不是 recording/showing 突触指标。 :/

已从此处下载突触-v2.rules:https://github.com/matrix-org/synapse/tree/master/contrib/prometheus

编辑:谢谢我编辑了 https 部分,并将其指向新的规则文件,这是我的 prometheus.yml:

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  - "/etc/prometheus/synapse-v2.rules"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

  - job_name: "synapse"
    metrics_path: "/_synapse/metrics"
    static_configs:
      - targets: ["localhost:9000"]

然后我重新启动了 Prometheus docker 但它仍然没有在 Web 下拉列表中显示突触指标。

There are prometheus statistics but no synapse ones.

scheme: "https"

Synapse 的指标侦听器不使用 tls。删除这个。

static_configs:
  - targets: ["localhost:9000"]

$ docker run -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml --name prometheus prom/prometheus

localhost 这里是 Docker 容器的 localhost。只有 Docker 容器中的内容才能在那里访问。

尝试下载已编译的软件包,运行 效果很好。