Skip to content
Closed
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
9 changes: 9 additions & 0 deletions files/image_config/monit/memory_checker
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def check_memory_usage(container_name, threshold_value):
sys.exit(4)


def is_service_active(service):
status = subprocess.run("systemctl is-active --quiet {}".format(service), shell=True, check=False)
return status.returncode == 0


def get_running_container_names():
"""Retrieves names of running containers by talking to the docker daemon.

Expand Down Expand Up @@ -128,6 +133,10 @@ def main():
parser.add_argument("threshold_value", type=int, help="threshold value in bytes")
args = parser.parse_args()

if not is_service_active("docker"):
syslog.syslog(syslog.LOG_INFO,"Skipping memory check: docker daemon is down")
sys.exit(0)

running_container_names = get_running_container_names()
if args.container_name in running_container_names:
check_memory_usage(args.container_name, args.threshold_value)
Expand Down