oracle_alert = open("c:\\data\\alert_log.txt", encoding='utf8')
oracle_text = oracle_alert.read()
lines = oracle_text.split()
error_list = []
from collections import Counter
import pandas as pd
import matplotlib.pyplot as plt
while True:
print('==========================================================')
print('dba 작업을 편하게 하기 위한 자동화 스크립트')
print('1. alert_log file의 뒷부분')
print('2. alert_log file에서 오류를 막대그래프로')
print('3. alert lof file에서 전체 에러 메시지 종류 및 개수')
print('9. 종료')
print('==========================================================')
num = input('번호를 입력하세요.')
if num == '1':
print(oracle_text[-900:])
break
elif num == '2':
for i in lines:
if 'ORA-' in i:
error_list.append(i.strip(':'))
df_error = pd.DataFrame(list(Counter(error_list).items()), columns=['에러번호', '건수'])
df_sort = df_error.loc[ df_error.건수 >= 20 , : ].sort_values(by='건수', ascending=False)
x = df_sort.loc[ :, ['에러번호']]
y = df_sort.loc[ :, ['건수']]
plt.rcParams['font.family'] = 'Malgun Gothic' #한글 깨지지 않게 해주는 코드
plt.bar(x['에러번호'], y['건수'])
break
elif num == '3':
for i in lines:
if 'ORA-' in i:
error_list.append(i.strip(':'))
print(Counter(error_list))
break
elif num == '9':
break