Initial commit. More work to do

This commit is contained in:
Thomas Williams 2024-06-25 20:11:07 +01:00
parent 4c93030123
commit f76a916c83
Signed by: thomas
GPG key ID: EB8F975CF60BCBFF
4 changed files with 82 additions and 1 deletions

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2024 thomas
Copyright (c) 2024 Thomas Williams
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

5
config.py Normal file
View file

@ -0,0 +1,5 @@
#!/usr/bin/python3
monitoringPeriod = 30
urls = ["https://bootlesshacker.com"]
urlTimeout = 10

0
log.py Normal file
View file

76
main.py Executable file
View file

@ -0,0 +1,76 @@
#!/usr/bin/python3
# MIT License
# Copyright (c) 2024 Thomas Williams
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import config
import psutil
import os
import time
import log
import requests
from bs4 import BeautifulSoup
while True:
load1, load5, load15 = psutil.getloadavg() # this takes time to warm up if not running script on *nix
loadavg = round((load1/os.cpu_count()) * 100, 2)
total_memory, used_memory, free_memory = map(
int, os.popen('free -t -m').readlines()[-1].split()[1:])
memory = round((used_memory/total_memory) * 100, 2)
print("CPU %: " + str(loadavg))
print("Memory %: " + str(memory))
# Log CPU/Memory
headers = {
'User-Agent': 'Monutil monitor'
}
for url in config.urls:
startTime = time.time()
request = requests.get(url, timeout=config.urlTimeout, headers=headers)
if request.status_code == 200:
html = BeautifulSoup(request.content, 'html.parser')
imageUrls = [img['src'] for img in html.find_all('img')]
for url in imageUrls:
request = requests.get(url)
if not request.status_code == 200:
# failure scenario
print("test")
endTime = time.time()
timeDiff = endTime - startTime
print(timeDiff)
else:
print(failure)
time.sleep(config.monitoringPeriod)