微信公众号:运维开发故事,作者:wanger
使用zabbix有多种方式可以监控ceph集群,这里依次介绍一下,本文只是提供监控ceph的思路或者方法,不涉及详细的配置
从zabbix5.0开始,zabbix agent2开始支持对ceph的监控,ceph提供了Restful的模块,利用restful模块调用命令获取ceph的相关状态,restful模块的监听端口为8003,关于此模块的使用方法可以参考这个文档,ceph restful模块使用文档
接下来介绍使用此模块的方法
ceph mgr module enable restful
此命令生成的是自签证书
ceph restful create-self-signed-cert
zabbix为创建的用户名
ceph restful create-key zabbix
查看所有的api 密钥
ceph restful list-keys

验证api用户是否可用,ceph-mgr为所在mgr节点的主机名或IP,端口8003
curl -k https://api:52dffd92-a103-4a10-bfce-5b60f48f764e@<ceph-mgr>:<port>/server

将url修改为mgr所在的host,

由于刚才用的是自签证书,所以需要修改配置文件来跳过TLS的验证
vim /etc/zabbix/zabbix_agent2.conf
Plugins.Ceph.InsecureSkipVerify=true
systemctl restart zabbix-agent2
可以看到已经收集到数据了

但是使用这种方法有一个问题
使用restful模块调用ceph pg dump
命令时访问拒绝

查看官方论坛ceph模板的主题发现有其他人也遇到了这个问题


zabbix的开发人员也在帖子后面回复说是最近版本会解决这个问题,不过这个问题应该跟zabbix无关,而是pg dump拒绝了mgr的访问

从ceph Luminous版本起,ceph-mgr开始提供zabbix模块用于对ceph的监控,接下来介绍使用此模块的方法
rpm -Uvh https://repo.zabbix.com/zabbix/5.2/rhel/7/x86_64/zabbix-release-5.2-1.el7.noarch.rpm
yum install zabbix-sender -y
ceph mgr module enable zabbix
ceph zabbix config-set zabbix_host 192.168.2.24
ceph zabbix config-set identifier node1
ceph zabbix config-show
我们可以从zabbix模块的源码目录获取模板,模板位置位于,导入之后链接模板即可
/usr/share/ceph/mgr/zabbix/zabbix_template.xml
可以看到zabbix上已经获取到数据了
ceph zabbix send

源码目录位于/usr/share/ceph/mgr/zabbix/module.py,可以看到其实是使用了mgr_module模块来获取ceph的数据,支持如下的传入参数

如果有其他的监控需求可以直接通过在module.py中传入参数来返回对应信息

可以使用shell或者python脚本来调用ceph命令或者利用Restful模块来进行监控,网上也有很多开源的自定义脚本可以参考。这里不多介绍