1.环境
192.168.244.128 Prometheus 监控服务器 192.168.244.129 docker 服务(被监控端) 注:都是centos7.5系统2.下载安装包
(需要的安装包都可以下载) wget服务端(监控server)
3.安装prometheus 部署到/usr/local/目录 promethus不用编译安装,解压目录中有配置文件与启动文件 tar -zxvf prometheus-2.3.2.linux-amd64.tar.gz -C /usr/local/ cd /usr/local/ && mv prometheus-2.3.2.linux-amd64/ prometheus 验证 [root local]# cd prometheus/ [root prometheus]# ./prometheus --version prometheus, version 2.3.2 (branch: HEAD, revision: 71af5e29e815795e9dd14742ee7725682fa14b7b) build user: root@5258e0bd9cc1 build date: 20180712-14:02:52 go version: go1.10.3备份配置文件并配置
cp prometheus.yml prometheus.yml-bakmy 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
- targets:
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: ['192.168.244.128:9090','192.168.244.129:8080']
添加需要监控的服务器IP和端口
启动(后台启动)
./prometheus --config.file=prometheus.yml & 然后我们可以访问![Prometheus+Grafana部署监控docker服务](https://s1.51cto.com/images/blog/201808/30/62d15d8a5d15f8cfac1f1fc534624408.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
4.node_exporter安装
wget 解压并安装 tar xf node_exporter-0.16.0.linux-amd64.tar.gz C /usr/local/ cd /usr/local/ && mv mv node_exporter-0.16.0 node_exporter cd node_exporter/ && ./node_exporter &返回一大堆指标
5.grafana安装
wget sudo yum localinstall grafana-5.2.3-1.x86_64.rpm 服务端图像呈现组件安装 yum install fontconfig freetype* urw-fonts -y 开启系统默认启动 systemctl enable grafana-server 启动服务 systemctl start grafana-server 查看服务是否正常启动 systemctl status grafana-server [root ~]# systemctl status grafana-server ● grafana-server.service - Grafana instance Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: disabled) Active: active (running) since 四 2018-08-30 16:18:55 CST; 3h 23min ago Docs: Main PID: 10535 (grafana-server) CGroup: /system.slice/grafana-server.service └─10535 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid ... 访问grafana, 默认用户名密码:admin/admin![Prometheus+Grafana部署监控docker服务](https://s1.51cto.com/images/blog/201808/30/199ea829bbecb88105e95a254e712713.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
客户端(被监控)
6.安装cAdvisor 来收集容器信息 所有节点运行以下命令来安装cAdvisor docker run \ --volume=/:/rootfs:ro \ --volume=/var/run:/var/run:rw \ --volume=/sys:/sys:ro \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --publish=8080:8080 \ --detach=true \ --name=cadvisor \ --net=host \ -v "/etc/localtime:/etc/localtime" \ google/cadvisor:latest为grafana添加Prometheus数据源
![Prometheus+Grafana部署监控docker服务](https://s1.51cto.com/images/blog/201808/30/e644ce5d6669567d167ea9de746d4630.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
![Prometheus+Grafana部署监控docker服务](https://s1.51cto.com/images/blog/201808/30/b176f2d48ac5dee789384241a2cfdf6d.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
![Prometheus+Grafana部署监控docker服务](https://s1.51cto.com/images/blog/201808/30/35b73fcec1b832b049b19f3a865d5de8.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
![Prometheus+Grafana部署监控docker服务](https://s1.51cto.com/images/blog/201808/30/f9c44ebf23a68e632a43e3bdb3545730.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
![Prometheus+Grafana部署监控docker服务](https://s1.51cto.com/images/blog/201808/30/60b84873ac044953c636d9161e5011d8.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
参考文档