Mysql
- 创建mysqld_exporter用户
useradd -M -s /usr/sbin/nologin mysqld_exporter
- 获取mysqld_exporter包, 解压并修改属主数组为mysqld_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz
mv mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter /usr/local/bin/
chown mysqld_exporter.mysqld_exporter /usr/local/bin/mysqld_exporter
- 在mysql中添加mysqld_exporter用户并授权
mysql> CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY '123456' WITH MAX_USER_CONNECTIONS 3;
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'localhost';
mysql> flush privileges;
- 创建mysqld_exporter配置文件,用于登录mysql
vim /etc/.mysqld_exporter.cnf
[client]
user=mysqld_exporter
password=123456
chown mysqld_exporter.mysqld_exporter /etc/.mysqld_exporter.cnf
- mysqld_exporter托管到systemd
cat >> /usr/lib/systemd/system/mysqld_exporter.service << EOF
[Unit]
Description=mysqld_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=mysqld_exporter
Group=mysqld_exporter
Environment=DATA_SOURCE_NAME=mysqld_exporter:123456@(localhost:3306)/
ExecStart=/usr/local/bin/mysqld_exporter \
--config.my-cnf="/etc/.mysqld_exporter.cnf" \
--collect.auto_increment.columns \
--collect.binlog_size \
--collect.engine_innodb_status \
--collect.engine_tokudb_status \
--collect.global_status \
--web.listen-address=0.0.0.0:9104
Restart=always
[Install]
WantedBy=multi-user.target
EOF
- 修改prometheus配置文件,添加mysql job
vim /usr/local/prometheus/prometheus.yml
- job_name: 'mysql'
static_configs:
- targets:
- 192.168.71.21:9104
- 重载prometheus
curl -X POST http://192.168.71.21:9090/-/reload
- 重载并启动mysqld_exporter
systemctl daemon-reload
systemctl start mysqld_exporter
[root@prometheus ~]# ss -lnt | grep 9104
LISTEN 0 128 :::9104 :::*
- 在grafana中添加mysql面板
Nginx
- 编译安装nginx,并安装vts模块
vts为nginx监控模块,能够提供json格式的数据输出
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre
wget https://github.com/vozlt/nginx-module-vts/archive/refs/tags/v0.1.18.tar.gz
./configure --add-module=/root/nginx-module-vts-0.1.18
make && make install
- 修改nginx配置文件,并重启服务
vim /usr/local/nginx/conf/nginx.conf
http {
...
vhost_traffic_status_filter_by_host on;
vhost_traffic_status_zone;
server {
listen 8888;
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
...
}
/usr/local/nginx/sbin/nginx -t
systemctl reload nginx
-
Nginx监控数据查看
-
nginx-vts-exporter获取并解压
wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.0/nginx-vts-exporter-0.10.0.linux-amd64.tar.gz
tar xf nginx-vts-exporter-0.10.0.linux-amd64.tar.gz
cp nginx-vts-exporter-0.10.0.linux-amd64/nginx-vts-exporter /usr/local/bin/
- nginx-vts-exporter托管到systemd
vim /usr/lib/systemd/system/nginx.service
[Unit]
Descirption=nginx-vts-exporter
After=network.target
[Service]
ExecStart=/usr/local/bin/nginx-vts-exporter -nginx.scrape_timeout 10 -nginx.scrape_uri http://192.168.71.21:8888/status/format/json
Restart=always
[Install]
WantedBy=multi-user.target
- 启动nginx-vts-exporter
systemctl daemon-reload
systemctl start nginx-vts-exporter
-
查看nginx-vts-exporter暴露的数据
-
添加nginx job到prometheus
- job_name: 'nginx'
static_configs:
- targets:
- 192.168.71.21:9913
- 重载prometheus
curl -X POST http://192.168.71.21:9090/-/reload
- prometheus 界面查看