Docker部署Prometheus与Grafana监控系统配置指南

24 年 3 月 13 日 星期三
280 字
2 分钟

使用docker安装prometheus和grafana后

当我使用prometheus时,服务正常,我可以从 http://localhost:9090 访问UI,所有目标都在运行。

我在grafana上Add new connection时,出现下述错误

text
 Error reading Prometheus: Post "http://localhost:9090/api/v1/query": dial tcp 127.0.0.1:9090: connect: connection refused

he prometheus.yml is:

yaml
global:
  scrape_interval: 15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'histogram'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:1010']

从grafana-github的issue发现问题

Grafana and Prometheus are both deployed using Docker? The localhost of one container is not the localhost of another container, even if you published the port to the host – you can't reach the Prometheus container or the host using localhost from the Grafana container. You need to use the IP address of the Prometheus container, or the hostname if you are using Docker Compose.If you need further help, please post your Docker configs (docker-compose.yml or docker run commands).

解决办法:

如果是用docker启动这两个容器可以尝试使用http://host.docker.internal:9090 去添加数据源

也可以 prometheus:9090,prometheus为容器的名称

文章标题:Docker部署Prometheus与Grafana监控系统配置指南

文章作者:Jinx

文章链接:https://blog.mytest.cc/posts/docker-prometheus-grafana-setup[复制]

最后修改时间:


商业转载请联系站长获得授权,非商业转载请注明本文出处及文章链接,您可以自由地在任何媒体以任何形式复制和分发作品,也可以修改和创作,但是分发衍生作品时必须采用相同的许可协议。
本文采用CC BY-NC-SA 4.0进行许可。