Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Monit] Fix in memory_checker, skip fetching running containers if Docker engine is not running #30

Closed
wants to merge 3 commits into from
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