Cleanup config.nodes_of
[check_mk.git] / checks / ceph_df
blob41321ffdfd4c4697cea1b1b90c64d77dee467947
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2019 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 _sanitize_line(line):
29 """Merges units to values in case values and units are contained in separate line elements."""
30 units = ("k", "K", "B", "M", "G", "T", "P", "E", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB")
31 sanitized_line = []
32 for word in line:
33 if word in units and sanitized_line:
34 sanitized_line[-1] += word
35 else:
36 sanitized_line.append(word)
37 return sanitized_line
40 def parse_ceph_df(info):
41 parsed = {}
42 section = None
43 global_headers = None
44 pools_headers = None
46 for line in info:
47 if line[0] == "GLOBAL:":
48 section = "global"
49 continue
51 elif line[0] == "POOLS:":
52 section = "pools"
53 continue
55 line = _sanitize_line(line)
56 if section == "global":
57 if line == ['SIZE', 'AVAIL', 'RAW', 'USED', '%RAW', 'USED', 'OBJECTS']:
58 global_headers = ['SIZE', 'AVAIL', 'RAW USED', '%RAW USED', 'OBJECTS']
60 elif global_headers is not None:
61 parsed.setdefault("SUMMARY", dict(zip(global_headers, line)))
63 elif section == "pools":
64 if line == [
65 'NAME', 'ID', 'CATEGORY', 'QUOTA', 'OBJECTS', 'QUOTA', 'BYTES', 'USED', '%USED',
66 'MAX', 'AVAIL', 'OBJECTS', 'DIRTY', 'READ', 'WRITE', 'RAW', 'USED'
68 pools_headers = [
69 'NAME', 'ID', 'CATEGORY', 'QUOTA OBJECTS', 'QUOTA BYTES', 'USED', '%USED',
70 'MAX AVAIL', 'OBJECTS', 'DIRTY', 'READ', 'WRITE', 'RAW USED'
73 elif line == [
74 'NAME', 'ID', 'QUOTA', 'OBJECTS', 'QUOTA', 'BYTES', 'USED', '%USED', 'MAX',
75 'AVAIL', 'OBJECTS', 'DIRTY', 'READ', 'WRITE', 'RAW', 'USED'
77 pools_headers = [
78 'NAME', 'ID', 'QUOTA OBJECTS', 'QUOTA BYTES', 'USED', '%USED', 'MAX AVAIL',
79 'OBJECTS', 'DIRTY', 'READ', 'WRITE', 'RAW USED'
82 elif pools_headers is not None:
83 parsed.setdefault(line[0], dict(zip(pools_headers[1:], line[1:])))
85 def parse_byte_values(value_str):
86 """
87 Returns the used storage in mebibytes.
88 """
89 # sanitize to possible units to single representation
90 value_str = value_str.rstrip("iB")
92 if value_str.endswith("E"):
93 return float(value_str[:-1]) * 1024**4
94 elif value_str.endswith("P"):
95 return float(value_str[:-1]) * 1024**3
96 elif value_str.endswith("T"):
97 return float(value_str[:-1]) * 1024**2
98 elif value_str.endswith("G"):
99 return float(value_str[:-1]) * 1024
100 elif value_str.endswith("M"):
101 return float(value_str[:-1])
102 elif value_str.lower().endswith("k"):
103 return float(value_str[:-1]) / 1024
104 elif value_str == 'N/A':
105 return 0.0
106 return float(value_str) / (1024**2)
108 mps = []
109 for mp, data in parsed.iteritems():
110 # GLOBAL section:
111 # SIZE: The overall storage capacity of the cluster.
112 # AVAIL: The amount of free space available in the cluster.
113 # POOLS section:
114 # USED: The notional amount of data stored in kilobytes, unless the number appends M for megabytes or G for gigabytes.
115 # MAX AVAIL: An estimate of the notional amount of data that can be written to this pool.
116 if mp == "SUMMARY":
117 size_mb = parse_byte_values(data["SIZE"])
118 avail_mb = parse_byte_values(data["AVAIL"])
119 else:
120 size_mb = parse_byte_values(data["MAX AVAIL"])
121 avail_mb = size_mb - parse_byte_values(data["USED"])
122 mps.append((mp, size_mb, avail_mb, 0))
123 return mps
126 def inventory_ceph_df(mps):
127 return df_inventory([x[0] for x in mps])
130 check_info['ceph_df'] = {
131 'parse_function': parse_ceph_df,
132 'inventory_function': inventory_ceph_df,
133 'check_function': df_check_filesystem_list,
134 'service_description': 'Ceph Pool %s',
135 'has_perfdata': True,
136 'includes': ['df.include', 'size_trend.include'],
137 'group': 'filesystem',
138 'default_levels_variable': 'filesystem_default_levels',