Docker Prometheus 在本地主机上抓取 API 服务器

问题描述 投票:0回答:1

我已将 prometheus 和警报管理器配置为在 Docker 桌面中运行。 Prometheus 服务器配置为抓取运行在本地主机(端口:7080)上的 API 服务器(未 Docker 化)。

prometheus 容器和警报管理器容器之间的通信正常,但我创建的用于测试 API 服务器是否已启动并运行的规则始终会设置警报,然后触发警报,即使服务器正在运行也是如此。如果我在本地主机中设置这个环境(没有 Docker),一切都很好。

我使用了prometheus服务器的基础镜像,该镜像是在执行命令时下载的。

我尝试了很多目标参数的配置,

targets: ["localhost:7080"], 
targets: ["192.168.62.1:7080"], 
targets: ["localhost:7080"],
targets: ["host.docker.internal:7080"].

这是我的配置 -

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 20 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
      - targets: ["172.17.0.3:9093"]
    
rule_files:
   - rules.yml
  

scrape_configs:
  
  - job_name: "Kernel"
    metrics_path: '/metrics'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    scheme: https
    static_configs:
      - targets: ["localhost:7080"]

规则.yml

groups:
- name: Kernel
  rules:
 
  - alert: Kernel Down Critical
    expr: up==0
    for: 30s
    labels:
      severity: critical
    annotations:
      summary: Kernel Down Critical
      description: Down fo more than 30s!!
      host: "{{ $labels.instance }}"

docekr 命令创建容器:

docker create --name Prometheus  --publish 9090:9090 --volume Prometheus-volume:/prometheus --volume C:\Users\t.domenici\Documents\prometheus-2.49.0-rc.0.windows-amd64/prometheus.yml:/etc/prometheus/prometheus.yml --volume C:\Users\t.domenici\Documents\prometheus-2.49.0-rc.0.windows-amd64/rules.yml:/etc/prometheus/rules.yml  prom/prometheus

谢谢

localhost prometheus
1个回答
0
投票

尝试将

--network host
添加到您的 docker run 命令中,并尝试抓取并共享您从目标/服务发现页面收到的任何错误

© www.soinside.com 2019 - 2024. All rights reserved.