目录

​​部署规划​​

​​process exporter安装​​

​​下载​​

​​安装​​

​​配置​​

​​验证​​

​​Prometheus配置​​

​​配置​​

​​重新启动​​

​​验证​​

​​Grafana展示监控数据​​

​​相关阅读​​


部署规划

主机名

bigdata111

bigdata112

IP地址

192.168.128.111

192.168.128.112

服务部署


Prometheus、

Grafana、

process exporter


process exporter


Prometheus

部署目录


/opt/prometheus/


node exporter

部署目录


/opt/node_exporter-1.3.1.linux-amd64

/opt/node_exporter-1.3.1.linux-amd64

process exporter安装

        在bigdata111和bigdata112两台主机上都安装process exporter。

下载

        下载地址如下:

​GitHub - ncabatoff/process-exporter: Prometheus exporter that mines /proc to report on selected processesPrometheus exporter that mines /proc to report on selected processes - GitHub - ncabatoff/process-exporter: Prometheus exporter that mines /proc to report on selected processeshttps://github.com/ncabatoff/process-exporter​​点击Releases,如图:

Prometheus+Process exporter+Grafana进程监控_prometheus

 下载对应版本,这里下载process-exporter-0.7.10.linux-amd64.tar.gz,如图:

Prometheus+Process exporter+Grafana进程监控_exporter_02

安装

        执行命令对安装包解压:

tar -zxvf process-exporter-0.7.10.linux-amd64.tar.gz -C /opt/

如图:

Prometheus+Process exporter+Grafana进程监控_prometheus_03

执行如下命令,创建process exporter服务启动配置文件process-exporter.service:

vi /etc/systemd/system/process-exporter.service

内容如下:

[Unit]
Description=Prometheus Process Exporter
After=network.target
[Service]
ExecStart=/opt/process-exporter-0.7.10.linux-amd64/process-exporter -config.path /opt/process-exporter-0.7.10.linux-amd64/process-conf.yml
[Install]
WantedBy=multi-user.target

配置

         bigdata111上运行进程,如图: 

Prometheus+Process exporter+Grafana进程监控_process_04

bigdata112上运行进程,如图:

Prometheus+Process exporter+Grafana进程监控_grafana_05

下面以监控这些进程为例配置。

        新建文件process-conf.yml,如图:

Prometheus+Process exporter+Grafana进程监控_exporter_06

 内容如下:

process_names:
- name: "{{.Matches}}"
cmdline:
- 'Kafka'

- name: "{{.Matches}}"
cmdline:
- 'JavaGateway'

- name: "{{.Matches}}"
cmdline:
- 'QuorumPeerMain'

配置含义表示监控Kafka,JavaGateWay和QuorumPeerMain进程。

执行如下命令启动服务

systemctl daemon-reload
systemctl enable process-exporter
systemctl start process-exporter


验证

        process exporter端口默认是9256,在主机上执行:

curl 127.0.0.1:9256

如图:

Prometheus+Process exporter+Grafana进程监控_process_07

 也可以通过页面输入

​​http://bigdata111:9256/metrics​​

如图:

Prometheus+Process exporter+Grafana进程监控_exporter_08

Prometheus配置

配置

        执行

vi /opt/prometheus/prometheus.yml

打开配置文件,在配置文件最后加入配置

  - job_name: 'process'

    static_configs:

      - targets: ['bigdata111:9256','bigdata112:9256']

如图:

Prometheus+Process exporter+Grafana进程监控_process_09

 执行如下命令,检查配置是否正确:

 ./promtool check config /opt/prometheus/prometheus.yml

如图:

Prometheus+Process exporter+Grafana进程监控_进程监控_10

注:

如果报错 

Prometheus+Process exporter+Grafana进程监控_prometheus_11

 FAILED: parsing YAML file /opt/prometheus/prometheus.yml: yaml: unmarshal errors:

  line 41: cannot unmarshal !!map into []*targetgroup.Group

原因可能是-和targerts之间缺少空格。

重新启动

有两种方式

(1)热加载

        执行如下命令即可:

curl -X POST http://localhost:9090/-/reload

(2)启动服务

        执行如下命令:

systemctl daemon-reload

systemctl restart prometheus.service

systemctl status prometheus.service


验证

在浏览器中输入:

​​http://bigdata111:9090/targets​​

 登录Prometheus页面,如图:

Prometheus+Process exporter+Grafana进程监控_exporter_12

Grafana展示监控数据

登录Grafna主页:

​​http://bigdata111:3000/Prometheus+Process exporter+Grafana进程监控_process_13http://bigdata111:3000/​​

Prometheus+Process exporter+Grafana进程监控_prometheus_14

 点击Create-->Import,填入249,成功后如图:

Prometheus+Process exporter+Grafana进程监控_prometheus_15

 如果出现如下无数据情况:

Prometheus+Process exporter+Grafana进程监控_prometheus_16

或者只有一个主机有数据,如图:

Prometheus+Process exporter+Grafana进程监控_exporter_17

检查process exporter配置是否正确。