在之前搭建好的環境上繼續部署
資料參考:https://www.cnblogs.com/bigberg/p/10118555.html
在gopath的目錄環境/usr/local/gopath/src/github.com/jiankunking下執行:
git clone https://github.com/jiankunking/zookeeper_exporter.git
進去
make build 后會出現下面的可執行命令
如果是二進制的包,則本身就一個命令,可以直接使用
將命令放入/usr/local/bin備用
cp zookeeper_exporter /usr/local/bin
啟動命令驗證
使用參數如下:
Usage of zookeeper_exporter:
-bind-addr string
bind address for the metrics server (default ":9141")
-log-level string
log level (default "info")
-metrics-path string
path to metrics endpoint (default "/metrics")
-reset-on-scrape
should a reset command be sent to zookeeper on each scrape (default true)
-version
show version and exit
-zookeeper string
host:port for zookeeper socket (default "localhost:2181")
添加host選項效果,如圖
添加方式
啟動腳本
root@localhost ~]# vim /usr/lib/systemd/system/zookeeper_exporter.service
內容如下:
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/zookeeper_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
root@localhost init.d]# vim /etc/init.d/zookeeper_exporter
內容如下:
#!/bin/bash
IP=`ip addr | grep -v virbr |grep -o -e 'inet [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'|grep -v "127.0.0"|awk '{print $2}'`
PORT=2181
COMMAND=/usr/local/bin/zookeeper_exporter
SERVER=zookeeper_exporter
PIDNUM=`pidof $SERVER`
start(){
if [ -z $PIDNUM ];then
$COMMAND -zookeeper $IP:$PORT >/dev/null 2>&1 &
else
echo "$0 is running"
fi
}
stop(){
if [ -z $PIDNUM ];then
echo "$0 is not running"
else
echo "shutting down $0"
kill -9 "$PIDNUM" && echo "PID $PIDNUM was killed."
fi
}
status(){
if [ -z $PIDNUM ];then
echo "$0 is not runing"
else
echo "$0 is runing,it's PID is $PIDNUM"
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "Usage:$0 {start|stop|status|restart}"
;;
esac
用chmod給上面2個腳本加上執行權限chmod +x
允許用戶啟動
systemctl enable zookeeper_exporter.service
然后可以啟動了,方式如下都可以
/etc/init.d/zookeeper_exporter
service zookeeper_exporter start
systemctl start zookeeper_exporter