prometheus exporter 监控主机

Posted CIAS

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了prometheus exporter 监控主机相关的知识,希望对你有一定的参考价值。

前提要求部署Grafana

前言

有许多库和服务器可以帮助将第三方系统中的现有指标导出为Prometheus指标。在无法直接使用Prometheus度量(例如,HAProxy或Linux系统统计数据)对给定系统进行检测的情况下,这是非常有用的。

Prometheus 一键安装

  • 配置文件位置/usr/local/prometheus-2.37.2.linux-amd64/prometheus.yml
  • Prometheus版本定义建议选择LTS长期支持版本
#!/bin/sh
# -*- coding: utf-8 -*-
# Date: 2022/11/17

echo "download prometheus"
sleep 2
wget -N -P /root/ https://github.com/prometheus/prometheus/releases/download/v2.37.2/prometheus-2.37.2.linux-amd64.tar.gz

echo "decompression prometheus"
sleep 2
tar -zxf /root/prometheus-2.37.2.linux-amd64.tar.gz -C  /usr/local/

echo "prometheus Start Service"
sleep 2
cat >>/usr/lib/systemd/system/prometheus.service<<EOF
[Unit]
Description=prometheus
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus-2.37.2.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.37.2.linux-amd64/prometheus.yml --storage.tsdb.path="/data/prometheus"
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

echo "prometheus Example Set the automatic startup service"
sleep 2
systemctl enable --now prometheus

进入prometheus http://192.168.11.230:9090/ 

 Linux_exporter 一键监控安装脚本

#!/bin/sh
# -*- coding: utf-8 -*-
# Date: 2022/11/17

wget -N -P /opt/ https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz

tar -xf /opt/node_exporter-1.4.0.linux-amd64.tar.gz -C /opt && mv /opt/node_exporter-1.1.2.linux-amd64 /opt/node_exporter

firewall-cmd --zone=public --add-port=9100/tcp --permanent && firewall-cmd --reload 

touch /var/log/node_exporter.log

cat << EOF > /opt/node_exporter/node_exporter.sh
#!/bin/bash
/opt/node_exporter/node_exporter  &>> /var/log/node_exporter.log
EOF

chmod +x /opt/node_exporter/node_exporter.sh 

cat << EOF > /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
#The startup script
ExecStart=/opt/node_exporter/node_exporter.sh

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload && systemctl enable --now node_exporter

sql_exporter 一键监控安装脚本

  • sed -i "18i  data_source_name: 'sqlserver://sa:YOU_password@YOU_IP:1433'" /opt/sql_exporter/sql_exporter.yml  #需要更改sql server主机的IP用户名密码
#!/bin/sh
# -*- coding: utf-8 -*-
# Date: 2022/02/23

wget -N -P /opt/ https://github.com/free/sql_exporter/releases/download/0.5/sql_exporter-0.5.linux-amd64.tar.gz

tar -xf /opt/sql_exporter-0.5.linux-amd64.tar.gz -C /opt/ && mv /opt/sql_exporter-0.5.linux-amd64 /opt/sql_exporter

firewall-cmd --zone=public --add-port=9399/tcp --permanent && firewall-cmd --reload 

sed -i '/data_source_name/'d /opt/sql_exporter/sql_exporter.yml 

sed -i "18i  data_source_name: 'sqlserver://sa:YOU_password@YOU_IP:1433'" /opt/sql_exporter/sql_exporter.yml 


cat << EOF > /usr/lib/systemd/system/sql_exporter.service
[Unit]
Description=sql_exporter
Documentation=https://github.com/free/sql_exporter
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/opt/sql_exporter/sql_exporter -config.file /opt/sql_exporter/sql_exporter.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload && systemctl enable --now sql_exporter

redis_exporter 一键监控安装脚本

  • ExecStart=/opt/redis_exporter/redis_exporter -log.level=debug -log-format='txt' -redis.addr=192.168.11.253:6379 -redis.password=YOU_password #更改主机redis 主机IP用户名密码
#!/bin/sh
# -*- coding: utf-8 -*-
# Date: 2022/02/23

wget -N -P /opt/ https://github.com/oliver006/redis_exporter/releases/download/v1.24.0/redis_exporter-v1.24.0.linux-amd64.tar.gz

tar -xf /opt/redis_exporter-v1.24.0.linux-amd64.tar.gz /opt/.tar.gz -C /opt/

mv /opt/redis_exporter-v1.24.0.linux-amd64 /opt/redis_exporter


cat << EOF > /etc/systemd/system/redis_exporter.service
[Unit]
Description=redis_exporter
Documentation=https://github.com/prometheus/redis_exporter
After=local-fs.target network-online.target network.target
Wants=local-fs.target network-online.target network.target
 
[Service]
User=root
Group=root
Type=simple
ExecStart=/opt/redis_exporter/redis_exporter -log.level=debug -log-format='txt' -redis.addr=192.168.11.253:6379 -redis.password=YOU_password

Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload && systemctl enable --now redis_exporter

firewall-cmd --zone=public --add-port=9121/tcp --permanent && firewall-cmd --zone=public --add-port=6379/tcp --permanent  && firewall-cmd --reload

mysqld_exporter 一键监控安装脚本

  • host=YOU_IP
  • port=3306
  • user=root
  • password=root
#!/bin/sh
# -*- coding: utf-8 -*-
# Date: 2022/11/17

wget -N -P /opt/ https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz

tar -xf /opt/mysqld_exporter-0.14.0.linux-amd64.tar.gz -C /opt/ && mv /opt/mysqld_exporter-0.14.0.linux-amd64 /opt/mysqld_exporter

cat << EOF > /opt/mysqld_exporter/.my.cnf
[client]
host=192.168.11.98
port=3306
user=root
password=root
EOF

firewall-cmd --zone=public --add-port=9104/tcp --permanent && firewall-cmd --reload 

cat << EOF > /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
Documentation=https://prometheus.io/
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
ExecStart=/opt/mysqld_exporter/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter/.my.cnf

Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload && systemctl enable --now mysqld_exporter

Windows 监控安装,Prometheus数据采集设置

以上是关于prometheus exporter 监控主机的主要内容,如果未能解决你的问题,请参考以下文章

prometheus 监控liunx主机

Prometheus + Node Exporter + Grafana 监控主机运行信息

Prometheus安装和配置node_exporter监控主机

prometheus exporter 监控主机

使用 prometheus 监控主机

使用 prometheus 监控主机