Skip to content

Instantly share code, notes, and snippets.

@vulongtran
Last active November 9, 2021 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vulongtran/33b73b2fb67d884dfe4c3413ef41294e to your computer and use it in GitHub Desktop.
Save vulongtran/33b73b2fb67d884dfe4c3413ef41294e to your computer and use it in GitHub Desktop.
"""Make sure you are in the scripts folder"""
"""To change to this folder type cd ~/scripts """
"""This is for the network.py file"""
#!/usr/bin/env python3
import requests
import socket
localhost = socket.gethostbyname('localhost')
request = requests.get("http://www.google.com")
"""This is for the health_checks.py file"""
#!/usr/bin/env python3
from network import *
import shutil
import psutil
def check_disk_usage(disk):
"""Verifies that there's enough free space on disk"""
du = shutil.disk_usage(disk)
free = du.free / du.total * 100
return free > 20
def check_cpu_usage():
"""Verifies that there's enough unused CPU"""
usage = psutil.cpu_percent(1)
return usage < 75
# If there's not enough disk, or not enough CPU, print an error
if not check_disk_usage('/') or not check_cpu_usage():
print("ERROR!")
elif check_localhost() and check_connectivity():
print("Everything ok")
else:
print("Network checks failed")
@veera-raju
Copy link

you have not defined check_localhost() and check_connectivity() in network.py to display the output when running health_checks.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment