1. centreon的排除选项
centreon通过snmp检测磁盘默认是检测所有挂载点的,包括linux下内存文件系统的挂载点,如:
代码语言:javascript复制$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VMs01-vm--103--disk--1 8191416 1126588 6629016 15% /
none 492 0 492 0% /dev
tmpfs 131868412 0 131868412 0% /dev/shm
tmpfs 131868412 24656 131843756 1% /run
tmpfs 5120 0 5120 0% /run/lock
tmpfs 131868412 0 131868412 0% /sys/fs/cgroup
tmpfs 26373680 0 26373680 0% /run/user/108
$ ./centreon_plugins.pl --hostname 192.168.100.100 --plugin os::linux::snmp::plugin --mode storage --snmp-community public
OK: All storages are ok | 'count'=6;;;0; 'used_/'=19601375232B;;;0;105152176128 'used_/dev'=0B;;;0;503808 'used_/dev/shm'=0B;;;0;135033253888 'used_/run'=253915136B;;;0;135033253888 'used_/sys/fs/cgroup'=0B;;;0;135033253888 'used_/run/user/0'=0B;;;0;859414528
输出显示检测了6个挂载点(检测输出count=6),其中除了根文件系统"/"之外另外5个tmpfs都是不希望检测的。
排除方法是使用"--storage"选项指定(实际通常使用正则表达式排除)挂载点,"--storage"需要和"--name --regexp"配合使用,如:
代码语言:javascript复制$ ./centreon_plugins.pl --hostname 192.168.100.100 --plugin os::linux::snmp::plugin --mode storage --snmp-community public --name --regexp --storage='^(?!(/dev|/run|/sys))'
OK: Storage '/' Usage Total: 97.93 GB Used: 18.26 GB (18.64%) Free: 79.68 GB (81.36%) | 'count'=1;;;0; 'used'=19601432576B;;;0;105152176128
这样就排除了以"/dev","/run","/sys"开头的挂载点,只检测根分区"/"。(检测输出count=1)
2. icinga2的配置
之后在icinga2里面配置检测主机,当然要先在该主机上启动snmpd服务。
2.1 配置一个检测命令
前面讲过集成centreon-plugins,这里直接调用。为了告警,设置两个等级的阈(yu)值,如:
代码语言:javascript复制object CheckCommand "check-linux-snmp-disk" {
import "ipv4-or-ipv6"
command = [ PluginDir "/thirdparty/centreon-plugins/centreon_plugins.pl" ]
arguments = {
"--plugin" = "os::linux::snmp::plugin"
"--mode" = "storage"
"--host" = "$address$"
"--snmp-community" = "$snmp_community$"
"--snmp-version" = "$snmpVers$"
"--warning-usage" = {
value = "$usage_warning$"
}
"--critical-usage" = {
value = "$usage_critical$"
}
"--storage" = {
value = "$usage_mount$"
}
"--regexp" = {
value = "--regexp"
skip_key = true
}
"--name" = {
value = "--name"
skip_key = true
}
}
vars.usage_mount = "^(?!(/dev|/run|/sys))"
}
2.2 配置主机
增加snmp community
代码语言:javascript复制object Host "hostnameXXX" {
display_name = "XXX系统"
address = "192.168.100.100"
......
vars.snmp_community = "public"
......
}
2.3 配置检测服务
代码语言:javascript复制apply Service "disk"{
display_name = "磁盘使用率"
import "generic-service"
check_command = "check-linux-snmp-disk"
vars.check_command = "disk"
vars.mode = "storage"
if (host.vars.usage_warning) {
vars.usage_warning = host.vars.usage_warning
} else {
vars.usage_warning = "80"
}
if (host.vars.usage_critical) {
vars.usage_critical = host.vars.usage_critical
} else {
vars.usage_critical = "90"
}
assign where (host.vars.client_endpoint == "icinga2-satellite-xxx" && host.vars.snmp_community && host.vars.os )
}
2.4 图形化
如果喜欢图形化,可以采集数据交给grafana展示,或者把grafana集成到icinga2里面