1. 程式人生 > >prometheus+node_exporter監控系統搭建

prometheus+node_exporter監控系統搭建

pidfile rip amd stat rep id號 start ash top

prometheus+node_exporter監控系統搭建:

註:
可結合icinga2、telegraf一起用,Disk IOs、Disk Throughout是前2個沒有的,traffic監控也可用這個

參考網址:http://blog.51cto.com/youerning/2050543

下載網址:
https://prometheus.io/download

服務器端:

tar zxfv prometheus-2.4.0.linux-amd64.tar.gz

mv prometheus-2.4.0.linux-amd64 /space/prometheus

/space/prometheus/prometheus --config.file=/space/prometheus/prometheus.yml --storage.tsdb.path=/space/prometheus/data

另開窗口

netstat -nplt | grep 9090

Redhat 6設置prometheus啟動腳本(只能start,沒有stop和restart):

vi /etc/init.d/prometheus (註意修改路徑和ip)

#!/bin/bash
#

Comments to support chkconfig

chkconfig: 2345 98 02

description: prometheus service script

#

Source function library.

. /etc/init.d/functions

Default variables

prog_name="prometheus"

config_file="/space/${prog_name}/${prog_name}.yml"
prog_path="/space/${prog_name}/${prog_name}"
data_path="/space/${prog_name}/data"
pidfile="/var/run/${prog_name}.pid"
prog_logs="/var/log/${prog_name}.log"
options="--web.listen-address=10.0.0.2:9090 --config.file=${config_file} --web.enable-lifecycle --storage.tsdb.path=${data_path}"
DESC="Prometheus Server"

Check if requirements are met

[ -x "${prog_path}" ] || exit 1

RETVAL=0

start(){
action $"Starting $DESC..." su -s /bin/sh -c "nohup $prog_path $options >> $prog_logs 2>&1 &" 2> /dev/null
RETVAL=$?
PID=$(pidof ${prog_path})
[ ! -z "${PID}" ] && echo ${PID} > ${pidfile}
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog_name
return $RETVAL
}

stop(){
echo -n $"Shutting down $prog_name: "
killproc -p ${pidfile}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog_name
return $RETVAL
}

restart() {
stop
start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status $prog_path
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
esac

:wq

/etc/init.d/prometheus start

chkconfig --level 35 prometheus on

瀏覽器訪問http://ip:9090

被監控端:

tar zxfv node_exporter-0.16.0.linux-amd64.tar.gz

cd node_exporter-0.16.0.linux-amd64

./node_exporter

另開窗口

curl 127.0.0.1:9100/metrics

Ubuntu 14.04設置node_exporter啟動腳本(只能start,沒有stop和restart):

ln -s /root/node_exporter-0.16.0.linux-amd64/node_exporter /usr/bin/

vi /etc/init/node_exporter.conf

Run node_exporter

start on startup

script
/usr/bin/node_exporter
end script
:wq

service node_exporter start

netstat -nplt | grep 9100

Ubuntu 16.04設置node_exporter啟動腳本(只能start,沒有stop和restart):

vi /etc/systemd/system/node-exporter.service

[Unit]
Description=Prometheus Node Exporter
After=network.target

[Service]
ExecStart=/home/node_exporter/node_exporter
User=nobody

[Install]
WantedBy=multi-user.target

:wq

systemctl daemon-reload

systemctl enable node-exporter

systemctl start node-exporter

netstat -ntpl | grep 9100

服務器端:

vi /space/prometheus/prometheus.yml (寫服務器名的話需在/etc/hosts加個本地解析)

- targets: [‘10.0.0.3:9100‘]
- targets: [‘shhua01:9100‘]

:wq

netstat -ntpl | grep 9090

kill pid號

/etc/init.d/prometheus start

訪問http://ip:9090 Status——targets,可看到已監控的服務器列表

集成到Grafana,選擇prometheus,http://ip:9090即可,Grafana官網有prometheus對應的模板可導入使用

prometheus+node_exporter監控系統搭建