Module: check_mk
Branch: master
Commit: eb1136f0a5503d49886ac2f7fe66dd79e816aace
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eb1136f0a5503d…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Tue Apr 9 15:17:36 2019 +0200
esx_vsphere_datastores: convert bytes as late as possible
Change-Id: Ia39640c3598b56d4bdf83060134eeeb06508ee3c
---
checks/esx_vsphere_datastores | 39 +++++++++++-----------
.../datasets/esx_vsphere_datastores_regression.py | 4 +--
2 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/checks/esx_vsphere_datastores b/checks/esx_vsphere_datastores
index b3916b3..459472b 100644
--- a/checks/esx_vsphere_datastores
+++ b/checks/esx_vsphere_datastores
@@ -67,20 +67,24 @@ def check_esx_vsphere_datastores(item, params, info):
if item not in stores:
return 3, "Datastore not existing"
store = stores[item]
- size_mb = store["capacity"] / 1024.0 / 1024.0
- avail_mb = store["freeSpace"] / 1024.0 / 1024.0
- state, infotext, perfdata = df_check_filesystem_single(item, size_mb, avail_mb, 0,
None, None,
- params)
+ mib = 1024.0**2
+ size_bytes = store["capacity"]
+ avail_bytes = store["freeSpace"]
+ #size_mb = store["capacity"] / mib
+ #avail_mb = store["freeSpace"] / mib
+
+ state, infotext, perfdata = df_check_filesystem_single(item, size_bytes / mib,
+ avail_bytes / mib, 0, None,
None, params)
if 'uncommitted' in store:
- uncommitted_mb = store["uncommitted"] / 1024.0 / 1024.0
- used_mb = size_mb - avail_mb
- prov_mb = used_mb + uncommitted_mb
- if size_mb == 0:
+ uncommitted_bytes = store["uncommitted"]
+ used_bytes = size_bytes - avail_bytes
+ prov_bytes = used_bytes + uncommitted_bytes
+ if size_bytes == 0:
prov_percent = 0
else:
- prov_percent = (prov_mb / size_mb) * 100
+ prov_percent = (prov_bytes * 100.) / size_bytes
prov_txt = ''
warn, crit = None, None
@@ -94,19 +98,16 @@ def check_esx_vsphere_datastores(item, params, info):
state = max(state, 1)
prov_txt = levels_text + '(!)'
- infotext += ", uncommitted: %.2f GB, provisioning: %.1f%%%s" %
(uncommitted_mb / 1024,
- prov_percent,
prov_txt)
+ infotext += ", uncommitted: %s, provisioning: %s%s" %
(get_bytes_human_readable(
+ uncommitted_bytes), get_percent_human_readable(prov_percent), prov_txt)
+
if perfdata:
+ perfdata.append(('uncommitted', uncommitted_bytes / mib))
if warn:
- prov_warn_mb = size_mb / 100 * warn
- prov_crit_mb = size_mb / 100 * crit
+ scale = size_bytes / mib / 100.
+ perfdata.append(('overprovisioned', prov_bytes / mib, scale *
warn, scale * crit))
else:
- prov_warn_mb = None
- prov_crit_mb = None
- perfdata += [
- ('uncommitted', uncommitted_mb),
- ('overprovisioned', prov_mb, prov_warn_mb, prov_crit_mb),
- ]
+ perfdata.append(('overprovisioned', prov_bytes / mib))
if not store["accessible"]:
state = 2
diff --git a/tests/unit/checks/generictests/datasets/esx_vsphere_datastores_regression.py
b/tests/unit/checks/generictests/datasets/esx_vsphere_datastores_regression.py
index cb7faa1..273ba3a 100644
--- a/tests/unit/checks/generictests/datasets/esx_vsphere_datastores_regression.py
+++ b/tests/unit/checks/generictests/datasets/esx_vsphere_datastores_regression.py
@@ -36,7 +36,7 @@ checks = {'': [(u'WIN-0100-MCC15-M-L000-SSD',
'trend_perfdata': True,
'trend_range': 24},
[(0,
- '24.7% used (1012.89 GB of 4.00 TB), trend: 0.00 B / 24 hours,
uncommitted: 0.00 GB, provisioning: 24.7%',
+ '24.7% used (1012.89 GB of 4.00 TB), trend: 0.00 B / 24 hours,
uncommitted: 0.00 B, provisioning: 24.7%',
[(u'WIN-0100-MCC15-M-L000-SSD',
1037195.0,
3355238.4,
@@ -59,7 +59,7 @@ checks = {'': [(u'WIN-0100-MCC15-M-L000-SSD',
'trend_perfdata': True,
'trend_range': 24},
[(0,
- '78.2% used (9.38 of 12.00 TB), trend: 0.00 B / 24 hours,
uncommitted: 0.00 GB, provisioning: 78.2%',
+ '78.2% used (9.38 of 12.00 TB), trend: 0.00 B / 24 hours,
uncommitted: 0.00 B, provisioning: 78.2%',
[(u'WIN-0108-MCC35-U-L008-SSD-EXC2',
9836700.0,
10066124.8,