/usr/share/check_mk/checks/diskstat.include is in check-mk-server 1.2.2p3-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238  | #!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2013             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.
diskstat_inventory_mode = "rule" # "summary", "single", "legacy"
diskstat_default_levels = {
#    "read" :    (10, 20),   # MB/sec
#    "write" :   (20, 40),   # MB/sec
#    "average" : 15,         # min
#    "latency" : (10, 20), # ms
#    "latency_perfdata" : True,
}
# Rule for controlling diskstat inventory more fine grained
diskstat_inventory = []
# Example
# diskstat_inventory = [
#  ( [], [ 'linux' ], ALL_HOST ), --> No diskstat on this host
#  ( [ 'summary', 'physical', 'lvm', 'vxvm' ], ALL_HOSTS ),
# ]
def inventory_diskstat_generic(info):
    # Skip over on empty data
    if not info:
        return
    # New style: use rule based configuration, defaulting to summary mode
    if diskstat_inventory_mode == "rule":
        hits = host_extra_conf(g_hostname, diskstat_inventory)
        if len(hits) > 0:
            modes = hits[0]
        else:
            modes = [ "summary" ]
    elif diskstat_inventory_mode == "single":
        modes = [ "physical" ]
    elif diskstat_inventory_mode == "summary":
        modes = [ "summary" ]
    else:
        modes = [ "legacy" ]
    inventory = []
    if "summary" in modes:
        inventory.append( ( "SUMMARY", "diskstat_default_levels" ) )
    if "legacy" in modes:
        inventory += [ ( "read", None ), ( "write", None ) ]
    if "physical" in modes:
        inventory += [ (line[0], "diskstat_default_levels")
                       for line in info
                       if not ' ' in line[0] ]
    if "lvm" in modes:
        inventory += [ (line[0], "diskstat_default_levels")
                       for line in info
                       if line[0].startswith("LVM ") ]
    if "vxvm" in modes:
        inventory += [ (line[0], "diskstat_default_levels")
                       for line in info
                       if line[0].startswith("VxVM ") ]
    return inventory
def check_diskstat_line(this_time, item, params, line):
    average_range = params.get("average")
    perfdata = []
    infos = []
    status = 0
    for what, ctr in [ ("read",  line[1]), ("write", line[2]) ]:
        countername = "diskstat.%s.%s" % (item, what)
        # unpack levels now, need also for perfdata
        levels = params.get(what)
        if levels:
            warn, crit = levels
        else:
            warn, crit = None, None
        # compute IO rate in bytes/sec
        timedif, sectors_per_sec = get_counter(countername, this_time, int(ctr))
        bytes_per_sec = sectors_per_sec * 512
        infos.append("%s/sec %s" % (get_bytes_human_readable(bytes_per_sec), what))
        perfdata.append( (what, bytes_per_sec, warn, crit) )
        # compute average of the rate over ___ minutes
        if average_range != None:
            timedif, avg = get_average(countername + ".avg", this_time, bytes_per_sec, average_range)
            perfdata.append( (what + ".avg", avg) )
            bytes_per_sec = avg
        # check levels
        if levels != None:
            mb_per_sec = bytes_per_sec / 1048576
            if mb_per_sec >= crit:
                status = 2
                infos[-1] += "(!!)"
            elif mb_per_sec >= warn:
                status = max(status, 1)
                infos[-1] += "(!)"
    # Add performance data for averaged IO
    if average_range != None:
        perfdata = [ perfdata[0], perfdata[2], perfdata[1], perfdata[3] ]
    # Process IOs when available
    ios_per_sec = None
    if len(line) >= 5 and line[3] >= 0 and line[4] > 0:
        reads, writes = map(int, line[3:5])
        ios = reads + writes
        timedif, ios_per_sec = get_counter(countername + ".ios", this_time, ios)
        infos.append("IOs: %.2f/sec" % ios_per_sec)
        if params.get("latency_perfdata"):
            perfdata.append(("ios", ios_per_sec))
    # Do Latency computation if this information is available:
    if len(line) >= 6 and line[5] >= 0:
        timems = int(line[5])
        timedif, timems_per_sec = get_counter(countername + ".time", this_time, timems)
        if not ios_per_sec:
            latency = 0.0
        else:
            latency = timems_per_sec / ios_per_sec
        infos.append("Latency: %.2fms" % latency)
        if "latency" in params:
            warn, crit = params["latency"]
            if latency >= crit:
                status = 2
                infos[-1] += "(!!)"
            elif latency >= warn:
                status = max(status, 1)
                infos[-1] += "(!)"
        else:
            warn, crit = None, None
        if params.get("latency_perfdata"):
            perfdata.append(("latency", latency, warn, crit))
    # Queue Lengths (currently only Windows). Windows uses counters here.
    # I have not understood, why....
    if len(line) >= 8:
        for what, ctr in [ ("read",  line[6]), ("write", line[7]) ]:
            countername = "diskstat.%s.ql.%s" % (item, what)
            levels = params.get(what + "_ql")
            if levels:
                warn, crit = levels
            else:
                warn, crit = None, None
            timedif, qlx = get_counter(countername, this_time, int(ctr))
            ql = qlx / 10000000.0
            infos.append(what.title() + " Queue: %.2f" % ql)
            # check levels
            if levels != None:
                if ql >= crit:
                    status = 2
                    infos[-1] += "(!!)"
                elif ql >= warn:
                    status = max(status, 1)
                    infos[-1] += "(!)"
            if params.get("ql_perfdata"):
                perfdata.append((what + "_ql", ql))
    return (status, nagios_state_names[status] + " - " + ", ".join(infos) , perfdata)
def check_diskstat_generic(item, params, this_time, info):
    # legacy version if item is "read" or "write"
    if item in [ 'read', 'write' ]:
        return check_diskstat_old(item, params, this_time, info)
    # summary mode
    if item == 'SUMMARY': # summary mode (only summarize physical disks!)
        summary_line = [0] * 13
        for line in info:
            devname = line[0]
            if ' ' in devname:
                continue
            summary_line = map(lambda e: e[0] + int(e[1]), zip(summary_line, line[1:]))
        return check_diskstat_line(this_time, "SUMMARY", params, [''] + summary_line)
    # single mode
    for line in info:
        if line[0] == item:
            return check_diskstat_line(this_time, item, params, line)
    return (3, "UNKNOWN - device missing")
# This is the legacy version of diskstat as used in <= 1.1.10.
# We keep it here for a while in order to be compatible with
# old installations.
def check_diskstat_old(item, params, this_time, info):
    # sum up over all devices
    if item == 'read':
        index = 1 # sectors read
    elif item == 'write':
        index = 2 # sectors written
    else:
        return (3, "UNKNOWN - invalid item %s" % (item,))
    this_val  = sum([int(x[index]) for x in info if ' ' not in x[0]])
    timedif, per_sec = get_counter("diskstat." + item, this_time, this_val)
    mb_per_s = per_sec / 2048.0    # Diskstat output is in sectors a 512 Byte
    perfdata = [ (item, "%dc" % this_val ) ]
    return (0, "OK - %.1fMB/s (in last %d secs)" % (mb_per_s, timedif), perfdata)
 |