Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions checkvsphere/vcmd/datastores.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def range_in_bytes(r: Range, uom):
":" + ('' if end == float('+inf') else str(end))

args = None
UNIT_METRICS = ('B', 'kB', 'MB', 'GB')
METRIC_CHOICES = (
['usage']
+ [metric for metric in ('free', 'used', 'capacity')]
+ [f"{metric}_{unit}" for metric in ('free', 'used', 'capacity') for unit in UNIT_METRICS]
)

def run():
global args
Expand All @@ -85,6 +91,7 @@ def run():
'options': {
'action': 'store',
'default': 'usage',
'choices': METRIC_CHOICES,
'help': 'The metric to apply the thresholds on, defaults to `usage`, can be: '
'usage (in percent), free and used. '
'free and used are measured in bytes. You can one of these suffixes: '
Expand Down
15 changes: 8 additions & 7 deletions checkvsphere/vcmd/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,18 @@ def run():
check = Check()
check.set_threshold(warning=args.warning, critical=args.critical)

args._si = service_instance.connect(args)

try:
vimtype = getattr(vim, args.vimtype)
except:
raise Exception(f"vim.{args.vimtype} is not known")

try:
args.perfcounter.split(":", 2)
except:
raise Exception("perfcounter must be composed as groupName:perfName:rollupType")
parts = args.perfcounter.split(":")
if len(parts) != 3 or any(not part for part in parts):
raise CheckVsphereException(
"perfcounter must be composed as groupName:perfName:rollupType"
)

args._si = service_instance.connect(args)

(counter, metricId) = get_metric(
args._si.content.perfManager, args.perfcounter, args.perfinstance
Expand Down Expand Up @@ -230,7 +231,7 @@ def get_argparser():
'options': {
'action': 'store',
'default': '',
'help': 'the instance of of the metric to monitor. defaults to empty string, '
'help': 'the instance of the metric to monitor. defaults to empty string, '
'which is not always available but means an aggregated value over all instances',
},
}
Expand Down
3 changes: 2 additions & 1 deletion checkvsphere/vcmd/vmguestfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
isallowed,
isbanned,
)
from checkvsphere.vcmd.datastores import Space, range_in_bytes
from checkvsphere.vcmd.datastores import METRIC_CHOICES, Space, range_in_bytes

args = None

Expand All @@ -49,6 +49,7 @@ def run():
"options": {
"action": "store",
"default": "usage",
"choices": METRIC_CHOICES,
"help": "The metric to apply the thresholds on, defaults to `usage`, can be: "
"usage (in percent), free and used. "
"free and used are measured in bytes. You can use one of these suffixes: "
Expand Down