Zabbix–基础–4.2–进阶–预处理
1、作用1
对原始数据,进行加工处理,达到要求的数据
收集原始值—>预处理—>达到要求的数据—>存入数据库
1.1、案例:CPU使用率
- 收集原始数据:system.cpu.util,idle
- 预处理:return 100 - value
2、作用2
对主监控数据,依赖监控项,进行预处理。提高收集效率。
2.1、需求
收集Linux服务器,/目录,空闲百分比、已使用百分比,总大小、已使用大小
2.2、设置主监控
文件系统主项目
vfs.fs.get
返回的内容如下
[
{
"fsname": "/sys",
"fstype": "sysfs",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/proc",
"fstype": "proc",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/dev",
"fstype": "devtmpfs",
"bytes": {
"total": 4162940928,
"free": 4162940928,
"used": 0,
"pfree": 100,
"pused": 0
},
"inodes": {
"total": 1016343,
"free": 1015990,
"used": 353,
"pfree": 99.96526763110485,
"pused": 0.034732368895146616
}
},
{
"fsname": "/sys/kernel/security",
"fstype": "securityfs",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/dev/shm",
"fstype": "tmpfs",
"bytes": {
"total": 4175319040,
"free": 4175319040,
"used": 0,
"pfree": 100,
"pused": 0
},
"inodes": {
"total": 1019365,
"free": 1019364,
"used": 1,
"pfree": 99.99990189971207,
"pused": 0.00009810028792434506
}
},
{
"fsname": "/dev/pts",
"fstype": "devpts",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/run",
"fstype": "tmpfs",
"bytes": {
"total": 4175319040,
"free": 4163162112,
"used": 12156928,
"pfree": 99.70883834544054,
"pused": 0.29116165455945975
},
"inodes": {
"total": 1019365,
"free": 1018109,
"used": 1256,
"pfree": 99.87678603836703,
"pused": 0.12321396163297739
}
},
{
"fsname": "/sys/fs/cgroup",
"fstype": "tmpfs",
"bytes": {
"total": 4175319040,
"free": 4175319040,
"used": 0,
"pfree": 100,
"pused": 0
},
"inodes": {
"total": 1019365,
"free": 1019349,
"used": 16,
"pfree": 99.99843039539321,
"pused": 0.001569604606789521
}
},
{
"fsname": "/sys/fs/cgroup/systemd",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/pstore",
"fstype": "pstore",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/blkio",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/devices",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/cpu,cpuacct",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/hugetlb",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/perf_event",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/memory",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/freezer",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/cpuset",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/pids",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/cgroup/net_cls,net_prio",
"fstype": "cgroup",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/kernel/config",
"fstype": "configfs",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/",
"fstype": "xfs",
"bytes": {
"total": 18238930944,
"free": 14942953472,
"used": 3295977472,
"pfree": 81.9288889128435,
"pused": 18.071111087156496
},
"inodes": {
"total": 8910848,
"free": 8836463,
"used": 74385,
"pfree": 99.16523096342794,
"pused": 0.8347690365720524
}
},
{
"fsname": "/sys/fs/selinux",
"fstype": "selinuxfs",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/proc/sys/fs/binfmt_misc",
"fstype": "autofs",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/kernel/debug",
"fstype": "debugfs",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/dev/hugepages",
"fstype": "hugetlbfs",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/dev/mqueue",
"fstype": "mqueue",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/sys/fs/fuse/connections",
"fstype": "fusectl",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
},
{
"fsname": "/boot",
"fstype": "xfs",
"bytes": {
"total": 1063256064,
"free": 903360512,
"used": 159895552,
"pfree": 84.96170796351085,
"pused": 15.038292036489153
},
"inodes": {
"total": 524288,
"free": 523951,
"used": 337,
"pfree": 99.93572235107422,
"pused": 0.06427764892578125
}
},
{
"fsname": "/run/user/0",
"fstype": "tmpfs",
"bytes": {
"total": 835063808,
"free": 835063808,
"used": 0,
"pfree": 100,
"pused": 0
},
"inodes": {
"total": 1019365,
"free": 1019364,
"used": 1,
"pfree": 99.99990189971207,
"pused": 0.00009810028792434506
}
},
{
"fsname": "/proc/sys/fs/binfmt_misc",
"fstype": "binfmt_misc",
"bytes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 0,
"pused": 0
},
"inodes": {
"total": 0,
"free": 0,
"used": 0,
"pfree": 100,
"pused": 0
}
}
]
2.3、设置依赖监控(/目录空闲百分比)
/目录空闲百分比
fs.pfree
这里fs.pfree是我随便写的,因为最终需要的数据,是通过JSONPath获取,和这个键值fs.pfree没有关系
2.3.1、添加预处理
$[?(@.fsname == '/')]
$[0].inodes.pfree
JSONPath参照
https://www.zabbix.com/documentation/6.0/zh/manual/config/items/preprocessing/jsonpath_functionality
$[?(@.fsname == ‘/’)],获得以下数据
[
{
"fsname": "/",
"bytes": {
"used": 3295977472,
"free": 14942953472,
"total": 18238930944,
"pused": 18.071111087156496,
"pfree": 81.9288889128435
},
"fstype": "xfs",
"inodes": {
"used": 74385,
"free": 8836463,
"total": 8910848,
"pused": 0.8347690365720524,
"pfree": 99.16523096342794
}
}
]
2.4、设置其他依赖项
名称:/目录已使用百分比
键值:fs.pused
添加预处理:
$[?(@.fsname == '/')]
$[0].bytes.pused
名称:/目录总大小
键值:fs.total
添加预处理:
$[?(@.fsname == '/')]
$[0].bytes.total
名称:/目录已使用大小
键值:fs.used
添加预处理:
$[?(@.fsname == '/')]
$[0].bytes.used