Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge 774ddc7 into a75aa94
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCoderCarl authored Aug 1, 2022
2 parents a75aa94 + 774ddc7 commit d7b9d6a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 90 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ jobs:
include:
- os: windows-latest
TARGET: windows
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F reporter.py
OUT_FILE_NAME: reporter.exe
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F administratum.py
OUT_FILE_NAME: administratum.exe
ASSET_MIME: application/vnd.microsoft.portable-executable
- os: ubuntu-latest
TARGET: ubuntu
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F reporter.py
OUT_FILE_NAME: reporter
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F administratum.py
OUT_FILE_NAME: administratum
ASSET_MIME: application/x-binary

steps:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ jobs:
include:
- os: windows-latest
TARGET: windows
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F reporter.py
OUT_FILE_NAME: reporter.exe
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F administratum.py
OUT_FILE_NAME: administratum.exe
ASSET_MIME: application/vnd.microsoft.portable-executable
- os: ubuntu-latest
TARGET: ubuntu
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F reporter.py
OUT_FILE_NAME: reporter
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F administratum.py
OUT_FILE_NAME: administratum
ASSET_MIME: application/x-binary

steps:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# reporter
# administratum

Report about your castle

Expand Down Expand Up @@ -31,13 +31,13 @@ While the program running the information about runtime for every function is a

### Example
For only **Disk** report:
`reporter.exe --disk`
`administratum.exe --disk`

For **Disk** & **CPU** report:
`reporter.exe --disk --cpu`
`administratum.exe --disk --cpu`

For **Disk**, **CPU** & **Memory & swap** report:
`reporter.exe --disk --cpu --mem`
`administratum.exe --disk --cpu --mem`

For only **Network** report:
`reporter.exe --net`
`administratum.exe --net`
156 changes: 79 additions & 77 deletions reporter.py → administratum.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@
import requests
import speedtest

REPORT_NAME = "castle_report_"
REPORT_FORMAT = ".md"

# Time when program execution started
start_time = time.time()

# Using in provider_info func to retrieve information about provider
IP_SITE = "http://ipinfo.io/"

REPORT_TIME = datetime.now().strftime("%d.%m.%Y_%H.%M.%S")


def get_args():
"""
Get arguments from CLI
:return:
"""
root_parser = argparse.ArgumentParser(
prog="reporter",
description="""Report about the castle""",
prog="administratum",
description="""Report about your castle""",
epilog="""(c) CoolCoderCarl""",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
Expand All @@ -37,14 +48,6 @@ def get_args():
# Shortening
namespace = get_args().parse_args(sys.argv[1:])

# Start time
start_time = time.time()

# Using in provider_info func to retrieve information about provider
IP_SITE = "http://ipinfo.io/"

timestamp = datetime.now().strftime("%d.%m.%Y_%H.%M.%S")


def general_info(report_time: str):
"""
Expand All @@ -54,14 +57,16 @@ def general_info(report_time: str):
"""
print("General info providing...")
system = platform.uname()
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("## GENERAL INFO \n")
report.write("System: " + system.system + " \n")
report.write("Node Name: " + system.node + " \n")
report.write("Release: " + system.release + " \n")
report.write("Version: " + system.version + " \n")
report.write("Machine: " + system.machine + " \n")
report.write("Processor: " + system.processor + " \n")
report.write(f"System: {system.system} \n")
report.write(f"Node Name: {system.node} \n")
report.write(f"Release: {system.release} \n")
report.write(f"Version: {system.version} \n")
report.write(f"Machine: {system.machine} \n")
report.write(f"Processor: {system.processor} \n")
report.write("\n")
print("--- %s seconds ---" % (time.time() - start_time))
print("General info provided.")
Expand Down Expand Up @@ -93,13 +98,15 @@ def disk_info(report_time: str):
:return:
"""
print("Disk info providing...")
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("## DISK USAGE \n")
for key in get_disk_usage():
if "percent" in key.lower():
report.write(key + " : " + str(get_disk_usage()[key]) + "% \n")
report.write(f"{key} : {get_disk_usage()[key]}% \n")
else:
report.write(key + " : " + str(get_disk_usage()[key]) + "GB \n")
report.write(f"{key} : {get_disk_usage()[key]} GB \n")
report.write("\n")
print("--- %s seconds ---" % (time.time() - start_time))
print("Disk info provided.")
Expand Down Expand Up @@ -131,10 +138,12 @@ def cpu_times_percent_info(report_time: str):
:return:
"""
print("CPU times percent info providing...")
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("### CPU TIMES \n")
for key, value in get_cpu_percent_usage().items():
report.write(key + " : " + str(value) + "% \n")
report.write(f"{key} : {value}% \n")
report.write("\n")
print("--- %s seconds ---" % (time.time() - start_time))
print("CPU times percent info provided.")
Expand All @@ -148,13 +157,15 @@ def cpu_info(report_time: str):
:return:
"""
print("CPU info providing...")
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("## CPU USAGE \n")
report.write("Logical processors: " + str(psutil.cpu_count()) + " \n")
report.write("Frequency: " + str(psutil.cpu_freq()[0]) + " \n")
report.write(f"Logical processors: {psutil.cpu_count()} \n")
report.write(f"Frequency: {psutil.cpu_freq()[0]} \n")
report.write("\n")

cpu_times_percent_info(timestamp)
cpu_times_percent_info(REPORT_TIME)
print("--- %s seconds ---" % (time.time() - start_time))
print("CPU info provided.")

Expand Down Expand Up @@ -187,13 +198,15 @@ def swap_info(report_time: str):
:return:
"""
print("SWAP info providing...")
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("### SWAP USAGE \n")
for key in get_swap_usage():
if "percent" in key.lower():
report.write(key + " : " + str(get_swap_usage()[key]) + "% \n")
report.write(f"{key} : {get_swap_usage()[key]}% \n")
else:
report.write(key + " : " + str(get_swap_usage()[key]) + "GB \n")
report.write(f"{key} : {get_swap_usage()[key]} GB \n")
report.write("\n")
print("--- %s seconds ---" % (time.time() - start_time))
print("SWAP info provided.")
Expand Down Expand Up @@ -231,13 +244,15 @@ def mem_info(report_time: str):
:return:
"""
print("Memory info providing...")
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("## MEMORY USAGE \n")
for key in get_mem_usage():
if "percent" in key.lower():
report.write(key + " : " + str(get_mem_usage()[key]) + "% \n")
report.write(f"{key} : {get_mem_usage()[key]}% \n")
else:
report.write(key + " : " + str(get_mem_usage()[key]) + "GB \n")
report.write(f"{key} : {get_mem_usage()[key]} GB \n")
report.write("\n")

swap_info(report_time)
Expand All @@ -253,21 +268,14 @@ def network_interfaces_status(report_time: str):
"""
print("Network interfaces info providing...")
net_activity = psutil.net_if_stats()
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("### INTERFACES STATUS \n")
# Change hardcoded ?
for i in net_activity.items():
report.write(
"Connection Type Name: "
+ str(i[0])
+ " | UP: "
+ str(i[1][0])
+ " | Speed: "
+ str(i[1][2])
+ " MB"
+ " | MTU: "
+ str(i[1][3])
+ " bytes"
f"Connection Type Name: {i[0]} | UP: {i[1][0]} | Speed: {i[1][2]}MB | MTU: {i[1][3]} bytes"
)
report.write(" \n")
report.write("\n")
Expand All @@ -283,17 +291,19 @@ def isp_info(report_time: str):
:return:
"""
print("ISP info providing...")
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("### ISP INFO \n")
try:
get_provider_info = json.loads(requests.get(IP_SITE).text)
ignored_value = ["city", "region", "loc", "postal", "readme"]
for k, v in get_provider_info.items():
if k not in ignored_value:
if k == "ip":
report.write(k.upper() + ": " + v + " \n")
report.write(f"{k.upper()} : {v} \n")
else:
report.write(k.capitalize() + ": " + v + " \n")
report.write(f"{k.capitalize()} : {v} \n")
report.write("\n")
except ConnectionError as connection_error:
report.write(str(connection_error))
Expand All @@ -313,24 +323,14 @@ def network_speed(report_time: str):
speed_test = speedtest.Speedtest()
download_speed = speed_test.download()
upload_speed = speed_test.upload(pre_allocate=False)
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("### NETWORK SPEED \n")
report.write(
"#### DOWNLOAD \n"
+ str(int(download_speed))
+ " bytes. "
+ str(int(download_speed / 1024))
+ " MB."
+ " \n"
)
report.write(
"#### UPLOAD \n"
+ str(int(upload_speed))
+ " bytes. "
+ str((upload_speed / 1024))
+ " MB."
+ " \n"
)
report.write("#### DOWNLOAD \n")
report.write(f"{download_speed} bytes. {download_speed / 1024} MB. \n")
report.write("#### UPLOAD \n")
report.write(f"{upload_speed} bytes. {upload_speed / 1024} MB. \n")
print("--- %s seconds ---" % (time.time() - start_time))
print("Network speed info provided.")

Expand All @@ -345,17 +345,19 @@ def net_info(report_time: str):
:return:
"""
print("Network info providing...")
with codecs.open("report_" + report_time + ".md", "a", "utf-8") as report:
with codecs.open(
f"{REPORT_NAME}{report_time}{REPORT_FORMAT}", "a", "utf-8"
) as report:
report.write("## NETWORK USAGE \n")
net_if_address = psutil.net_if_addrs()
for i in net_if_address:
report.write(i + " \n")
report.write(f"{i} \n")
# print(net_if_address[i][1])
report.write(str(net_if_address[i][1][1:3]) + " \n")
report.write(f"{net_if_address[i][1][1:3]} \n")
report.write("\n")

network_interfaces_status(report_time)
isp_info(timestamp)
isp_info(REPORT_TIME)
network_speed(report_time)

print("--- %s seconds ---" % (time.time() - start_time))
Expand All @@ -371,18 +373,18 @@ def net_info(report_time: str):
if __name__ == "__main__":
# Fix excluding
if not (sys.argv[1:]):
general_info(timestamp)
disk_info(timestamp)
cpu_info(timestamp)
mem_info(timestamp)
net_info(timestamp)
general_info(REPORT_TIME)
disk_info(REPORT_TIME)
cpu_info(REPORT_TIME)
mem_info(REPORT_TIME)
net_info(REPORT_TIME)
else:
general_info(timestamp)
general_info(REPORT_TIME)
if namespace.disk:
disk_info(timestamp)
disk_info(REPORT_TIME)
if namespace.cpu:
cpu_info(timestamp)
cpu_info(REPORT_TIME)
if namespace.mem:
mem_info(timestamp)
mem_info(REPORT_TIME)
if namespace.net:
net_info(timestamp)
net_info(REPORT_TIME)

0 comments on commit d7b9d6a

Please sign in to comment.