node.js - Node.js + Prometheus - 目标连接被拒绝
问题描述
我在本地运行节点应用程序。它http://localhost:3002
使用prom-client运行,我可以在以下端点http://localhost:3002/metrics看到指标。
我已经在 docker 容器中设置了 prometheus 并运行了它。
Dockerfile
FROM prom/prometheus
ADD prometheus.yml /etc/prometheus/
普罗米修斯.yml
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:3002']
labels:
service: 'my-service'
group: 'production'
rule_files:
- 'alert.rules'
docker build -t my-prometheus .
docker run -p 9090:9090 my-prometheus
当我导航到http://localhost:9090/targets
它显示
获取http://localhost:3002/metrics : 拨打 tcp 127.0.0.1:3002: connect: 连接被拒绝
你能告诉我我在这里做错了什么吗?节点应用程序正在该端口的本地主机上运行,因为当我去时http://localhost:3002/metrics
我可以看到指标。
解决方案
当您在容器内时,您无法直接访问 localhost。您需要将 docker.for.mac.localhost 添加到您的 prometheus.yml 文件中。见下文:
prometheus.yml 文件中的工作。- 工作名称:'普罗米修斯'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- targets: ['docker.for.mac.localhost:3002']
推荐阅读
- javascript - 是否有合适的时间例行删除yarn.lock/package-lock.json?
- java - 多级字符串拆分
- google-cloud-platform - 是否可以在云功能中获取项目元数据?
- microservices - JHipster - 如何在 application.yml 中添加到外部微服务的路由
- python - scrapy 如何在内部发送 Web 请求?
- c++ - Visual Studio C++ 代码如何自动缩进预处理器指令
- django - 尝试使用 django 框架开发一个反映用户和分数的门户网站
- c# - 单个 glControl 上的多个纹理 - openTK
- python - 我正在尝试在 jupyter notebook 中获取数据透视表,但 aggfunc 无法正常工作
- shiny - 更改颜色主题 DT 表