Extending Zabbix Monitoring with Custom Scripts and Handling Stale NFS Handles
This article explains how Zabbix monitoring can be extended with custom shell or Python scripts to gather business-specific metrics, demonstrates a sample script that checks disk usage, and provides three methods to resolve a stale NFS file handle error, including using fuser, process inspection, and forced unmount.
Zabbix monitoring supports custom scripts and self‑made templates to extend its capabilities, allowing you to monitor business‑specific metrics by writing scripts in shell, Python, or other languages.
Below is an example of a debug‑run shell script that checks disk usage and evaluates a threshold:
[root@mha ~]# sh -x watch_disk.sh
++ df -k
++ grep centos-root
++ awk '{print $4}'
df: ‘/NFS’: Stale file handle
+ Disk=320455292
+ [ 320455292 -le 83886080 ]
+ echo 1
1The script captures the output of df -k , filters the relevant line, extracts the free space column, and compares it against a predefined limit. In this run the NFS mount returned a “Stale file handle” error, causing the script to treat the free space as a large value.
To resolve the stale NFS handle, three approaches are suggested:
Kill the processes using the mount point: fuser -k /NFS
Search for processes holding the directory: ps -ef | awk '{print $2}' | grep -v PID | xargs /usr/proc/bin/pwdx
Force unmount the NFS share: umount -f /NFS
The article concludes with a list of recommended reading links covering topics such as Kubernetes deployment, Ansible roles, and other DevOps practices.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.