Node_Exporters收集服务器指标

使用Node_Exporter来收集服务器的各项指标,从https://github.com/prometheus/node_exporter/releases下载对应服务器的版本

  1. #获取node_exporter
  2. wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
  3. #解压
  4. tar xvfz node_exporter-0.18.1.linux-amd64.tar.gz -C /application/
  5. #做软链接
  6. cd /application/ && ln -s /application/node_exporter-0.18.1.linux-amd64 node_exporter
  7. #后台启动
  8. ./application/node_exporter/node_exporter &

修改Prometheus配置文件,添加Node的信息

  1. - job_name: 'elk'
  2. static_configs:
  3. - targets: ['10.0.0.110:9100']

MySQL

mysqld_exporter可以很方便的帮我们监控MySQL的各项指标
官方下载地址:https://github.com/prometheus/mysqld_exporter/releases

  1. #获取
  2. wgethttps://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
  3. #解压
  4. tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /application/
  5. #做软连接
  6. ln -s mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
  7. #后台启动
  8. ./mysqld_exporter &

然后在Prometheus配置文件后添加mysqld_exporter的信息

  1. - job_name: 'mariadb'
  2. static_configs:
  3. - targets: ['10.0.0.220:9104']
  4. labels:
  5. instance: db

Nginx

监控nginx有很多插件和模块可以使用,其中Nginx VTS exporter是比较强大的,使用它需要用到nginx的vts模块,vts模块能输出多种监控项和多种格式数据。不足是nginx没有自带这个模块,需要手动编译添加

具体编译的过程可以看
语雀内容
添加模块后编辑nginx的配置文件开启模块

  1. vim /etc/nginx/nginx.conf
  2. ...
  3. http {
  4. ...
  5. vhost_traffic_status_zone;
  6. vhost_traffic_status_filter_by_host on;
  7. }

在任意子配置文件中添加

  1. location /status {
  2. vhost_traffic_status_display;
  3. vhost_traffic_status_display_format html;
  4. }

重启nginx完成加载

  1. #检测nginx语法是否正确
  2. nginx -t
  3. #重启
  4. systemctl restart nginx

打开IP:端口即可看到信息,nginx配置部分完成。

下载nginx-vts-exporter

  1. ./nginx-vts-exporter -nginx.scrape_uri=http://10.0.0.220/status/format/json &

在Prometheus配置文件添加nginx-vts-exporter

  1. - job_name: 'nginx'
  2. static_configs:
  3. - targets: ['10.0.0.220:9913']
  4. labels:
  5. instance: nginx