(1) 安装Redis 服务器并确保它能正常的响应请求

root@kvm:~# apt-get install -y redis-server
...
root@kvm:~# redis-cli ping
PONG

(2)安装Rabbitq 服务器

root@kvm:~# apt-get install -y rabbitmq-server
...

(3)创建虚拟主机,Sensu agent将会订阅和授预它用rabbitmq 客户端连接的权限。

root@kvm:~# rabbitmqctl add_vhost /sensu
Creating vhost "/sensu" ...
...done.
root@kvm:~# rabbitmqctl add_user sensu secret
Creating user "sensu" ...
...done.
root@kvm:~# rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*"
Setting permissions for user "sensu" in vhost "/sensu" ...
...done.

(4)添加Sensu的库,我们好利用这个库进行安装。

root@kvm:~# wget -q https://sensu.global.ssl.fastly.net/apt/pubkey.gpg -O- | apt-key add -
OK
root@kvm:~# echo "deb https://sensu.global.ssl.fastly.net/apt sensu main" | tee /etc/apt/sources.list.d/sensu.list
deb https://sensu.global.ssl.fastly.net/apt sensu main
root@kvm:~# apt-get update
...
root@kvm:~# apt-get install -y sensu
...

(5) 创建 Sensu API配置文件

root@kvm:/etc/sensu/conf.d# cat api.json
{
 "api": {
   "host": "localhost",
   "bind": "0.0.0.0",
   "port": 4567
 }
}

(6)配置Sensu传送 的类型 ,我们这里使用的是Rabbitmq

root@kvm:/etc/sensu/conf.d# cat transport.json
{
 "transport": {
   "name": "rabbitmq",
   "reconnect_on_error": true
 }
}

(7)配置rabbitmq服务允许接受连接

root@kvm:/etc/sensu/conf.d# cat rabbitmq.json
{
 "rabbitmq": {
   "host": "0.0.0.0",
   "port": 5672,
   "vhost": "/sensu",
   "user": "sensu",
   "password": "secret"
 }
}

(8)指定Redis服务侦听的IP和端口。

root@kvm:/etc/sensu/conf.d# cat redis.json
{
 "redis": {
   "host": "localhost",
   "port": 6379
 }
}

(9)配置Sensu的客户端

root@kvm:/etc/sensu/conf.d# cat client.json
{
 "client": {
   "name": "ubuntu",
   "address": "127.0.0.1",
   "subscriptions": [
     "base"
   ],
   "socket": {
     "bind": "127.0.0.1",
     "port": 3030
   }
 }
}

(10)安装Sensu的前端,叫做Uchiwa:

root@kvm:/etc/sensu/conf.d# apt-get install -y uchiwa
...

(11)配置Uchiwa的前端

root@kvm:/etc/sensu/conf.d# cat /etc/sensu/uchiwa.json
{
  "sensu": [
    {
      "name": "KVM guests",
      "host": "localhost",
      "ssl": false,
      "port": 4567,
      "path": "",
      "timeout": 5000
    }
  ],
 "uchiwa": {
   "port": 3000,
   "stats": 10,
   "refresh": 10000
 }
}

(12)开启Sensu 服务器,API,客户端和前端组件

root@kvm:/etc/sensu/conf.d# /etc/init.d/sensu-server start
 * Starting sensu-server [ OK ]
root@kvm:/etc/sensu/conf.d# /etc/init.d/sensu-api start
 * Starting sensu-api [ OK ]
root@kvm:/etc/sensu/conf.d# /etc/init.d/sensu-client start
 * Starting sensu-client [ OK ]
root@kvm:/etc/sensu/conf.d# /etc/init.d/uchiwa restart
uchiwa started.

(13)连接KVroot@kvm:/etc/sensu/conf.d# /etc/init.d/sensu-server start

 * Starting sensu-server [ OK ]
root@kvm:/etc/sensu/conf.d# /etc/init.d/sensu-api start
 * Starting sensu-api [ OK ]
root@kvm:/etc/sensu/conf.d# /etc/init.d/sensu-client start
 * Starting sensu-client [ OK ]
root@kvm:/etc/sensu/conf.d# /etc/init.d/uchiwa restart
uchiwa started.

(14)开启Sensu 客户端

root@debian:/etc/sensu/conf.d# /etc/init.d/sensu-client start
Starting sensu-client:.

(15)连接Uchiwa接口,确保host Sensu 客户端和KVM Guest 客户端显示在Client区域。

使用Sensu监控KVM实例_第1张图片

(16)下面我们安装内存检测的的插件,来确保服务正常能运行

root@debian:/etc/sensu/conf.d# apt install rubygems
...
root@debian:/etc/sensu/conf.d# gem search sensu | grep plugins | grep memory
sensu-plugins-memory (0.0.2)
sensu-plugins-memory-checks (2.1.0)
root@debian:/etc/sensu/conf.d#
root@debian:/etc/sensu/conf.d# gem install sensu-plugins-memory-checks
...
root@debian:/etc/sensu/conf.d# /etc/init.d/sensu-client restart
configuration is valid
Stopping sensu-client:.
Starting sensu-client:.
oot@debian:/etc/sensu/conf.d# /usr/local/bin/check-memory-percent.rb -w 80 -c 9
MEM OK - system memory usage: 11%
root@debian:/etc/sensu/conf.d#

)

(17)定义KVM的内存检测

root@kvm:/etc/sensu/conf.d# cat check_memory.json
{
  "checks": {
    "memory_check": {
      "command": "/usr/local/bin/check-memory-percent.rb -w 80 -c 90",
      "subscribers": ["base"],
      "handlers": ["default"],
      "interval": 300
    }
  }
}

(18)重新启动Sensu components的组件

root@kvm:/etc/sensu/conf.d# /etc/init.d/uchiwa restart
Killing uchiwa (pid 15350) with SIGTERM
Waiting uchiwa (pid 15350) to die...
Waiting uchiwa (pid 15350) to die...
uchiwa stopped.
uchiwa started.
root@kvm:/etc/sensu/conf.d# /etc/init.d/sensu-server restart
configuration is valid
 * Stopping sensu-server [ OK ]
 * Starting sensu-server [ OK ]
root@kvm:/etc/sensu/conf.d# /etc/init.d/sensu-api restart
configuration is valid
 * Stopping sensu-api [ OK ]
 * Starting sensu-api [ OK ]

(19)现在在Uchiwa的dashboard中,能够显示memory_check。
使用Sensu监控KVM实例_第2张图片