Skip to content

Commit

Permalink
Update LVM cache template. Add scripts. Fix import issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlozt committed Dec 30, 2024
1 parent 6e9f003 commit 88b907f
Show file tree
Hide file tree
Showing 10 changed files with 547 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Operating_Systems/Linux/template_lvm_cache/6.0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LVM Cache monitoring template.
==============================


allows you to evaluate the efficiency of caching by the built-in dm-cache mechanism.
Allows you to evaluate the efficiency of caching by the built-in dm-cache mechanism.


**What do these values mean?**
Expand Down Expand Up @@ -74,6 +74,7 @@ There are no discovery rules in this template.
|total_metadata_blocks|<p>-</p>|`Dependent item`|lvmcache.total_metadata_blocks<p>Update: 0</p>|
|total_cache_blocks|<p>-</p>|`Dependent item`|lvmcache.total_cache_blocks<p>Update: 0</p>|
|read_hits|<p>-</p>|`Dependent item`|lvmcache.read_hits<p>Update: 0</p>|
|read_misses|<p>-</p>|`Dependent item`|lvmcache.read_misses<p>Update: 0</p>|
|promotions|<p>-</p>|`Dependent item`|lvmcache.promotions<p>Update: 0</p>|
|lvm raw data|<p>-</p>|`Zabbix agent`|lvmcache.raw<p>Update: 3m</p>|
|write_hits|<p>-</p>|`Dependent item`|lvmcache.write_hits<p>Update: 0</p>|
Expand Down
36 changes: 36 additions & 0 deletions Operating_Systems/Linux/template_lvm_cache/6.0/scripts/lvmcache
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

DMSTRING=$(sudo /usr/sbin/dmsetup status |grep -P -- '\d+\W+cache\W+\d+' | head -1)
# example:
# 11617255424 cache 8 3005/12288 1984 998185/998185 227992434 36220107 294608588 12215083 0 0 861691 3 metadata2 writethrough no_discard_passdown 2 migration_threshold 2048 cleaner 0 rw -

IFS=' ' read -a POS <<< "${DMSTRING}"
metadata_blocksize="${POS[4]}"
used_metadata_blocks="${POS[5]%%/*}"
total_metadata_blocks="${POS[5]##*/}"
cache_block_size="${POS[6]}"
used_cache_blocks="${POS[7]%%/*}"
total_cache_blocks="${POS[7]##*/}"
read_hits="${POS[8]}"
read_misses="${POS[9]}"
write_hits="${POS[10]}"
write_misses="${POS[11]}"
demotions="${POS[12]}"
promotions="${POS[13]}"
dirty="${POS[14]}"



echo "{
\"used_metadata_blocks\": $used_metadata_blocks,
\"total_metadata_blocks\": $total_metadata_blocks,
\"used_cache_blocks\": $used_cache_blocks,
\"total_cache_blocks\": $total_cache_blocks,
\"read_hits\": $read_hits,
\"read_misses\": $read_misses,
\"write_hits\": $write_hits,
\"write_misses\": $write_misses,
\"demotions\": $demotions,
\"promotions\": $promotions,
\"dirty\": $dirty
}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Defaults:zabbix !requiretty
zabbix ALL= (ALL) NOPASSWD: /usr/sbin/dmsetup status
Original file line number Diff line number Diff line change
@@ -1,68 +1,67 @@
zabbix_export:
version: '6.0'
date: '2021-11-21T22:04:12Z'
date: '2024-12-30T00:04:12Z'
groups:
-
uuid: b1a65eeba3cc4c9fb198e8f18f433839
name: 'Templates/Operating Systems'
- uuid: 846977d1dfed4968bc5f8bdb363285bc
name: 'Templates/Operating systems'
templates:
-
uuid: a81a5e460d8e420baab75a080d5f2375
template: 'LVM Cache'
name: 'LVM Cache'
description: |
## Description
LVM cache monitoring Details in kernel documentation https://www.kernel.org/doc/Documentation/device-mapper/cache.txt
## Overview
LVM Cache monitoring template.
==============================
allows you to evaluate the efficiency of caching by the built-in dm-cache mechanism.
**What do these values mean?**
------------------------------
Details about monitored values described in Linux Kernel Documentation <https://www.kernel.org/doc/Documentation/device-mapper/cache.txt>
**Usage**
---------
1. Put file lvmcache.conf to /etc/zabbix/zabbix\_agent.d/
2. Put file sudoers\_lvmcache to /etc/sudoers.d/ (you need `sudo` program installed)
3. Put file vmcache to /etc/zabbix/scripts/. Then you can execut this file and test. This script produces JSON output.
4. Import the [`lvmcache_template.xml`](https://github.com/pavlozt/somezabbixtemplates/blob/master/lvmcache/lvmcache_template.xml) into your Zabbix server (click on the `Raw` button to download)
5. Add the template to your host
6. Check if new data arrives at Last Data section and Graphs.
This script assumes that you have **ONLY ONE caching device** and polls the first device. Therefore, it does not require configuration and specifying a device name. Working with disks implies elevated privileges and therefore you need do not forget about sudoers\_zabbix\_lvmcache file.
**Commands for debugging**
--------------------------
* dmsetup status
* /etc/zabbix/scripts/lvmcache
* zabbix\_get -s 192.168.1.1 -k 'lvmcache.raw' (on zabbix server or zabbix proxy)
## Author
pavlozt
groups:
-
name: 'Templates/Operating Systems'
name: 'Templates/Operating systems'
items:
-
uuid: 6245993545644076a677d67342856d8e
Expand Down Expand Up @@ -174,12 +173,21 @@ zabbix_export:
- ''
master_item:
key: lvmcache.raw
tags:
-
tag: Application
value: 'LVM Cache'
-
uuid: 7f3f12b6642a4afdb91b10ed522144f2
- uuid: a381ae2385e74dafba594395bef7e898
name: read_misses
type: DEPENDENT
key: lvmcache.read_misses
delay: '0'
preprocessing:
- type: JSONPATH
parameters:
- $.read_misses
- type: SIMPLE_CHANGE
parameters:
- ''
master_item:
key: lvmcache.raw
- uuid: 7f3f12b6642a4afdb91b10ed522144f2
name: total_cache_blocks
type: DEPENDENT
key: lvmcache.total_cache_blocks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UserParameter=lvmcache.raw,/etc/zabbix/scripts/lvmcache
86 changes: 86 additions & 0 deletions Operating_Systems/Linux/template_lvm_cache/7.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# LVM Cache

## Description

LVM cache monitoring Details in kernel documentation https://www.kernel.org/doc/Documentation/device-mapper/cache.txt

## Overview

LVM Cache monitoring template.
==============================


Allows you to evaluate the efficiency of caching by the built-in dm-cache mechanism.


**What do these values mean?**
------------------------------


Details about monitored values described in Linux Kernel Documentation <https://www.kernel.org/doc/Documentation/device-mapper/cache.txt>


**Usage**
---------


1. Put file lvmcache.conf to /etc/zabbix/zabbix\_agent.d/
2. Put file sudoers\_lvmcache to /etc/sudoers.d/ (you need `sudo` program installed)
3. Put file vmcache to /etc/zabbix/scripts/. Then you can execut this file and test. This script produces JSON output.
4. Import the [`lvmcache_template.xml`](https://github.com/pavlozt/somezabbixtemplates/blob/master/lvmcache/lvmcache_template.xml) into your Zabbix server (click on the `Raw` button to download)
5. Add the template to your host
6. Check if new data arrives at Last Data section and Graphs.


This script assumes that you have **ONLY ONE caching device** and polls the first device. Therefore, it does not require configuration and specifying a device name. Working with disks implies elevated privileges and therefore you need do not forget about sudoers\_zabbix\_lvmcache file.


**Commands for debugging**
--------------------------


* dmsetup status
* /etc/zabbix/scripts/lvmcache
* zabbix\_get -s 192.168.1.1 -k 'lvmcache.raw' (on zabbix server or zabbix proxy)


## Author

pavlozt

## Macros used

There are no macros links in this template.

## Template links

There are no template links in this template.

## Discovery rules

There are no discovery rules in this template.

## Items collected

|Name|Description|Type|Key and additional info|
|----|-----------|----|----|
|demotions|<p>-</p>|`Dependent item`|lvmcache.demotions<p>Update: 0</p>|
|used_metadata_blocks|<p>-</p>|`Dependent item`|lvmcache.used_metadata_blocks<p>Update: 0</p>|
|write_misses|<p>-</p>|`Dependent item`|lvmcache.write_misses<p>Update: 0</p>|
|dirty|<p>-</p>|`Dependent item`|lvmcache.dirty<p>Update: 0</p>|
|LVM data cache usage|<p>-</p>|`Calculated`|lvmcache.usage<p>Update: 3m</p>|
|LVM meta cache usage|<p>-</p>|`Calculated`|lvmcache.metausage<p>Update: 3m</p>|
|used_cache_blocks|<p>-</p>|`Dependent item`|lvmcache.used_cache_blocks<p>Update: 0</p>|
|total_metadata_blocks|<p>-</p>|`Dependent item`|lvmcache.total_metadata_blocks<p>Update: 0</p>|
|total_cache_blocks|<p>-</p>|`Dependent item`|lvmcache.total_cache_blocks<p>Update: 0</p>|
|read_hits|<p>-</p>|`Dependent item`|lvmcache.read_hits<p>Update: 0</p>|
|read_misses|<p>-</p>|`Dependent item`|lvmcache.read_misses<p>Update: 0</p>|
|promotions|<p>-</p>|`Dependent item`|lvmcache.promotions<p>Update: 0</p>|
|lvm raw data|<p>-</p>|`Zabbix agent`|lvmcache.raw<p>Update: 3m</p>|
|write_hits|<p>-</p>|`Dependent item`|lvmcache.write_hits<p>Update: 0</p>|


## Triggers

There are no triggers in this template.

36 changes: 36 additions & 0 deletions Operating_Systems/Linux/template_lvm_cache/7.0/scripts/lvmcache
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

DMSTRING=$(sudo /usr/sbin/dmsetup status |grep -P -- '\d+\W+cache\W+\d+' | head -1)
# example:
# 11617255424 cache 8 3005/12288 1984 998185/998185 227992434 36220107 294608588 12215083 0 0 861691 3 metadata2 writethrough no_discard_passdown 2 migration_threshold 2048 cleaner 0 rw -

IFS=' ' read -a POS <<< "${DMSTRING}"
metadata_blocksize="${POS[4]}"
used_metadata_blocks="${POS[5]%%/*}"
total_metadata_blocks="${POS[5]##*/}"
cache_block_size="${POS[6]}"
used_cache_blocks="${POS[7]%%/*}"
total_cache_blocks="${POS[7]##*/}"
read_hits="${POS[8]}"
read_misses="${POS[9]}"
write_hits="${POS[10]}"
write_misses="${POS[11]}"
demotions="${POS[12]}"
promotions="${POS[13]}"
dirty="${POS[14]}"



echo "{
\"used_metadata_blocks\": $used_metadata_blocks,
\"total_metadata_blocks\": $total_metadata_blocks,
\"used_cache_blocks\": $used_cache_blocks,
\"total_cache_blocks\": $total_cache_blocks,
\"read_hits\": $read_hits,
\"read_misses\": $read_misses,
\"write_hits\": $write_hits,
\"write_misses\": $write_misses,
\"demotions\": $demotions,
\"promotions\": $promotions,
\"dirty\": $dirty
}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Defaults:zabbix !requiretty
zabbix ALL= (ALL) NOPASSWD: /usr/sbin/dmsetup status
Loading

0 comments on commit 88b907f

Please sign in to comment.