patternMinor
Deriving an item value from a structured file in Zabbix
Viewed 0 times
itemfilederivingvaluestructuredzabbixfrom
Problem
Zabbix's builtin items for monitoring system parameters are reasonably rich, but there are occasionally things it doesn't seem to make trivial to obtain, such as how many dirty cache pages there are.
For example, consider
What I want is 39620, from the
I could do this with a UserParameter:
and then access the value with the item key
I'd prefer not to use a UserParameter for this, though, as UserParameter require me to deploy additional configuration to each node, and also the process spawns consume system entropy. Both are things I generally prefer to avoid.
For example, consider
/proc/meminfo on your typical Linux system:Inactive(file): 1348288 kB
Unevictable: 18876 kB
Mlocked: 18876 kB
SwapTotal: 8388604 kB
SwapFree: 8388604 kB
Dirty: 39620 kB
Writeback: 948 kB
AnonPages: 6184596 kB
Mapped: 5319216 kB
Shmem: 427020 kB
Slab: 741476 kB
SReclaimable: 633088 kB
SUnreclaim: 108388 kB
KernelStack: 14528 kB
PageTables: 118816 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 16575460 kB
Committed_AS: 19184632 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 9692684 kB
DirectMap2M: 7049216 kBWhat I want is 39620, from the
Dirty line. With a combination of sed and grep, this would be as simple as export field=Dirty; grep -e "$field:" /proc/meminfo | sed -e "s/^$field: \+\([0-9]\)\+.*$/\1/"; fairly straightforward.I could do this with a UserParameter:
UserParameter=proc.meminfo[*], grep -e "$1:" /proc/meminfo | sed -e "s/^$1: \+\([0-9]\)\+.*$/\1/"and then access the value with the item key
proc.meminfo[Dirty].I'd prefer not to use a UserParameter for this, though, as UserParameter require me to deploy additional configuration to each node, and also the process spawns consume system entropy. Both are things I generally prefer to avoid.
Solution
If your Zabbix agent is 2.2 or later, you could use Zabbix agent item
If your Zabbix is 3.4 or later, you can use a master item to collect the data blob (perhaps with
vfs.file.regexp like so:vfs.file.regexp[/proc/meminfo,^Dirty.*([0-9]+),,,,\1]If your Zabbix is 3.4 or later, you can use a master item to collect the data blob (perhaps with
vfs.file.contents) and then extract and parse the desired values with item value preprocessing.Code Snippets
vfs.file.regexp[/proc/meminfo,^Dirty.*([0-9]+),,,,\1]Context
StackExchange DevOps Q#1176, answer score: 3
Revisions (0)
No revisions yet.