add check disk usage
This commit is contained in:
@@ -123,6 +123,26 @@ class DockerSwarmMemoryResource(nagiosplugin.Resource):
|
||||
return nagiosplugin.Metric(name='memory', value=memory_usage_percent, uom='%', context='scalar_context')
|
||||
|
||||
|
||||
#
|
||||
# Check Swarm disk
|
||||
#
|
||||
class DockerSwarmDiskResource(nagiosplugin.Resource):
|
||||
def __init__(self, api) -> None:
|
||||
self.api = api
|
||||
|
||||
def probe(self) -> list:
|
||||
"""check disk usage of full swarm
|
||||
|
||||
Returns:
|
||||
nagiosplugin.Metric: single metric element (return)
|
||||
"""
|
||||
data = self.api.statistics()
|
||||
disk = data['disk']
|
||||
disk_usage_percent = round(disk['usage'], 2)
|
||||
|
||||
return nagiosplugin.Metric(name='disk', value=disk_usage_percent, uom='%', context='scalar_context')
|
||||
|
||||
|
||||
#
|
||||
# Check Swarm services
|
||||
#
|
||||
@@ -277,6 +297,7 @@ def parse_args() -> argparse.Namespace:
|
||||
choices=[
|
||||
'load',
|
||||
'memory',
|
||||
'disk',
|
||||
'service_states',
|
||||
'service_updates'
|
||||
],
|
||||
@@ -322,6 +343,12 @@ def main():
|
||||
nagiosplugin.ScalarContext(name='scalar_context', warning=args.warning, critical=args.critical),
|
||||
nagiosplugin.Summary())
|
||||
check.name = "swarm memory"
|
||||
case 'disk':
|
||||
check = nagiosplugin.Check(
|
||||
DockerSwarmDiskResource(api=api),
|
||||
nagiosplugin.ScalarContext(name='scalar_context', warning=args.warning, critical=args.critical),
|
||||
nagiosplugin.Summary())
|
||||
check.name = "swarm disk"
|
||||
case 'service_states':
|
||||
check = nagiosplugin.Check(
|
||||
DockerSwarmServiceStatesResource(api=api),
|
||||
|
||||
Reference in New Issue
Block a user