【环境介绍】
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# Here it\'s Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: \'prometheus\'
# scheme defaults to \'http\'.
- targets: [\'localhost:9090\']
- job_name: linux
static_configs:
- targets: [\'10.0.0.166:9100\']
labels:
instance: linux_10.0.0.166
#!/bin/bash
BASEPATH=/home/prometheus/prometheus
LOG=$BASEPATH/logs
nohup $BASEPATH/prometheus --config.file=$BASEPATH/conf/prometheus.yml --web.listen-address=:9090 --storage.tsdb.path=$BASEPATH/data/ --storage.tsdb.retention=5d >> $LOG/prometheus.log 2>&1 & echo $! > $BASEPATH/run/prometheus.pid
PROC=`ps -ef |grep \`cat $BASEPATH/run/prometheus.pid\` |grep -v grep`
echo "##########################################"
echo "Process not found, please check by yourself"
echo "##########################################"
else
echo "##########################################"
echo "Prometheus is running"
echo "##########################################"
fi
4,安装node_exporter,mysqld_exporter,oracledb_exporter
cd /home/prometheus/
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz
wget https://github.com/iamseth/oracledb_exporter/releases/download/0.2.9/oracledb_exporter.0.2.9-ora18.5.linux-amd64.tar.gz
解压到指定export目录:
tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C prometheus_exporter/
cd /home/prometheus/prometheus_exporter/node_exporter-1.0.1.linux-amd64
nohup ./node_exporter &
cd prometheus_exporter/mysqld_exporter-0.12.1.linux-amd64
GRANT REPLICATION CLIENT, PROCESS ON *.* TO mysql_monitor@\'%\';
GRANT SELECT ON performance_schema.* TO mysql_monitor@\'%\';
[client]
host=localhost
port=3306
user=mysql_monitor
password=Mysql_monitor123
https://www.oracle.com/cn/database/technologies/instant-client/linux-x86-64-downloads.html
Preparing... ################################# [100%]
Updating / installing...
1:oracle-instantclient19.5-basic-19################################# [100%]
[root@oracle21 prometheus_exporter]# cd /usr/lib/oracle/19.3/client64/network/admin
-bash: cd: /usr/lib/oracle/19.3/client64/network/admin: No such file or directory
[root@oracle21 prometheus_exporter]# cd /usr/lib/oracle/19.5/client64/
[root@oracle21 client64]# ls -trl
total 4
drwxr-xr-x 2 root root 33 Aug 13 09:54 bin
drwxr-xr-x 3 root root 4096 Aug 13 09:54 lib
[root@oracle21 client64]# mkdir -p network/admin/
[root@oracle21 client64]# cd network/admin/
[root@oracle21 admin]# cat >tnsnames.ora
oratest =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.166)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oratest)
)
)
[root@oracle21 admin]#
vim ~/.bash_profile
export ORACLE_HOME=/usr/lib/oracle/19.5/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=\'simplified chinese_china\'.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
grant connect,dba,select any table to oracle_monitor;
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# pwd
/home/prometheus/prometheus_exporter/oracledb_exporter.0.2.9-ora18.5.linux-amd64
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# export DATA_SOURCE_NAME=oracle_monitor/Oracle_monitor123@oratest
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# nohup ./oracledb_exporter &
[1] 2623
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# nohup: ignoring input and appending output to ‘nohup.out’
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]# ps -ef |grep oracledb_exporter
root 2623 32023 0 10:01 pts/0 00:00:00 ./oracledb_exporter
root 2669 32023 0 10:01 pts/0 00:00:00 grep --color=auto oracledb_exporter
[root@oracle21 oracledb_exporter.0.2.9-ora18.5.linux-amd64]#
- targets: [\'localhost:9090\']
- job_name: linux
static_configs:
- targets: [\'10.0.0.166:9100\']
labels:
instance: linux_10.0.0.166
- job_name: mysql
static_configs:
- targets: [\'10.0.0.166:9104\']
labels:
instance: mysql_10.0.0.166
static_configs:
- targets: [\'10.0.0.166:9161\']
labels:
instance: oracle_10.0.0.166
##########################################
Prometheus is running
##########################################
[root@oracle21 prometheus]#
5,安装grafana
这里使用RPM安装
wget https://dl.grafana.com/oss/release/grafana-7.1.3-1.x86_64.rpm
yum install grafana-7.1.3-1.x86_64.rpm
$ systemctl daemon-reload
$ systemctl start grafana-server
$ systemctl status grafana-server
访问网址是否正常
http://10.0.0.166:3000 用户密码为admin admin
6,导入对应的仪表盘效果如下
下载对应的仪表盘:https://grafana.com/grafana/dashboards
主机:
MySQL:
Oracle:
7,遇到的问题
使用之前查看的批量导入MySQL仪表盘显示需要安装插件,该插件本身自带,解决办法直接下载最新的仪表盘导入即可;
Oracle数据库采集数据异常,查看为查询表空间耗时很久,在数据库层面清理回收站即可;
Linux6安装监控异常,为需要安装Linux需要支持2.14 strings /lib64/libc.so.6 |grep GLIBC_ linux6需要升级
下载glibc-2.14.tar.gz http://ftp.gnu.org/gnu/glibc/
注意新的版本一定得用其他目录,防止覆盖原版本导致系统异常:
mkdir -p /root/soft/glibc
gunzip glibc-2.14.tar.gz
tar -xvf glibc-2.14.tar
cd glibc-2.14
mkdir build
cd build
../configure --prefix=/root/soft/glibc
make -j4
make install
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/root/soft/glibc/lib