Docker部署prometheus和grafana – 记忆角落

Docker部署prometheus和grafana

/ 0评 / 0

Docker部署prometheus和grafana

安装prometheus

创建配置文件

在任意路径下创建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 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# 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: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
运行容器
docker run -itd --name prometheus -p 9090:9090 \
-v /data/prometheus_data/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /etc/localtime:/etc/localtime:ro \
prom/prometheus:v2.32.1

安装cAdvisor

prometheus无法独自收集容器信息,所以需要cAdvisor,同时他还可以完成自动发现容器的任务。

运行容器

docker run -itd --name cadvisor -p 8080:8080 \
-v /:/rootfs:ro \
-v /var/run:/var/run:rw \
-v /sys:/sys:ro \
-v /var/lib/docker/:/var/lib/docker:ro \
-v /dev/disk/:/dev/disk:ro \
google/cadvisor

修改prometheus.yml文件

再最后增加:

  - job_name: 'docker'
    static_configs:
    - targets: ['cadvisor宿主机IP:8080']

安装grafana

运行容器

docker run -itd --name grafana -p 3000:3000 grafana/grafana

初始用户名和密码都是admin,初次登陆系统需要更改密码。

img

然后进行基础的配置,最后自己配置的效果如下:

img

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注