Prometheus 邮递http://localhost:9093/api/v1/alerts: 拨号tcp[::1]:9093:连接:连接被拒绝

Prometheus 邮递http://localhost:9093/api/v1/alerts: 拨号tcp[::1]:9093:连接:连接被拒绝,prometheus,Prometheus,我在k8s集群的同一个pod上启动prometheus和alertmanager,两个容器都正常启动,但我发现prometheus无法向alertmanager发送post请求,为什么 论普罗米修斯容器 level=info ts=2018-11-15T07:02:02.147783133Z caller=main.go:238 msg="Starting Prometheus" version="(version=2.4.3, branch=HEAD, revision=167a4b4e73a

我在k8s集群的同一个pod上启动prometheus和alertmanager,两个容器都正常启动,但我发现prometheus无法向alertmanager发送post请求,为什么

论普罗米修斯容器

level=info ts=2018-11-15T07:02:02.147783133Z caller=main.go:238 msg="Starting Prometheus" version="(version=2.4.3, branch=HEAD, revision=167a4b4e73a8eca8df648d2d2043e21bdb9a7449)"
level=info ts=2018-11-15T07:02:02.147861401Z caller=main.go:239 build_context="(go=go1.11.1, user=root@1e42b46043e9, date=20181004-08:42:02)"
level=info ts=2018-11-15T07:02:02.147879439Z caller=main.go:240 host_details="(Linux 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 k8s-monitor-6d9cd9cd55-vzlmq (none))"
level=info ts=2018-11-15T07:02:02.147895594Z caller=main.go:241 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2018-11-15T07:02:02.147908172Z caller=main.go:242 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2018-11-15T07:02:02.151206196Z caller=main.go:554 msg="Starting TSDB ..."
level=info ts=2018-11-15T07:02:02.151347322Z caller=web.go:397 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2018-11-15T07:02:02.15948818Z caller=main.go:564 msg="TSDB started"
level=info ts=2018-11-15T07:02:02.159530481Z caller=main.go:624 msg="Loading configuration file" filename=/opt/prometheus-2.4.3.linux-amd64/prometheus.yml
level=info ts=2018-11-15T07:02:02.164675684Z caller=main.go:650 msg="Completed loading of configuration file" filename=/opt/prometheus-2.4.3.linux-amd64/prometheus.yml
level=info ts=2018-11-15T07:02:02.16470252Z caller=main.go:523 msg="Server is ready to receive web requests."
level=error ts=2018-11-15T07:02:02.165912877Z caller=notifier.go:473 component=notifier alertmanager=http://localhost:9093/api/v1/alerts count=0 msg="Error sending alert" err="Post http://localhost:9093/api/v1/alerts: dial tcp [::1]:9093: connect: connection refused"
关于alertmanager容器

level=info ts=2018-11-15T07:02:02.498442497Z caller=main.go:174 msg="Starting Alertmanager" version="(version=0.15.2, branch=HEAD, revision=d19fae3bae451940b8470abb680cfdd59bfa7cfa)"
level=info ts=2018-11-15T07:02:02.498524847Z caller=main.go:175 build_context="(go=go1.10.3, user=root@3101e5b68a55, date=20180814-10:53:39)"
level=info ts=2018-11-15T07:02:02.505830622Z caller=cluster.go:155 component=cluster msg="setting advertise address explicitly" addr=192.168.216.185 port=9094
level=info ts=2018-11-15T07:02:02.50851545Z caller=main.go:322 msg="Loading configuration file" file=/opt/alertmanager/alertmanager.yml
level=info ts=2018-11-15T07:02:02.508720329Z caller=cluster.go:570 component=cluster msg="Waiting for gossip to settle..." interval=2s
level=info ts=2018-11-15T07:02:02.512111679Z caller=main.go:398 msg=Listening address=:9093
level=info ts=2018-11-15T07:02:04.508881502Z caller=cluster.go:595 component=cluster msg="gossip not settled" polls=0 before=0 now=1 elapsed=2.000097885s
level=info ts=2018-11-15T07:02:12.50938298Z caller=cluster.go:587 component=cluster msg="gossip settled; proceeding" elapsed=10.000595281s
舱内

[root@k8s-monitor-6d9cd9cd55-vzlmq /]# netstat -utlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp6       0      0 :::9090                 :::*                    LISTEN      5/prometheus
tcp6       0      0 :::9093                 :::*                    LISTEN      -
tcp6       0      0 :::9094                 :::*                    LISTEN      -
udp6       0      0 :::9094                 :::*                                -

我使用docker compose进行测试,遇到了同样的问题

[compose.yaml]
prometeus:
  image: prom/prometheus:master
  networks: [ test ]
  hostname: prometeus
  ports:
   - 9090:9090
alertmanager:
  image: prom/alertmanager:master
  networks: [ test ]
  hostname: alertmanager
  ports:
    - "9093:9093"

prometeus.yml
alerting:
  alertmanagers:
    - static_configs:
      - targets: ['alertmanager:9093', `'127.0.0.1:9093', 'localhost:9093'`]

使用
127.0.0.1
localhost
时,我收到错误,但更改为
HOSTNAME
有助于解决此问题。

删除“围绕端口号为我解决了这个问题

你问了这么糟糕的问题。您还应该添加您的配置文件!看起来您的YAML文件被弄乱了,因为您没有在问题中使用。您好,欢迎使用SO!请阅读,例如添加一个完整的代码可能会有所帮助。