Answers: <p>If your Zabbix agent is 2.2 or later, you could use <a href="https://www.zabbix.com/documentation/3.0/manual/config/items/itemtypes/zabbix_agent" rel="nofollow noreferrer">Zabbix agent item</a> <code>vfs.file.regexp</code> like so:</p>
  
  <pre><code>vfs.file.regexp[/proc/meminfo,^Dirty.*([0-9]+),,,,\1]
  </code></pre>
  
  <p>If your Zabbix is 3.4 or later, you can use a <a href="https://www.zabbix.com/documentation/4.0/manual/config/items/itemtypes/dependent_items" rel="nofollow noreferrer">master item</a> to collect the data blob (perhaps with <code>vfs.file.contents</code>) and then extract and parse the desired values with <a href="https://www.zabbix.com/documentation/3.4/manual/config/items/item#item_value_preprocessing" rel="nofollow noreferrer">item value preprocessing</a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2017-05-16T16:17:20.517Z
Answers: 2018-12-19T11:46:14.013Z
Answers: 2018-12-19T11:46:14.013Z
Answers: Richlv
Body: <p>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.</p>
  
  <p>For example, consider <code>/proc/meminfo</code> on your typical Linux system:</p>
  
  <pre><code>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 kB
  </code></pre>
  
  <p>What I want is 39620, from the <code>Dirty</code> line. With a combination of <code>sed</code> and <code>grep</code>, this would be as simple as <code>export field=Dirty; grep -e "$field:" /proc/meminfo  | sed -e "s/^$field: \+\([0-9]\)\+.*$/\1/"</code>; fairly straightforward.</p>
  
  <p>I <em>could</em> do this with a UserParameter:</p>
  
  <pre><code>UserParameter=proc.meminfo[*], grep -e "$1:" /proc/meminfo | sed -e "s/^$1: \+\([0-9]\)\+.*$/\1/"
  </code></pre>
  
  <p>and then access the value with the item key <code>proc.meminfo[Dirty]</code>.</p>
  
  <p>I'd <em>prefer</em> 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.</p>
  
Tags: <monitoring>
Title: Deriving an item value from a structured file in Zabbix
UserDisplayName: Michael Mol
ThreadText: # Deriving an item value from a structured file in Zabbix
  
  (Asked by: username_0 on 2017-05-16)
  
  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 `/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 kB
  
  ```
  
  What 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.
  
  **Tags:** monitoring
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-05-16. Score: 3 | Accepted answer
  
  If your Zabbix agent is 2.2 or later, you could use [Zabbix agent item](https://www.zabbix.com/documentation/3.0/manual/config/items/itemtypes/zabbix_agent) `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](https://www.zabbix.com/documentation/4.0/manual/config/items/itemtypes/dependent_items) to collect the data blob (perhaps with `vfs.file.contents`) and then extract and parse the desired values with [item value preprocessing](https://www.zabbix.com/documentation/3.4/manual/config/items/item#item_value_preprocessing).
  
  
  ---
  
  