add check memory usage
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
- pip3 install requests
|
||||
"""
|
||||
|
||||
__version__ = '0.4.0'
|
||||
__version__ = '0.5.0'
|
||||
__author__ = 'anima'
|
||||
|
||||
# imports
|
||||
@@ -97,10 +97,31 @@ class DockerSwarmCoresResource(nagiosplugin.Resource):
|
||||
nagiosplugin.Metric: single metric element (return)
|
||||
"""
|
||||
data = self.api.statistics()
|
||||
memory = data['memory']
|
||||
memory_usage_percent = round(memory['usage'], 2)
|
||||
|
||||
return nagiosplugin.Metric(name='load', value=memory_usage_percent, uom='%', context='scalar_context')
|
||||
|
||||
|
||||
#
|
||||
# Check Swarm memory
|
||||
#
|
||||
class DockerSwarmMemoryResource(nagiosplugin.Resource):
|
||||
def __init__(self, api) -> None:
|
||||
self.api = api
|
||||
|
||||
def probe(self) -> list:
|
||||
"""check memory usage of full swarm
|
||||
|
||||
Returns:
|
||||
nagiosplugin.Metric: single metric element (return)
|
||||
"""
|
||||
data = self.api.statistics()
|
||||
print(data)
|
||||
cpu = data['cpu']
|
||||
cpu_usage_percent = round((cpu['usage'] / cpu['cores']) * 100, 2)
|
||||
|
||||
return nagiosplugin.Metric(name='load', value=cpu_usage_percent, uom='%', context='scalar_context')
|
||||
return nagiosplugin.Metric(name='memory', value=cpu_usage_percent, uom='%', context='scalar_context')
|
||||
|
||||
|
||||
#
|
||||
@@ -256,6 +277,7 @@ def parse_args() -> argparse.Namespace:
|
||||
argp.add_argument('-m', '--check_mode',
|
||||
choices=[
|
||||
'load',
|
||||
'memory',
|
||||
'service_states',
|
||||
'service_updates'
|
||||
],
|
||||
@@ -295,6 +317,12 @@ def main():
|
||||
nagiosplugin.ScalarContext(name='scalar_context', warning=args.warning, critical=args.critical),
|
||||
nagiosplugin.Summary())
|
||||
check.name = "swarm load"
|
||||
case 'memory':
|
||||
check = nagiosplugin.Check(
|
||||
DockerSwarmMemoryResource(api=api),
|
||||
nagiosplugin.ScalarContext(name='scalar_context', warning=args.warning, critical=args.critical),
|
||||
nagiosplugin.Summary())
|
||||
check.name = "swarm memory"
|
||||
case 'service_states':
|
||||
check = nagiosplugin.Check(
|
||||
DockerSwarmServiceStatesResource(api=api),
|
||||
|
||||
Reference in New Issue
Block a user