prometheus通过各种exporter添加数据源

prometheus安装好了,需要通过各种exporter来收集数据,下面将讲解各种exporter工具的安装及配置使用

node_exporter 是一款用来收集liunx服务器的参数的exporter,
下载地址:https://prometheus.io/download/

#下载node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
#解压node_exporter
tar zxvf  node_exporter-1.1.2.linux-amd64.tar.gz
#把文件移动安装到/opt/node_exporter
mv node_exporter-1.1.2.linux-amd64 /opt/node_exporter
#创建node_exporter用户
useradd -s /sbin/nologin -M node_exporter

下面是启动脚本
启动脚本的位置:/etc/systemd/system/node_exporter.service
把下面的代码贴到上面的文件中

[Unit]
Description=node_exporter
Documentation=https://github.com/prometheus/node_exporter
After=network.target
[Service]
Type=simple
User=node_exporter
ExecStart=/opt/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

node_exporter.service 的启动及停止脚本
systemctl start node_exporter.service #启动
systemctl stop node_exporter.service #停止
systemctl status node_exporter.service #查看状态
systemctl restart node_exporter.service #重启

服务确定正常启动后,在prometheus的prometheus.yml添加一下数据源

  - job_name: 'linux'
    static_configs:
    - targets: ['127.0.0.1:9100']

在grafana中导入模板 https://grafana.com/grafana/dashboards/9276,效果图如下

mysqld_exporter的安装及调试

下载mysqld_exporter
https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz

#下载mysqld_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
#解压
tar zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
#安装到mysqld_exporter
mv mysqld_exporter-0.13.0.linux-amd64 /opt/mysqld_exporter
# 创建脚本运行用户node_exporter
useradd -s /sbin/nologin -M node_exporter

通过sql给数据库添加账号

CREATE USER 'exporter'@'localhost' IDENTIFIED BY '123456Khsdfh' WITH MAX_USER_CONNECTIONS 5;
 GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
 flush PRIVILEGES;

把mysql 账号放到 /opt/mysqld_exporter/.mysqld_exporter.cnf
[client]
host=localhost
port=3306
user=exporter
password=123456

下面是启动脚本,把下面内容复制到 /etc/systemd/system/mysqld_exporter.service

[Unit]
Description=mysqld_exporter
Documentation=https://github.com/prometheus/mysqld_exporter
After=network.target
[Service]
Type=simple
User=mysqld_exporter
ExecStart=/opt/mysqld_exporter/mysqld_exporter \
--config.my-cnf /opt/mysqld_exporter/.mysqld_exporter.cnf \
--collect.auto_increment.columns \
--collect.binlog_size \
--collect.engine_innodb_status \
--collect.global_status \
--log.level=error \
--collect.info_schema.processlist \
--collect.info_schema.innodb_metrics \
--collect.info_schema.innodb_tablespaces \
--collect.info_schema.innodb_cmp \
--collect.global_variables \
--collect.info_schema.innodb_cmpmem

Restart=on-failure
[Install]
WantedBy=multi-user.target

mysqld_exporter.service 的启动及停止脚本
systemctl start mysqld_exporter.service #启动
systemctl stop mysqld_exporter.service #停止
systemctl status mysqld_exporter.service #查看状态
systemctl restart mysqld_exporter.service #重启

服务确定正常启动后,在prometheus的prometheus.yml添加一下数据源

 - job_name: 'mysqld'
    static_configs:
    - targets: ['127.0.0.1:9104']

在grafana中使用模板id 7362 就可以了,展示效果还不错。

nginx-vts-exporter的安装及使用

下载地址 https://github.com/hnlq715/nginx-vts-exporter

#下载
wget  https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
#解压
tar zxvf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
#安装到/opt/nginx-vts-exporter
mv nginx-vts-exporter-0.10.3.linux-amd64 /opt/nginx-vts-exporter
# 创建脚本运行用户vts
useradd -s /sbin/nologin -M vts

下面是启动脚本
/etc/systemd/system/nginx-vts-exporter.service

[Unit]
Description=nginx-vts-exporter
Documentation=https://github.com/hnlq715/nginx-vts-exporter
After=network.target
[Service]
Type=simple
User=vts
ExecStart=/opt/nginx-vts-exporter/nginx-vts-exporter -nginx.scrape_uri='http://127.0.0.1/vts_nginx_status/format/json'
Restart=on-failure
[Install]
WantedBy=multi-user.target

启动及停止脚本
systemctl start nginx-vts-exporter.service #启动
systemctl stop nginx-vts-exporter.service #停止
systemctl status nginx-vts-exporter.service #查看状态
systemctl restart nginx-vts-exporter.service #重启

服务确定正常启动后,在prometheus的prometheus.yml添加一下数据源

- job_name: 'nginx'
    static_configs:
      - targets: ['127.0.0.1:9913']
        labels:
          instance: '127.0.0.1'

grafana导入模板 https://grafana.com/grafana/dashboards/2949

reids_exporter的安装及配置
下载地址:https://github.com/oliver006/redis_exporter/releases/download/v1.24.0/redis_exporter-v1.24.0.linux-amd64.tar.gz

#下载
wget https://github.com/oliver006/redis_exporter/releases/download/v1.24.0/redis_exporter-v1.24.0.linux-amd64.tar.gz
#解压
tar zxvf redis_exporter-v1.24.0.linux-amd64.tar.gz
#安装到/opt/nginx-vts-exporter
mv redis_exporter-v1.24.0.linux-amd64 /opt/redis_exporter
# 创建脚本运行用户vts
useradd -s /sbin/nologin -M redis_exporter

下面是启动脚本,无密码的话就不要设置 -redis.password 了,如果有密码的话记得把passwdXXXX改成自己服务器上的密码

[Unit]
Description=redis_exporter
Documentation=https://github.com/oliver006/redis_exporter
After=network.target
[Service]
Type=simple
User=redis_exporter
ExecStart=/opt/redis_exporter/redis_exporter -redis.addr 127.0.0.1:6379 -redis.password passwdXXXX
Restart=on-failure
[Install]
WantedBy=multi-user.target

在prometheus中加入如下配置,就可以收集到redis_exporter的数据信息了

- job_name: 'redis'
    static_configs:
      - targets: ['127.0.0.1:9121']
        labels:
          instance: '127.0.0.1'

导入grafana的模板:https://grafana.com/grafana/dashboards/11835,就可以看到如下的监控界面了


参考链接 https://blog.csdn.net/allway2/article/details/106986309/

You May Also Like