Prometheus + Grafana monitoring system set up

Bowen outline:
a, prometheus About
two, Prometheus composition and architecture
Third, the deployment prometheus
1) Preparing the environment
2) to deploy prometheus

A, prometheus Profile

Prometheus is an open source framework alarm monitoring system. It's a given time interval collected from the target configured indicators to assess regular expressions, display the results, and in some cases found to be true when an alarm is triggered.

As a new generation of monitoring framework, Prometheus has the following characteristics:

  • Powerful multi-dimensional data model:
    (1) time-series data are differentiated by the names and values of the metric;
    (2) all of the metrics can be set arbitrarily multidimensional label;
    (3) more random data model ,, not deliberately set dotted string;
    (4) the polymerization may be made to the data model, cutting and slicing;
    (5) supporting double precision floating point type, the whole tab can be set to unicode (Unicode);
  • Flexible and powerful query: In the same query can be a plurality of metrics for multiplication, addition, connection, and other fetch operations fractional bits;
  • Easy to manage: do not rely on distributed storage;
  • Pull mode acquisition using time-series data;
  • Push gateway may be employed in a time series manner to push data to Prometheus server terminal;
  • To acquire targets can be monitored through service discovery or static configuration;
  • There are many visual graphical interface;
  • Easily scalable. ;

Two, Prometheus composition and architecture

Prometheus contains many components, many of which are optional components commonly used components are:

  • Prometheus Server: for collecting and storing time-series data;
  • Client Library: client library generates the appropriate metrics for the need to monitor the service and exposed to Prometheus server;
  • Push Gateway: mainly used for short-term jobs. Because of the presence of such jobs a short time, possibly before Prometheus to pull it disappeared. To this end, the jobs can push their metrics directly to Prometheus server end;
  • Exporters: for exposing existing third-party service metrics to Prometheus;
  • Alertmanager: From Prometheus server. After receiving Alerts, removal will duplicate data packet, and route the received acceptance embodiment, alarm;
    ............ the like, there are many, here are a few common components!

Prometheus official document architecture diagram:

Prometheus + Grafana monitoring system set up
Official architecture diagram, the main block module comprising: Prometheus server, exporters, Pushgateway, PromQL, Alertmanager and graphical interface;

Substantially workflow is:
(. 1) good jobs from Prometheus server periodically pull configuration, or exporters metrics or metrics from Pushgateway sent, received, or pulled from the other metrics in Prometheus server;
(2) Prometheus server in the local storage collected metrics, and run the defined alert.rules, recording new time series or an alarm to push Alertmanager;
(. 3) according to the configuration file Alertmanager, processing the received alert, an alarm;
(4) in the graph interface, the visual data acquisition;

Third, the deployment of prometheus

1) Preparing the Environment

Prometheus + Grafana monitoring system set up
Note: The above three servers must have the most basic docker environment, docker version of this I used to 18.09.0!

The case required components deployed:

  • Prometheus server: Prometheus master server;
  • NodeEXporter: Host responsible for collecting information on hardware and operating system information;
  • cAdvisor: container is responsible for collecting information on running Host;
  • Grafana: Prometheus responsible for displaying monitoring interface;

The relationship between the various components of this case: NodeEXporter, cAdvisor responsible for collecting information to Prometheus server, to Grafana displayed graphically by the Prometheus server's.

Experimental environment, for simplicity's sake, turn off the firewall, SELinux, the actual environment need to open the appropriate ports!

2) deployment prometheus

(1) run the node-exporter container

NodeEXporter mainly responsible for collecting information Host hardware and operating system information!

[root@dockerA ~]# docker run -d --name node -p 9100:9100 -v /proc:/host/proc -v /sys:/host/sys -v /:/rootfs --net=host prom/node-exporter --path.procfs /host/proc --path.sysfs /host/sys --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
//使用prom/node-exporter 镜像创建一个名为node的容器,用于收集硬件和系统信息;
//--net=host表示Prometheus server可以直接与node-exporter通信;
//并映射9100端口

After execution, the client using a browser to access, as:
Prometheus + Grafana monitoring system set up
access to the page above represents a node-exporter this component installed successfully!

由于这个NodeEXporter组件需要在三台docker host主机上,所以以上命令就需要在另外两台主机上都执行。执行完成后,自行使用浏览器访问测试!

(2)运行cAdvisor容器

cAdvisor主要负责收集Host上运行的容器信息!

[root@dockerA ~]# docker run -v /:/rootfs:ro -v /var/run:/var/run/:rw -v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro -p 8080:8080 --detach=true --name=cadvisor --net=host google/cadvisor

客户端访问测试:
Prometheus + Grafana monitoring system set up
访问到上述页面则表示cAdvisor这个组件安装成功!

同样这个cAdvisor组件也是需要在三台docker host上全部安装的!所以以上命令也需在另外两台主机上执行,执行完成后,自行测试!

(3)运行Prometheus server容器(只需在dockerA主机上执行即可!)

Prometheus是普罗米修斯的主服务器!

在部署Prometheus之前,需要对它的配置文件进行修改,所以首先运行一个Prometheus容器将其配置文件复制到本地,便于进行修改。

[root@dockerA ~]# docker run -d -p 9090:9090 --name prometheus --net=host prom/prometheus
//运行一个Prometheus容器是为了将它的配置文件拿到本地
[root@dockerA ~]# docker cp prometheus:/etc/prometheus/prometheus.yml .
//将Prometheus容器中的主配置文件复制到本地
[root@dockerA ~]# vim prometheus.yml      //编辑主配置文件
    - targets: ['localhost:9090','localhost:8080','localhost:9100','192.168.1.2:8080','192.168.1.2:9100','192.168.1.3:8080','192.168.1.3:9100']
//这项原本是存在的,只需修改即可!    
 //用于指定监控本机的9090、8080、9100这三个端口,另外添加另外两台docker主机的8080、9100这两个端口。
 //8080端口运行的是cAdvisor服务
 //9100端口运行的是node-exporter服务
 //9090端口运行的就是Prometheus服务
[root@dockerA ~]# docker rm prometheus -f      //将刚才运行的容器删除
prometheus
[root@dockerA ~]# docker run -d -p 9090:9090 --name prometheus --net=host -v /root/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
//重新运行一个prometheus容器,将刚才修改完成的配置文件挂载到容器中

客户端访问测试:
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up

(4)运行grafana容器(同样只需在dockerA主机上运行即可!)

grafana主要负责展示普罗米修斯监控界面,给我们提供良好的图形化界面!

[root@dockerA ~]# mkdir grafana-storage
[root@dockerA ~]# chmod 777 -R grafana-storage
//创建一个目录,赋予777的权限
[root@dockerA ~]# docker run -d -p 3000:3000 --name grafana -v /root/grafana-storage:/var/lib/grafana -e "GF_SECURITY_ADMIN_PASSWORD=123.com" grafana/grafana
//“-e”选项表示修改容器内部的环境变量,将admin用户的密码更改为123.com;

客户端访问测试:
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up

上述配置完成后,我们就需要配置它以什么样的形式来给我们展示了,可以自定义,但是很麻烦,我选择直接去grafana官网寻找现成的模板。如图:
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up

将grafana官方的模板导入到我们的grafana容器提供的web页面中,方法有两种方式:

1)第一种方式:

在grafana官网选择自己喜欢的模板,点击进入,如图:
Prometheus + Grafana monitoring system set up
下载后,回到自己搭建的grafana容器提供的web页面中,如图:
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up
但是仔细看的话,会发现这个模板有些信息都检测不到,所以这里就是为了展示一种方式导入模板的方式。个人建议推荐使用第二种方式!

2)第二种方式:

After selecting the appropriate template, the ID number recorded as:
Prometheus + Grafana monitoring system set up
after recording the ID number of the template, return to the same web pages built grafana own container provided, as shown in FIG:
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up
Prometheus + Grafana monitoring system set up

So far the monitoring web interface to deploy done!

Guess you like

Origin blog.51cto.com/14157628/2461349