关于prometheus:prometheusgrafana-容器方式部署方式

3次阅读

共计 2514 个字符,预计需要花费 7 分钟才能阅读完成。

背景

新增两台物理机用于压测,为了监控服务器状况,现须要对服务器进行监控,所有须要装置 prometheus+grafana 来监控服务。

筹备

  • 机器:

    机器 1 机器 2
    192.168.1.103 192.168.1.102
    mock 服务,压测脚本 业务服务
    prometheus+ grafana+node-exporter+cadvisor node-exporter+cadvisor

阐明:

   cadvisor: 用于收集容器的信息
   node-exporter: 用于收集机器主机的信息
   prometheus: 别离把 node-exporter 和 cadivsor 的数据对立汇合
   grafana: 页面 web 展现
  • 同步工夫
    因为物理机是新装的 centos7.9 的零碎,本地工夫和 windows 的工夫不统一,会导致后续的 grafana 不能拉取到数据 no data. 同步网络工夫很重要。 date 查看工夫
  • 敞开防火墙或者凋谢相应的端口 systemctl status firewalld 查看防火墙状况
  • 机器的网口名要统一
    目前我的两台机器网口名一个是:p2p1, 一个是:enp3s0. 导致 grafana 页面填写收集的表达式 device 不能对立,很麻烦。
    node_network_receive_bytes_total{instance=~'$node', device="enp3s0", job="host"}
    ifconfig 查看网口名
装置 ntpd
yum install -y ntpd 

systemctl enable ntpd
systemctl  start ntpd 
systemctl status ntpd 
同步工夫
ntpdate -u ntp.sjtu.edu.cn 

开始部署

  • node-exporter
docker run  -v "/proc:/host/proc" -v  "/sys:/host/sys" -v "/:/rootfs" --net=host --restart=always --name node-exporter prom/node-exporter --path.procfs /host/proc --path.sysfs /host/sys --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"

阐明: node-exporter肯定要以 host 模式装置,bridge 模式,不能收集到网口的数据。

  • cadvisor
    docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw --volume=/sys/sys:ro --volume=/home/docker-file/:/var/lib/docker:ro --volume=/dev/disk:/dev/disk:ro --net=host --detach=true --name=cadvisor --restart=always google/cadvisor:latest

阐明:–volume=/home/docker-file:/var/lib/docker 这个指向的是本地 docker 服务运行的门路,我这里是指向了 /home/docker-file 门路,如果没有改变的话就是 /var/lib/docker。df -h 能够查看门路。

  • prometheus
    docker run -d -v /home/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml --restart=always --net=host --name=prometheus prom/prometheus

prometheus.yaml

global:
   scrape_interval: 15s
   evaluation_interval: 15s
   external_labels: 
     monitor: 'edc-lab-monitor'

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['192.168.1.103:9090']
  
  - job_name: 'host' 
    static_configs:
      - targets: ['192.168.1.102:9100', '192.168.1.103:9100']
  
  - job_name: 'container'
    static_configs:
      - targets: ['192.168.1.102:8080', '192.168.1.103:8080']  

能够通过 192.168.1.103:9090 查看 prometheus 的数据收集状况,
在搜寻框中搜寻 node_network_receive_bytes_total 能够查看网口进来的数据。

  • grafana
    docker run -d -i -p 3000:3000 -e "GF_SERVER_ROOT_URL=http://grafana.server.name" -e "GF_SECURITY_ADMIN_PASSWORD=admin123" --restart=always --name=grafana grafana/grafana

GF_SECURITY_ADMIN_PASSWORD:web 登陆 admin 的明码

登陆 grafana

http://192.168.1.103:3000/login 输出用户名: admin 明码:admin123

  1. 增加 data sources

选中 prometheus

填写 http 连贯:http://192.168.1.103:9090 而后点击 save and test ok 的话,数据增加胜利,不胜利,查看服务或者防火墙等。

  1. 增加 grafana 模版:
    点击左侧的“Home”–>Dashboards。在 New 按键下,抉择 import

    罕用的模版是 9276,193, 315, 6139,3146 等,其余的能够在 grafana 官网上查找。

    抉择 promethues, import 胜利。

查看页面, 分组抉择 ”host”, 能够看到主机的信息,容器的话,该模版中没显示进去,能够其余的容器模块来看容器的信息。

正文完
 0