使用Sensu监控KVM实例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Sensu监控KVM实例相关的知识,希望对你有一定的参考价值。
(1) 安装Redis 服务器并确保它能正常的响应请求
[email protected]:~# apt-get install -y redis-server
...
[email protected]:~# redis-cli ping
PONG
(2)安装Rabbitq 服务器
[email protected]:~# apt-get install -y rabbitmq-server
...
(3)创建虚拟主机,Sensu agent将会订阅和授预它用rabbitmq 客户端连接的权限。
[email protected]:~# rabbitmqctl add_vhost /sensu
Creating vhost "/sensu" ...
...done.
[email protected]:~# rabbitmqctl add_user sensu secret
Creating user "sensu" ...
...done.
[email protected]:~# rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*"
Setting permissions for user "sensu" in vhost "/sensu" ...
...done.
(4)添加Sensu的库,我们好利用这个库进行安装。
[email protected]:~# wget -q https://sensu.global.ssl.fastly.net/apt/pubkey.gpg -O- | apt-key add -
OK
[email protected]:~# 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
[email protected]:~# apt-get update
...
[email protected]:~# apt-get install -y sensu
...
(5) 创建 Sensu API配置文件
[email protected]:/etc/sensu/conf.d# cat api.json
{
"api": {
"host": "localhost",
"bind": "0.0.0.0",
"port": 4567
}
}
(6)配置Sensu传送 的类型 ,我们这里使用的是Rabbitmq
[email protected]:/etc/sensu/conf.d# cat transport.json
{
"transport": {
"name": "rabbitmq",
"reconnect_on_error": true
}
}
(7)配置rabbitmq服务允许接受连接
[email protected]:/etc/sensu/conf.d# cat rabbitmq.json
{
"rabbitmq": {
"host": "0.0.0.0",
"port": 5672,
"vhost": "/sensu",
"user": "sensu",
"password": "secret"
}
}
(8)指定Redis服务侦听的IP和端口。
[email protected]:/etc/sensu/conf.d# cat redis.json
{
"redis": {
"host": "localhost",
"port": 6379
}
}
(9)配置Sensu的客户端
[email protected]:/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:
[email protected]:/etc/sensu/conf.d# apt-get install -y uchiwa
...
(11)配置Uchiwa的前端
[email protected]:/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,客户端和前端组件
[email protected]:/etc/sensu/conf.d# /etc/init.d/sensu-server start
* Starting sensu-server [ OK ]
[email protected]:/etc/sensu/conf.d# /etc/init.d/sensu-api start
* Starting sensu-api [ OK ]
[email protected]:/etc/sensu/conf.d# /etc/init.d/sensu-client start
* Starting sensu-client [ OK ]
[email protected]:/etc/sensu/conf.d# /etc/init.d/uchiwa restart
uchiwa started.
(13)连接[email protected]:/etc/sensu/conf.d# /etc/init.d/sensu-server start
* Starting sensu-server [ OK ]
[email protected]:/etc/sensu/conf.d# /etc/init.d/sensu-api start
* Starting sensu-api [ OK ]
[email protected]:/etc/sensu/conf.d# /etc/init.d/sensu-client start
* Starting sensu-client [ OK ]
[email protected]:/etc/sensu/conf.d# /etc/init.d/uchiwa restart
uchiwa started.
(14)开启Sensu 客户端
[email protected]:/etc/sensu/conf.d# /etc/init.d/sensu-client start
Starting sensu-client:.
(15)连接Uchiwa接口,确保host Sensu 客户端和KVM Guest 客户端显示在Client区域。
(16)下面我们安装内存检测的的插件,来确保服务正常能运行
[email protected]:/etc/sensu/conf.d# apt install rubygems
...
[email protected]:/etc/sensu/conf.d# gem search sensu | grep plugins | grep memory
sensu-plugins-memory (0.0.2)
sensu-plugins-memory-checks (2.1.0)
[email protected]:/etc/sensu/conf.d#
[email protected]:/etc/sensu/conf.d# gem install sensu-plugins-memory-checks
...
[email protected]:/etc/sensu/conf.d# /etc/init.d/sensu-client restart
configuration is valid
Stopping sensu-client:.
Starting sensu-client:.
[email protected]:/etc/sensu/conf.d# /usr/local/bin/check-memory-percent.rb -w 80 -c 9
MEM OK - system memory usage: 11%
[email protected]:/etc/sensu/conf.d#
)
(17)定义KVM的内存检测
[email protected]:/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的组件
[email protected]:/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.
[email protected]:/etc/sensu/conf.d# /etc/init.d/sensu-server restart
configuration is valid
* Stopping sensu-server [ OK ]
* Starting sensu-server [ OK ]
[email protected]:/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实例的主要内容,如果未能解决你的问题,请参考以下文章
通过python获取kvm虚拟机的监控信息(基于libvirt API)
ruby sensu_standalone_check.rb