Prometheus 安装
安装包下载
Prometheus 官网下载地址
包含Prometheus软件及各种exporter插件
解压安装
tar -xvf prometheus-2.39.1.linux-amd64.tar.gz
配置文件
vi prometheus.yml
# mglobal config
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).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093']
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "/monitor/prometheus-2.39.1.linux-amd64/alerts/*.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# 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'
static_configs:
- targets: ['localhost:9100']
- job_name: 'db-server-windows-sqlserver'
static_configs:
- targets: ['10.16.1.9:9182']
- job_name: 'db-server-windows-oracle'
static_configs:
- targets: ['172.16.1.89:9182']
- job_name: 'db-server-linux-oracle'
static_configs:
- targets: ['172.17.8.32:9100']
注册服务
可参考
linux 自定义服务
vi /etc/init.d/promethues
#!/bin/bash
#Create by:zhangyongze
#为什么不问问神奇的海螺呢丶
# chkconfig: 2345 55 25
# description: Prometheus-server
#
RETVAL=0
PROG="prometheus"
EXEC="/monitor/prometheus-2.39.1.linux-amd64/prometheus"
LOCKFILE="/var/lock/subsys/$PROG"
OPTIONS="--web.listen-address=:7746 --config.file=/monitor/prometheus-2.39.1.linux-amd64/prometheus.yml"
# Source function library.
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
echo "/etc/rc.d/init.d/functions does not exist"
exit 0
fi
start() {
if [ -f $LOCKFILE ]
then
echo "$PROG is already running!"
else
echo -n "Starting $PROG: "
nohup $EXEC $OPTIONS >/dev/null 2>&1 &
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $LOCKFILE && success || failure
echo
return $RETVAL
fi
}
stop() {
echo -n "Stopping $PROG: "
killproc $EXEC
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -r $LOCKFILE && success || failure
echo
}
restart ()
{
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $PROG
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
修改执行权限
chmod 775 /etc/init.d/promethues
设置chkconfig 管理服务
根据服务文件中 # chkconfig: 2345 55 25 设置启动级别
chkconfig --add promethues
检查现有服务启动级别
chkconfig --list
运行Prometheus 服务
service prometheus start
web页面查看
浏览器访问 服务器地址+端口号(服务中配置的)
例如 http://192.168.1.21:7746/
targets 可查看所有监控中exporter