5.02021-11-21T21:59:42ZTemplatesOS Linux diskstatsOS Linux diskstats## Description
Self-contained template for monitoring disk statistics on Linux systems. Source: https://github.com/frei-style/zabbix-linux-diskstats-template
## Overview
This is a self-contained monitoring template to get I/O statistics of block devices on Linux systems.
## Author
Manuel Frei
Templatesdiskstats- diskstats (master)ZABBIX_ACTIVEvfs.file.contents[/proc/diskstats]30s00TEXTdiskstatsJAVASCRIPT// https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
// https://www.kernel.org/doc/Documentation/admin-guide/iostats.rst
function zeroTest(element) {
return parseInt(element) === 0;
}
var returnData = [];
var lines = value.split("\n");
var lineCount = lines.length;
for(var lineNumber = 0; lineNumber < lineCount; lineNumber++) {
var fields = lines[lineNumber].trim().split(/[ ]+/);
// skip devices by name
if(/^(ram[0-9]+|dm-[0-9]+|loop[0-9]+)$/.test(fields[2])) {
continue;
}
var allZero = fields.slice(3).every(zeroTest);
// skip devices where all values are 0
if(allZero) {
continue;
}
var diskData = {
"majorNumber": parseInt(fields[0]),
"minorNumber": parseInt(fields[1]),
"deviceName": fields[2],
"readsCompleted": parseInt(fields[3]),
"readsMerged": parseInt(fields[4]),
"sectorsRead": parseInt(fields[5]),
"timeSpentReading": parseInt(fields[6]),
"writesCompleted": parseInt(fields[7]),
"writesMerged": parseInt(fields[8]),
"sectorsWritten": parseInt(fields[9]),
"timeSpentWriting": parseInt(fields[10]),
"iOsCurrentlyInProgress": parseInt(fields[11]),
"timeSpentDoingIOs": parseInt(fields[12]),
"weightedTimeSpentDoingIOs": parseInt(fields[13]),
}
if(fields.length>=18) {
diskData["discardsCompleted"] = parseInt(fields[14]);
diskData["discardsMerged"] = parseInt(fields[15]);
diskData["sectorsDiscarded"] = parseInt(fields[16]);
diskData["timeSpentDiscarding"] = parseInt(fields[17]);
}
if(fields.length>=20) {
diskData["flushRequestsCompleted"] = parseInt(fields[18]);
diskData["timeSpentFlushing"] = parseInt(fields[19]);
}
returnData.push(diskData);
}
return JSON.stringify(returnData);
Discover Block DevicesDEPENDENTlinux.diskstats.discovery07d{#DEVICE_NAME}: discards completedDEPENDENTlinux.diskstats[{#DEVICE_NAME},discardsCompleted]0!requests/sThis is the total number of discards completed successfully.
Linux 4.18+diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].discardsCompleted.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: discards mergedDEPENDENTlinux.diskstats[{#DEVICE_NAME},discardsMerged]0!requests/sDiscards which are adjacent to each other may be merged for efficiency. Thus two 4K reads may become one 8K read before it is ultimately handed to the disk, and so it will be counted (and queued) as only one I/O. This field lets you know how often this was done.
Linux 4.18+diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].discardsMerged.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: flush requests completedDEPENDENTlinux.diskstats[{#DEVICE_NAME},flushRequestsCompleted]0!requests/sThis is the number of flush requests completed successfully per second.
Block layer combines flush requests and executes at most one at a time. This counts flush requests executed by disk. Not tracked for partitions.
Linux 5.5+diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].flushRequestsCompleted.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: I/Os currently in progressDEPENDENTlinux.diskstats[{#DEVICE_NAME},iOsCurrentlyInProgress]0!I/OsNumber of I/Os currently in progress.diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].iOsCurrentlyInProgress.first()DISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: reads completedDEPENDENTlinux.diskstats[{#DEVICE_NAME},readsCompleted]0!requests/sThis is the total number of reads completed successfully.diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].readsCompleted.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: reads mergedDEPENDENTlinux.diskstats[{#DEVICE_NAME},readsMerged]0!requests/sNumber of reads merged per second.diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].readsMerged.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: sectors discardedDEPENDENTlinux.diskstats[{#DEVICE_NAME},sectorsDiscarded]0!requests/sThis is the total number of sectors discarded successfully.
Linux 4.18+diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].sectorsDiscarded.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: sectors readDEPENDENTlinux.diskstats[{#DEVICE_NAME},sectorsRead]0!requests/sNumber of sectors read per second.diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].sectorsRead.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: sectors writtenDEPENDENTlinux.diskstats[{#DEVICE_NAME},sectorsWritten]0!requests/sThis is the total number of sectors written successfully per second.diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].sectorsWritten.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: time spent discardingDEPENDENTlinux.diskstats[{#DEVICE_NAME},timeSpentDiscarding]0!msThis is the total number of milliseconds spent by all discards (as measured from __make_request() to end_that_request_last()).
Linux 4.18+diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].timeSpentDiscarding.first()SIMPLE_CHANGEDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: time spent doing I/OsDEPENDENTlinux.diskstats[{#DEVICE_NAME},timeSpentDoingIOs]0!msNumber of milliseconds spent doing I/Os.
Since Linux 5.0 this field counts jiffies when at least one request was started or completed. If request runs more than 2 jiffies then some I/O time might be not accounted in case of concurrent requests.diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].timeSpentDoingIOs.first()SIMPLE_CHANGEDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: time spent flushingDEPENDENTlinux.diskstats[{#DEVICE_NAME},timeSpentFlushing]0!msThis is the total number of milliseconds spent by all discards (as measured from __make_request() to end_that_request_last()).
Linux 5.5+diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].timeSpentFlushing.first()SIMPLE_CHANGEDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: time spent readingDEPENDENTlinux.diskstats[{#DEVICE_NAME},timeSpentReading]0!msThis is the total number of milliseconds spent by all reads (as measured from __make_request() to end_that_request_last()).diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].timeSpentReading.first()SIMPLE_CHANGEDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: time spent writingDEPENDENTlinux.diskstats[{#DEVICE_NAME},timeSpentWriting]0!msThis is the total number of milliseconds spent by all writes (as measured from __make_request() to end_that_request_last()).diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].timeSpentWriting.first()SIMPLE_CHANGEDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: weighted time spent doing I/OsDEPENDENTlinux.diskstats[{#DEVICE_NAME},weightedTimeSpentDoingIOs]0!msThis is the numer per second of each of this actions: I/O start, I/O completion, I/O merge, or read. This can provide an easy measure of both I/O completion time and the backlog that may be accumulating.diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].weightedTimeSpentDoingIOs.first()SIMPLE_CHANGEDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: writes completedDEPENDENTlinux.diskstats[{#DEVICE_NAME},writesCompleted]0!requests/sThis is the total number of writes completed successfully per second.diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].writesCompleted.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: writes mergedDEPENDENTlinux.diskstats[{#DEVICE_NAME},writesMerged]0!requests/sThis is the total number of writes merged per second.diskstatsJSONPATH$.[?(@.deviceName == "{#DEVICE_NAME}")].writesMerged.first()CHANGE_PER_SECONDDISCARD_UNCHANGED_HEARTBEAT5mvfs.file.contents[/proc/diskstats]{#DEVICE_NAME}: I/O Times1A7C11- OS Linux diskstatslinux.diskstats[{#DEVICE_NAME},timeSpentReading]
13949AB- OS Linux diskstatslinux.diskstats[{#DEVICE_NAME},timeSpentWriting]
{#DEVICE_NAME}: IOPS1A7C11- OS Linux diskstatslinux.diskstats[{#DEVICE_NAME},readsCompleted]
1303F9F- OS Linux diskstatslinux.diskstats[{#DEVICE_NAME},writesCompleted]
vfs.file.contents[/proc/diskstats]{#DEVICE_NAME}$.deviceName