Monitoring LVM Thin Volume Pool using Zabbix

From Notes_Wiki

Home > Debian > Proxmox virtual environment > Monitoring LVM Thin Volume Pool using Zabbix

Home > CentOS > CentOS 8.x > Monitoring > Zabbix > Monitoring LVM Thin Volume Pool using Zabbix


We can Monitor LVM Thin Volume Pool using Zabbix custom script

Zabbix Agent Script and Configuration

Create a new script in zabbix folder

# nano /etc/zabbix/script.sh

Script

#!/bin/bash

# Get LVM thin pool usage
disk_usage=$(sudo lvdisplay -v /dev/ssdvg/ssdlv | grep "Allocated pool data" | awk '{print $4}' | tr -d '%')

# Output the numeric value
echo "$disk_usage"

# Check if usage exceeds threshold (e.g., 80%)
if (( $(echo "$disk_usage > 80" | bc -l) )); then
    exit 1
fi

exit 0

Make the script executable and change owner to zabbix user

# chmod +x /etc/zabbix/script.sh

# chown -R zabbix:zabbix /etc/zabbix/script.sh

Install sudo package

# apt install sudo

Edit the configuration file

# nano /etc/zabbix/zabbix_agentd.conf

Add the following lines at the bottom in the following positions

### Option: EnableRemoteCommands - Deprecated, use AllowKey=system.run[*] or DenyKey=system.run[*] instead
 AllowKey=system.run[*]

### Option: UnsafeUserParameters
 UnsafeUserParameters=1

### Option: UserParameter
 UserParameter=custom.script,/etc/zabbix/script.sh

Restart the service

# systemctl restart zabbix-agent

Add the zabbix user in sudoers file

# visudo
   
 zabbix  ALL=(ALL) NOPASSWD: /sbin/lvdisplay

Zabbix Web Interface (UI) Setup

  • Login as Admin to Zabbix web UI
    • Navigate to the host list in Zabbix for configuration.
  • Click on Host Name
    • Select the specific Proxmox host to monitor.
  • Select Items tab
  • Create New Item (Top Right Button)
  • Set Item Name, Type, and Key
  • Example:
  Name: lvm-script
  Type: zabbix-agent
  Key: custom.script
  Type of Information: Numeric (float)
  Update Interval: 15m
  • Test the configuration with “Get Value and Test
    • Verify that Zabbix can correctly retrieve and display the script output.
  • Click Add to save the Item

Setting Up Trigger and Alerting

  • Go to Triggers and click Create Trigger
  • Define Trigger Name, Severity, and Expression
  • Example
 Name: Proxmox: lvm storage above 80%
 Severity: High
 Expression: last(/proxtest/custom.script)>80
  • Use Expression Constructor to validate
    • The expression will be saved when there are no errors
  • Click Add/Update to save the trigger
  • Go to Alerts > Actions > Trigger actions
  • Create New Action
  • Set Action Name and Add Condition
  • Condition Example
Type: Trigger severity
Operator: is greater than or equals
Severity; High
  • Select operations, Click Add under operation field
  • In Operation details
 Steps: 1 - 1
 Step duration: 0
 Send to user groups: Zabbix administrators
 Send only to: All
  • Select Add under Recovery operations field
  • In Operation details
 Operation: Notify all invovled
  • Click Update/Add to the trigger action

Testing and Alert Verification

  • Simulate alert by forcing disk_usage=85

comment the following line in script:

disk_usage=$(sudo lvdisplay -v /dev/ssdvg/ssdlv | grep "Allocated pool data" | awk '{print $4}' | tr -d '%')

and add the following line:

disk_usage=85
  • Email alert is received
  • Comment the previously added line and uncomment the main line, to resolve the error.
  • Resolved status is received in alert



Home > Debian > Proxmox virtual environment > Monitoring LVM Thin Volume Pool using Zabbix

Home > CentOS > CentOS 8.x > Monitoring > Zabbix > Monitoring LVM Thin Volume Pool using Zabbix