Prometheus监控容器并邮箱报警
作者:互联网
Prometheus监控容器并邮箱报警
在被监控的主机上拉取google/cadvisor官方镜像
[root@node1 ~]# docker pull google/cadvisor
[root@node1 ~]# docker images|grep cadvisor
google/cadvisor latest eb1210707573 3 years ago 69.6MB
在被监控的主机上使用google官方镜像运行cadvisor容器并进行目录及端口映射
[root@node1 ~]# docker run \
> --volume=/:/rootfs:ro \
> --volume=/var/run:/var/run:ro \
> --volume=/sys:/sys:ro \
> --volume=/var/lib/docker/:/var/lib/docker:ro \
> --volume=/dev/disk/:/dev/disk:ro \
> --publish=8080:8080 \
> --detach=true \
> --name=cadvisor \
> --privileged \
> --device=/dev/kmsg \
> google/cadvisor
c3262f1a6c2f3862daf414b7d7e6f5a6ff18949a8b4e02c27fea74e481ec038a
[root@node1 ~]# docker ps |grep cadvisor
c3262f1a6c2f google/cadvisor "/usr/bin/cadvisor -…" 25 seconds ago Up 23 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp cadvisor
访问测试
在master上修改Prometheus的配置文件
使Prometheus能够接收到cadsvisor采集的信息从而实现对cadvisor所处主机的监控
[root@master ~]# vim /opt/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"]
- job_name: "Linux Server"
static_configs:
- targets: ["192.168.100.120:9100"]
- job_name: "containers" //添加此处
static_configs: //添加此处
- targets: ["192.168.100.120:8080"] //添加此处
[root@master ~]# docker restart prometheus
prometheus
[root@master ~]# docker ps |grep prom
f81031397de2 prom/prometheus "/bin/prometheus --c…" 25 hours ago Up 8 seconds 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus
Prometheus中查看监控情况
进入grafana导入模板11600
标签:容器,8080,cadvisor,--,prometheus,Prometheus,邮箱,docker,root 来源: https://blog.csdn.net/Cadillac_Yuhuang/article/details/122246608