Zabbix application Low-level discovery monitoring disk IO

Source: Internet
Author: User
Tags egrep

Zabbix's "template OS Linux" Templates support monitoring mounted disk space utilization, which is implemented using LLD (low-level discovery) without disk IO monitoring. This article describes the method of monitoring disk IO using the Zabbix LLD function.

idea : First create discovery rules, configure the corresponding userparameter on the agent side, invoke the well-written shell script, dynamically find out the mounted disk partition, and then create the item prototypes, using Vfs.dev.read[device,<type>,<mode>] and Vfs.dev.write[device,<type>,<mode>] To monitor disk partition IO, including disk read and write rates, number of read-write sectors per second, read and write operations per second, and then create graph prototypes to generate disk IO graphs.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/30/wKiom1SrfI7Ck94QAAVYlQSogRw530.jpg "title=" History.png "alt=" Wkiom1srfi7ck94qaavylqsogrw530.jpg "/>

Disk read/write rate:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/2E/wKioL1Srlk3jjHPpAALFZQoinzs867.jpg "title=" 1.png " alt= "Wkiol1srlk3jjhppaalfzqoinzs867.jpg"/>

Number of read/write sectors per second on disk:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/31/wKiom1SrlZzShsciAALhGqG-xEc215.jpg "title=" 2.png " alt= "Wkiom1srlzzshsciaalhgqg-xec215.jpg"/>

Number of read/write operations per second on disk:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/31/wKiom1SrlamSrDbtAAM4ADAbjhA423.jpg "title=" 3.png " alt= "Wkiom1srlamsrdbtaam4adabjha423.jpg"/>

Specific monitoring steps are given below:

I. Scripting to find mounted disk partitions

    1) Create a script to find the disk partition in the Zabbix client /etc/zabbix/monitor_scripts directory, the contents are as follows:

#!/bin/bash#function: low-level discovery mounted disk#script_name: mount_disk_ Discovery.sh mount_disk_discovery () {    local regexp= "\b (btrfs|ext2|ext3|ext4| JFS|REISER|XFS|FFS|UFS|JFS|JFS2|VXFS|HFS|NTFS|FAT32|ZFS) \b "    local tmpfile="/tmp/ Mounts.tmp "    :> " $tmpfile "    #  filter all mounted file systems      egrep  "$regexp"  /proc/mounts >  "$tmpfile"      local num=$ (cat  "$tmpfile"  | wc -l)     printf  ' {\ n '      printf  ' \ t ' data ':[  '     while read line;do         #  disk partition name         dev_ name=$ (echo  $line  | awk  ' {print $1} ')          #  file system name, which is the mount point of the disk partition         fs_name=$ (echo  $line  | awk  ' {print $2} ')    The       # blockdev command gets the sector size used to calculate the disk read/write rate          sec_size=$ (sudo /sbin/blockdev --getss  $DEV _name 2>/dev/null)          printf  ' \n\t\t{'          printf  "\" {#DEV_NAME}\ ": \" ${dev_name}\ ","         printf  "\" { #FS_NAME}\ ": \" ${fs_name}\ ","         printf  "\" {#SEC_SIZE}\ ": \" ${ Sec_size}\ "}"          ((num--))          [  "$num"  == 0 ] && break         printf  ","     done <  $tmpfile "     printf  ' \n\t]\n '     printf  '}\n '}case  "$"  in    mount_disk_discovery)           "$"         ;;     *)         echo  "Bad parameter."         echo  "Usage: $0 mount_disk_discovery"          exit 1        ;; Esac

The script first filters the type of disk in /proc/mounts and then outputs the JSON data that contains the disk name, file system name, and sector size.

2) Set the relevant file permissions:

Touch/tmp/mounts.tmpchown zabbix:zabbix/tmp/mounts.tmpchown-r zabbix:zabbix/etc/zabbix/monitor_scriptschmod 755/ etc/zabbix/monitor_scripts/mount_disk_discovery.sh

3) Test:

[[email protected] ~]#/etc/zabbix/monitor_scripts/mount_disk_discovery.sh mount_disk_discovery{"Data": [{"{#D Ev_name} ":"/dev/sda3 "," {#FS_NAME} ":"/"," {#SEC_SIZE} ":" $ "}, {" {#DEV_NAME} ":"/dev/sda1 "," {#FS_NAME} ":"/Boot "," { #SEC_SIZE} ":" 512 "}]}

The above data indicates that the disk partition/dev/sda3 mounted to the root directory, the sector size is 512b;/dev/sda1 mounted to the/boot directory, and the sector size is 512B.


Second, configure the Zabbix client

1) Edit the Zabbix agent configuration file and set the Include directory:

include=/etc/zabbix/zabbix_agentd.d/

The configuration file under the Include directory is automatically loaded when the agent starts.

2) in the/etc/zabbix/zabbix_agentd.d/directory to establish the disk_lld.conf, the contents are as follows:

Userparameter=mount_disk_discovery,/bin/bash/etc/zabbix/monitor_scripts/mount_disk_discovery.sh Mount_disk_ Discovery

Represents: Establishes a user-defined parameter mount_disk_discovery, and when Zabbix server requests this item key from the agent, the agent calls/etc/zabbix/monitor_scripts/ mount_disk_discovery.sh script that returns JSON data.

3) because the Zabbix agent's startup user is Zabbix, the Zabbix user is authorized to run the/sbin/blockdev command without a password. Using the Visudo command, comment out defaults requiretty in/etc/sudoers:

#Defaults Requiretty

And at the very end add:

Zabbix all= (All) nopasswd:/sbin/blockdev

This way, it is no problem to execute instructions like "Sudo/sbin/blockdev--getss/dev/sda1" in the script.

4) Finally restart the Zabbix agent

/etc/init.d/zabbix-agent restart

5) Test:

Let's get it remotely from Zabbix server Mount_disk_discovery

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/2E/wKioL1SrmB2z2bO-AAEv3eBm9w0950.jpg "title=" Get.png "alt=" Wkiol1srmb2z2bo-aaev3ebm9w0950.jpg "/>

such as Dev_name, Fs_name, and sec_size have values that indicate that the client is configured correctly.


Third, configure the Zabbix front desk

1) Log in to the Zabbix foreground, select Configuration->templates->import, and import the template Linux Diskio templates (see attachment).

2) go to the Host Configuration Interface, link "template Linux Diskio" templates

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/58/31/wKiom1SrlBeCKotjAAG5PXwjM6I328.jpg "title=" Host.png "alt=" Wkiom1srlbeckotjaag5pxwjm6i328.jpg "/>

At this point, the entire configuration is over, wait patiently for the monitoring data to appear ~

The following is a description of the configuration of LLD in the template.

3) Discovery rule Introduction to Templates

Discovery rule's key is mount_disk_discovery, corresponding to the Zabbix agent configuration:

Userparameter=mount_disk_discovery,/bin/bash/etc/zabbix/monitor_scripts/mount_disk_discovery.sh Mount_disk_ Discovery

Every once in a while, the server requests Mount_disk_discovery to the agent, and the agent calls/etc/zabbix/monitor_scripts/mount_disk_ The discovery.sh script returns the JSON data to the server.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/58/2F/wKioL1SroEPxQs8GAAGhMcWqqF4073.jpg "title=" dr.png "alt=" Wkiol1sroepxqs8gaaghmcwqqf4073.jpg "/>

4) Template Item prototypes Introduction

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/31/wKiom1SrmFDDcxcEAAOermcg-TI132.jpg "title=" Item.png "alt=" Wkiom1srmfddcxceaaoermcg-ti132.jpg "/>

The monitoring items of sectors and operations are ZABBIX agent type. By reading Zabbix C source code, we will find that the Zabbix agent calculates sectors and operations per second based on/proc/diskstats files, and the default takes a minute average . Interested students can read the SRC/LIBS/ZBXSYSINFO/LINUX/DISKIO.C.

Disk read and write speed monitoring entries are of type calculated, calculated by multiplying the number of read-write sectors per second by the sector size, see:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/58/2E/wKioL1Srmo-woHCfAALFbRDOYjU046.jpg "title=" Read.png "alt=" Wkiol1srmo-wohcfaalfbrdoyju046.jpg "/>

5) Graph prototypes Introduction to Templates

The template creates three charts for each disk partition, including the disk read-write rate chart, the read-write sector number chart, and the read-write operand graph.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/58/2E/wKioL1SrmPzSlBOfAAIxIlfBAzQ692.jpg "title=" Gra.png "alt=" Wkiol1srmpzslbofaaixilfbazq692.jpg "/>



Attached: Client One-click Configuration script

#!/bin/sh## filename:    automonitordiskio.sh# date:         2014/01/05# author:      qicheng# website:      http://qicheng0211.blog.51cto.com/# Description:  Deployment zabbix  low-level discovery  monitoring Disk io# notes:  Run this script on the monitored client, the prerequisites are already installed zabbix agent# root_uid= 0if [  "$UID"  -ne  "$ROOT _uid"  ];then    echo  "error:  Please run this script as root user. "     exit 1fi #  modify it to your Zabbix agent profile path agent_conf= "/etc/zabbix/zabbix _agentd.conf " mkdir -p /etc/zabbix/monitor_scripts#  Create  low-level discovery  mounted disk  Script cat > /etc/zabbix/monitor_scripts/mount_disk_discovery.sh <<   ' EOF ' #!/bin/bash#function: low-level discovery mounTed disk#script_name: mount_disk_discovery.sh mount_disk_discovery () {     local regexp= "\b (btrfs|ext2|ext3|ext4|jfs|reiser|xfs|ffs|ufs|jfs|jfs2|vxfs|hfs|ntfs|fat32|zfs) \b"      local tmpfile= "/tmp/mounts.tmp"     :>  "$tmpfile"      egrep  "$regexp"  /proc/mounts >  "$tmpfile"      local num=$ (cat  "$tmpfile"  | wc -l)     printf  ' {\ n '      printf  ' \ t ' data ':[  '     while read line;do         dev_name=$ (echo  $line  | awk  ' {print $1} ')         fs_name=$ (echo  $line  | awk  ' {print $2 } ')         sec_size=$ (sudo /sbin/blockdev --getss  $DEV _ Name 2>/dev/null)         printf  ' \n\t\t{'          printf  "\" {#DEV_NAME}\ ": \" ${dev_name}\ ","         printf  "\" { #FS_NAME}\ ": \" ${fs_name}\ ","         printf  "\" {#SEC_SIZE}\ ": \" ${ Sec_size}\ "}"          ((num--))          [  "$num"  == 0 ] && break         printf  ","     done <  $tmpfile "     printf  ' \n\t]\n '     printf  '}\n '}case  "$"  in     Mount_disk_discovery)          "$"          ;;     *)         echo  "Bad parameter."         echo  "Usage: $0 mount_disk_discovery"          exit 1        ;; Esaceoftouch /tmp/mounts.tmpchown zabbix:zabbix /tmp/mounts.tmpchown -r zabbix:zabbix  /etc/zabbix/monitor_scriptschmod 755 /etc/zabbix/monitor_scripts/mount_disk_discovery.sh  #  determine if the configuration file exists [ -f  "${agent_conf}"  ] | |  { echo  "Error: file ${agent_conf} does not exist."; exit 1;}  include= ' grep  ' ^include '  ${agent_conf} | cut -d ' = '  -f2 ' #  Add custom parameters to the configuration file if [ -d  "$include"  ];then    cat >  $include/ disk_lld.conf <<  ' EOF ' userparameter=mount_disk_discovery,/bin/bash /etc/zabbix/monitor_ scripts/mount_disk_discovery.sh mount_disk_discoveryeofelse    grep -q  ' ^userparameter=mount_disk_discovery '  ${agent_conf} | |  cat >> ${AGENT_CONF} <<  ' EOF ' userparameter=mount_disk_discovery,/bin/ bash /etc/zabbix/monitor_scripts/mount_disk_discovery.sh mount_disk_discoveryeoffi#  Authorize Zabbix user without password run/sbin/blockdev command chmod +w /etc/sudoers sed -i  '/^defaults\s\+requiretty /s/^/#/'  /etc/sudoersgrep -q  ' ^zabbix all= (All). *blockdev '  /etc/sudoers | |  echo  ' zabbix all= (All)        nopasswd: /sbin/blockdev '  >> /etc/sudoerschmod 440 /etc/sudoers#  Restart Agent service [ -f  '/etc/init.d/ Zabbix-agent '  ] && /etc/init.d/zabbix-agent restart | |  echo  "Manual restart of the Zabbix agent service is required."


This article is from the "Start Linux blog" blog, reproduced please contact the author!

Zabbix application Low-level discovery monitoring disk IO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.