[英]context deadline extended - prometheus - while running on docker
I'm trying to get a spring microservice to regsiter on Prometheus. 我试图在Prometheus上获得春季微服务作为注册人。 Both are running on docker.
两者都在docker上运行。 I get "context deadline exceeded" in the Prometheus UI for my service.
我在Prometheus用户界面中获得“超出上下文截止日期”的服务。
Funnily, when i try to open "localhost:8081/metrics" in a new tab, it shows the metrics. 有趣的是,当我尝试在新标签中打开“ localhost:8081 / metrics”时,它会显示指标。
This is my docker-compose.yml. 这是我的docker-compose.yml。 This issue seems pretty common but I've not come across a solution that works for me ;
这个问题似乎很普遍,但是我并没有遇到适合我的解决方案; yet.
然而。
docker-compose.yml docker-compose.yml
version: '2.1'
networks:
cadrs:
ipam:
config:
- subnet: 172.28.0.0/16
services:
prometheus:
image: prom/prometheus:0.18.0
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '-config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'
demo:
build: "C:/Users/hmt843/Downloads/demo"
hostname: "demo"
ports:
- "8081:8081"
networks:
cadrs:
ipv4_address: 172.28.1.2
node-exporter:
image: prom/node-exporter:v0.15.0
ports:
- '9100:9100'
prometheus.yml 普罗米修斯
global:
scrape_interval: 15s
external_labels:
monitor: 'my-monitor'
scrape_configs:
- job_name: 'prometheus'
target_groups:
- targets: ['localhost:9090']
- job_name: 'demo'
tls_config:
insecure_skip_verify: true
target_groups:
- targets: ['172.28.1.2:8081']
- job_name: 'node-exporter'
target_groups:
- targets: ['node-exporter:9100']
By specifying the network section in your app's service the container is placed in a separate docker network called cadrs
. 通过在您应用的服务中指定网络部分,可以将容器放置在一个名为
cadrs
的单独的cadrs
网络中。 Your Prometheus service has no such network definition and thus is in the default
network. 您普罗米修斯服务有没有这样的网络定义,因此在
default
网络。 Containers must reside in at least one common network to be able to access each others. 容器必须驻留在至少一个公共网络中,才能相互访问。 Even exposing the container on the host port doesn't affect this (but you could reach the app via your host ip - don't do this).
即使将容器暴露在主机端口上也不会对此造成影响(但是您可以通过主机ip访问应用程序-请勿这样做)。
If you really need this network configuration, either add Prometheus to the same network by adding the same network section to your Prometheus service or introduce another network (eg monitoring
) that is used in both services. 如果您确实需要此网络配置,则可以通过将相同的网络部分添加到您的Prometheus服务中来将Prometheus添加到相同的网络中,或者引入两个服务中都使用的另一个网络(例如,
monitoring
)。 Alternatively you could also specify that your app is in the default network by adding one more line to your networks section of the app. 另外,您还可以通过在应用程序的“网络”部分添加一行来指定您的应用程序在默认网络中。
networks:
cadrs:
[...]
default:
Reference: https://docs.docker.com/compose/networking/#configure-the-default-network 参考: https : //docs.docker.com/compose/networking/#configure-the-default-network
With this setup, you can modify your scrape configuration also back to demo:8081
. 有了这个设置,你可以修改你刮配置也回到
demo:8081
。 Either way, ask yourself if you really want to use manage container addresses by yourself... 无论哪种方式,问问自己是否真的要自己使用管理容器地址...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.