Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / docker_container_diskstat
blobc0ecc03d7eaab413a4072d0b4db84750b7cd7981
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
28 def parse_docker_container_diskstat(info):
29 node_sections = _parse_sub_sections(info)
31 disks = {}
32 for node_name, node_info in node_sections.items():
33 timestamp = node_info["time"]
35 for _device_id, device in node_info["devices"].items():
36 # Filter out unwanted things
37 if device["name"].startswith("loop"):
38 continue
40 # Skip devices without counts
41 if "ios" not in device or "bytes" not in device:
42 continue
44 disks[(node_name, device["name"])] = timestamp, device
46 return disks
49 def _parse_sub_sections(info):
50 node_sections = {}
52 node = None
53 for line in info:
54 node = line[0]
56 if line[1] == "[io_service_bytes]":
57 phase = "bytes"
58 elif line[1] == "[io_serviced]":
59 phase = "ios"
60 elif line[1] == '[names]':
61 phase = "names"
62 elif line[1] == '[time]':
63 phase = "time"
64 else:
65 if line[1] == "Total":
66 continue
68 sections = node_sections.setdefault(node, {})
70 if phase == "time":
71 sections["time"] = int(line[1])
72 continue
74 devices = sections.setdefault("devices", {})
76 if phase == "names":
77 major, minor = map(int, line[2].split(":"))
78 else:
79 major, minor = map(int, line[1].split(":"))
81 device_id = node, major, minor
82 device = devices.setdefault(device_id, {})
84 if phase == "names":
85 device["name"] = line[1]
86 else:
87 device_phase = device.setdefault(phase, {})
88 device_phase[line[2]] = int(line[3])
90 return node_sections
93 def inventory_docker_container_diskstat(parsed):
94 return inventory_diskstat_generic(parsed.keys())
97 def check_docker_container_diskstat(item, params, parsed):
98 disks = {}
99 for (node_name, device_name), (timestamp, device) in parsed.items():
100 counter_base = "diskstat.%s." % device_name
102 # Docker container information is provided via piggyback in the most cases. In case
103 # we got no new data simply skip this check
104 previous_timestamp = get_item_state(counter_base + "time")
105 if previous_timestamp == timestamp:
106 raise MKCounterWrapped('No time difference')
107 set_item_state(counter_base + "time", timestamp)
109 read_ios_rate = get_rate(
110 counter_base + "read_ios", timestamp, device["ios"]["Read"], onwrap=0.0)
111 write_ios_rate = get_rate(
112 counter_base + "write_ios", timestamp, device["ios"]["Write"], onwrap=0.0)
113 read_bytes_rate = get_rate(
114 counter_base + "read_bytes", timestamp, device["bytes"]["Read"], onwrap=0.0)
115 write_bytes_rate = get_rate(
116 counter_base + "write_bytes", timestamp, device["bytes"]["Write"], onwrap=0.0)
118 disks[device_name] = {
119 "node": node_name,
120 "read_ios": read_ios_rate,
121 "write_ios": write_ios_rate,
122 "read_throughput": read_bytes_rate,
123 "write_throughput": write_bytes_rate,
126 return check_diskstat_dict(item, params, disks)
129 check_info["docker_container_diskstat"] = {
130 "parse_function": parse_docker_container_diskstat,
131 "inventory_function": inventory_docker_container_diskstat,
132 "check_function": check_docker_container_diskstat,
133 "service_description": "Disk IO %s",
134 "has_perfdata": True,
135 "group": "diskstat",
136 "node_info": True, # add first column with actual host name
137 "includes": ["diskstat.include"],