-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
95 lines (73 loc) · 3.22 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from helpers.get_bearer_token import retrieve_bearer_token
from helpers.get_environment_id import get_environment_id
from helpers.get_instance_id import get_instance_id
from helpers.get_thread_dump import get_thread_dump
from helpers.get_log_file import get_log_file
# from helpers.log_analysis import parse_log_file create_bar_chart
from dotenv import load_dotenv
import os
from datetime import datetime
# Load variables from .env file
load_dotenv()
def download_thread_dump():
# Get the application name and environment from the user
application_name = input("Enter the application name: ")
environment = input("Enter the environment (DEV, INT, EDU or PROD): ")
# Retrieve the bearer token
bearer_token = retrieve_bearer_token()
try:
environment_id = get_environment_id(bearer_token, environment)
instance_id = get_instance_id(bearer_token, environment_id, application_name)
# Retrieve the thread dump
thread_dump = get_thread_dump(application_name, environment_id, instance_id)
# Define the directory to save the thread dump
dump_dir = f"thread_dumps/{environment}"
os.makedirs(dump_dir, exist_ok=True)
# Create a unique filename for the thread dump
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{dump_dir}/{application_name}_{timestamp}.txt"
# Write the thread dump to the file
with open(filename, 'w') as file:
file.write(thread_dump)
print(f"Thread dump saved to {filename}")
except Exception as e:
print(f"An error occurred: {e}")
def download_log_file():
# Get the application name and environment from the user
application_name = input("Enter the application name: ")
environment = input("Enter the environment (DEV, INT, EDU or PROD): ")
# Retrieve the bearer token
bearer_token = retrieve_bearer_token()
try:
environment_id = get_environment_id(bearer_token, environment)
instance_id = get_instance_id(bearer_token, environment_id, application_name)
# Retrieve the log file
log_file = get_log_file(application_name, environment_id, instance_id)
# Define the directory to save the log file
log_dir = f"log_files/{environment}"
os.makedirs(log_dir, exist_ok=True)
# Create a unique filename for the log file
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{log_dir}/{application_name}_{timestamp}.txt"
# Write the log to the file
with open(filename, 'w') as file:
file.write(log_file)
print(f"Log file saved to {filename}")
# Analyze the log file and create the bar chart
# log_data = parse_log_file(filename)
# create_bar_chart(log_data)
except Exception as e:
print(f"An error occurred: {e}")
def main():
print("Select the feature you want to use:")
print("1: Download Thread Dump")
print("2: Download Log File")
choice = input("Enter your choice (1 or 2): ")
if choice == '1':
download_thread_dump()
elif choice == '2':
download_log_file()
else:
print("Invalid choice. Please enter 1 or 2.")
if __name__ == "__main__":
main()