sql_exporter
我们可以将这些数据接入到prometheus
中,进行监控告警。vim /sql_exporter.sh
- #!/bin/bash
- # -*- coding: utf-8 -*-
- # Author: make.han
- # Email: CIASM@CIASM
- # Date: 2024/01/12
-
- OPT_CATALOGUE=/opt
- SQL_EXPORTER_PREFIX=/opt/sql_exporter
- SQL_EXPORTER_URL=https://github.com/free/sql_exporter/releases/download/0.5/sql_exporter-0.5.linux-amd64.tar.gz
- SQL_EXPORTER_GZ=sql_exporter-0.5.linux-amd64.tar.gz
- SQL_EXPORTER_DIRECTORY=sql_exporter-0.5.linux-amd64
- SQL_EXPORTER_NEW=sql_exporter
- SQL_EXPORTER_PORT=9399
-
- install_sql_exporter (){
- if [ ! -d ${SQL_EXPORTER_PREFIX} ];then
-
- # selinux stop
- setenforce 0
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
-
- if [ $? -eq 0 ];then
-
- echo "download sql_exporter"
- curl -o $OPT_CATALOGUE/$SQL_EXPORTER_GZ $SQL_EXPORTER_URL
-
- echo "decompression sql_exporter"
- tar -xf $OPT_CATALOGUE/$SQL_EXPORTER_GZ -C $OPT_CATALOGUE
- mv $OPT_CATALOGUE/$SQL_EXPORTER_DIRECTORY $SQL_EXPORTER_PREFIX
-
- echo "firewall sql_exporter port"
- firewall-cmd --zone=public --add-port=$SQL_EXPORTER_PORT/tcp --permanent && firewall-cmd --reload
-
- echo "congfig sql_exporter"
- sed -i "s|data_source_name.*|data_source_name: 'sqlserver://sa:YOU_password@YOU_IP:1433'|g" $SQL_EXPORTER_PREFIX/sql_exporter.yml
-
- echo "add sql_exporter.service"
- cat >>/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=$SQL_EXPORTER_PREFIX/sql_exporter --config.file=$SQL_EXPORTER_PREFIX/sql_exporter.yml
- Restart=on-failure
-
- [Install]
- WantedBy=multi-user.target
- EOF
-
- echo "start sql_exporter.service"
- systemctl daemon-reload
- systemctl enable --now sql_exporter
-
- echo -e "\033[32mThe sql exporter Install Sussess...\033[0m"
- else
- echo -e "\033[33mThe sql exporter Install Failed...\033[0m"
- exit 1
- fi
- else
- echo -e "\033[31mThe sql exporter Install already...\033[0m"
- fi
- }
-
- main (){
- install_sql_exporter
- }
-
- main
sh /sql_exporter.sh
- scrape_configs:
- - job_name: 'web'
- scrape_interval: 5s
- static_configs:
- - targets:
- - localhost:9090
- - job_name: 'SQL-monitoring'
- scrape_interval: 5s
- static_configs:
- - targets:
- - 192.168.11.252:9399