prometheus监控zookeeper

在之前搭建好的环境上继续部署

 

资料参考: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

 

原文地址:https://www.cnblogs.com/fatyao/p/11192218.html