首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Prometheus与Dockerfile

Prometheus与Dockerfile
EN

Stack Overflow用户
提问于 2020-12-24 19:11:13
回答 1查看 1.1K关注 0票数 0

我有下面的Dockerfile

代码语言:javascript
复制
FROM prom/prometheus
ADD prometheus.yml /etc/prometheus/

用prometheus.yml

代码语言:javascript
复制
global:
scrape_interval: 15s

external_labels:
  monitor: 'codelab-monitor'

scrape_configs:
  - job_name: 'prometheus'
    metrics_path: /metrics
    scrape_interval: 15s
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'auth-service'
    scrape_interval: 15s
    metrics_path: /actuator/prometheus
    static_configs:
      - targets: ['localhost:8080']

并使用以下命令运行它:

代码语言:javascript
复制
docker build -t prometheus .
docker run -d -p 9090:9090 --rm prometheus

prometheus拥有up状态

8月-服务状态为down (Get "http://localhost:8080/actuator/prometheus":拨号tcp 127.0.0.1:8080:连接:连接被拒绝“)

我如何解决auth-service,的问题,因为从本地机器我可以从这个地址http://localhost:8080/actuator/prometheus获得指标。

代码语言:javascript
复制
v.balun@macbook-vbalun Trainter-Prometheus % curl -X GET 
http://localhost:8080/actuator/prometheus
# HELP jvm_memory_committed_bytes The amount of memory in bytes that is committed for the 
Java virtual machine to use
# TYPE jvm_memory_committed_bytes gauge
jvm_memory_committed_bytes{area="heap",id="G1 Survivor Space",} 4194304.0
jvm_memory_committed_bytes{area="heap",id="G1 Old Gen",} 3.145728E7
jvm_memory_committed_bytes{area="nonheap",id="Metaspace",} 3.0982144E7
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-nmethods'",} 2555904.0
jvm_memory_committed_bytes{area="heap",id="G1 Eden Space",} 2.7262976E7
jvm_memory_committed_bytes{area="nonheap",id="Compressed Class Space",} 4325376.0
jvm_memory_committed_bytes{area="nonheap",id="CodeHeap 'non-profiled nmethods'",} 6291456.0
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-24 20:11:53

你的问题似乎与普罗米修斯无关,似乎是在码头网络层面。

在您的prometheus容器中,您会这样说:

代码语言:javascript
复制
    static_configs:
      - targets: ['localhost:8080']

但是请记住,localhost现在不是您的物理主机(就像您在Docker之外本地运行它时那样),它现在在容器中,并且在同一个容器中,很可能您没有运行您的服务……

根据所提供的资料,我建议你如下:

  1. 首先尝试使用真正的IP,根据您为容器使用的网络配置,它将足够.
  2. ,您可以使用localhost来代替auth-service的ip地址,这是由对接者给出的地址,您可以运行docker inspect...来获得它。如果#1和#2没有工作,那么

H 112如果auth-service运行在同一物理主机内的另一个容器中,那么您可以使用桥接网络来实现容器之间的通信,这里有更多详细信息:https://docs.docker.com/network/bridge/,一旦两个容器在同一个网络中运行,您可以使用容器名称来引用它,而不是localhost,类似于:

代码语言:javascript
复制
    static_configs:
      - targets: ['auth-service:8080']
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65442417

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档