prometheus+node_exporter监控系统搭建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了prometheus+node_exporter监控系统搭建相关的知识,希望对你有一定的参考价值。
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监控系统搭建的主要内容,如果未能解决你的问题,请参考以下文章
grafana+prometheus+node_exporter+linux
Prometheus+node_exporter+grafana
Prometheus node_exporter设置开机启动服务
prometheus+node_exporter监控系统搭建