김민석

최종 업로드

Showing 61 changed files with 749 additions and 0 deletions
No preview for this file type
No preview for this file type
# -*- coding: utf-8 -*-
\ No newline at end of file
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
import traceback
import MySQLdb, json
from common.testException import TestDBException
logger = logging.getLogger("db_logger")
class TestDB():
db = None
def __init__(self):
try:
self.db = MySQLdb.connect(host='localhost', user='root', passwd='PASSWORD', db='mydb', port=3306, charset='utf8')
except Exception as e:
logger.error(traceback.format_exc())
raise TestDBException(-1, "TestDBException: cannot connect TestDB(%s)"%(e[1]))
def commitDB(self):
try:
self.db.commit()
except Exception as e:
logger.error(traceback.format_exc())
raise TestDBException(-1, "TestDBException: cannot commit db(%s)"%(e[1]))
def rollbackDB(self):
try:
self.db.rollback()
except Exception as e:
logger.error(traceback.format_exc())
raise TestDBException(-1, "TestDBException: cannot rollback db(%s)"%(e[1]))
def closeDB(self):
try:
self.db.close()
except Exception as e:
logger.error(traceback.format_exc())
raise TestDBException(-1, "TestDBException: cannot close db connection(%s)"%(e[1]))
def getDictCursor(self):
try:
return self.db.cursor(MySQLdb.cursors.DictCursor)
except Exception as e:
logger.error(traceback.format_exc())
raise TestDBException(-1, "TestDBException: cannot get mysql dict cursor(%s)"%(e[1]))
def getCommonCursor(self):
try:
return self.db.cursor()
except Exception as e:
logger.error(traceback.format_exc())
raise TestDBException(-1, "TestDBException: cannot get mysql common cursor(%s)"%(e[1]))
def executeQuery(self, cursor, query):
try:
logger.info(query)
row = cursor.execute(query)
return row
except Exception as e:
logger.error(traceback.format_exc())
logger.error(query)
raise TestDBException(-1, "TestDBException: cannot execute query(%s)" %(query))
def executeSelectQuery(self, query, one=False):
try:
cursor = self.getDictCursor()
self.executeQuery(cursor, query)
if one:
res = cursor.fetchone()
else:
res = cursor.fetchall()
self.closeDbCursor(cursor)
return res
except TestDBException as e:
raise e
except Exception as e:
print(traceback.format_exc())
raise TestDBException(-1, "TestDBException: executeSelectQuery()")
def closeDbCursor(self, cursor):
try:
cursor.close()
except Exception as e:
logger.error(traceback.format_exc())
raise TestDBException(-1, "TestDBException: cannot close db cursor(%s)"%(e[1]))
# insert api call log function
def insertIntoApiCallLog(self, url, ip, method, response_time, result):
try:
_id = None
cursor = self.getDictCursor()
query = ("""INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('%s', '%s', '%s', '%s', '%s', '%s');"""
% (url, ip, method, result.get('code'), result.get('message'), response_time))
row = self.executeQuery(cursor, query)
if row > 0:
_id = cursor.lastrowid
self.commitDB()
self.closeDbCursor(cursor)
return _id
except Exception as e:
print(traceback.format_exc())
logger.error(traceback.format_exc())
raise TestDBException(-1, "TestDBException: insertIntoApiCallLog()")
def selectApiCallLog(self):
try:
_id = None
cursor = self.getDictCursor()
query = """SELECT * FROM api_call_log;"""
self.executeQuery(cursor, query)
logList = cursor.fetchall()
self.closeDbCursor(cursor)
return logList
except Exception as e:
print(traceback.format_exc())
logger.error(traceback.format_exc())
raise TestDBException(-1, "TestDBException: selectApiCallLog()")
\ No newline at end of file
No preview for this file type
#!/usr/bin/python
# -*- coding: utf-8 -*-
class TestException(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
class TestDBException(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
\ No newline at end of file
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
def tic(tag=None):
"""
Start timer function.
tag = used to link a tic to a later toc. Can be any dictionary-able key.
"""
global TIC_TIME
if tag is None:
tag = 'default'
try:
TIC_TIME[tag] = time.time()
except NameError:
TIC_TIME = {tag: time.time()}
def toc(tag=None, save=False, fmt=False):
"""
Timer ending function.
tag - used to link a toc to a previous tic. Allows multipler timers, nesting timers.
save - if True, returns int time to out (in ms)
fmt - if True, formats time in H:M:S, if False just seconds.
"""
global TOC_TIME
template = 'Elapsed time is:'
if tag is None:
tag = 'default'
else:
template = u'%s - '%tag + template
try:
TOC_TIME[tag] = time.time()
except NameError:
TOC_TIME = {tag: time.time()}
if TIC_TIME:
d = int((TOC_TIME[tag]-TIC_TIME[tag]) * 1000)
if save: return d
else:
print("no tic() start time available. Check global var settings")
\ No newline at end of file
#!/usr/bin/python
# -*- coding: utf-8 -*-import json
import traceback
import json
import datetime
import time
from rest_framework.decorators import api_view
from django.http import HttpResponse
from common.testDB import TestDB
import logging
from common.testFunctions import tic, toc
logger = logging.getLogger("common_logger")
# check response time decorator
def response_timer(function=None, home_url=None, redirect_field_name=None):
def _dec(view_func):
def _view(request, *args, **kwargs):
result = {}
try:
tic(request.path)
return view_func(request, *args, **kwargs)
except:
print(traceback.format_exc())
result['code'] = 500
result['message'] = 'Internal Server Error'
return returnHttpResponseLogging(request, result)
_view.__name__ = view_func.__name__
_view.__dict__ = view_func.__dict__
_view.__doc__ = view_func.__doc__
return _view
if function is None:
return _dec
else:
return _dec(function)
def returnHttpResponseLogging(request, result):
try:
db = TestDB()
url = request.path
ip = request.META['REMOTE_ADDR']
method = request.method
response_time = toc(request.path, True)
db.insertIntoApiCallLog(url, ip, method, response_time, result)
db.closeDB()
except:
print(traceback.format_exc())
json_data = json.dumps(result, default=datetime_handler)
return HttpResponse(json_data, content_type="application/json")
@response_timer
@api_view(["GET"])
def monitoringGetTest(request):
try:
result = dict()
db = TestDB()
result['data'] = db.selectApiCallLog()
result['code'] = 200
result['message'] = 'OK'
logger.info("""HTTP method used: %s, client IP : %s, message : %s, code : %s""",request.method ,request.META['REMOTE_ADDR'], result['message'], result['code'])
except Exception as e:
result['code'] = 500
result['message'] = 'testMonitoring Internal Error'
logger.error(traceback.format_exc())
raise TestException(1, "TestException: monitoringPostTest()")
finally:
return returnHttpResponseLogging(request, result)
@response_timer
@api_view(["POST"])
def monitoringPostTest(request):
try:
result = dict()
db = TestDB()
result['data'] = db.selectApiCallLog()
result['code'] = 200
result['message'] = 'OK'
logger.info("""HTTP method used: %s, client IP : %s, message : %s, code : %s""",request.method ,request.META['REMOTE_ADDR'], result['message'], result['code'])
except Exception as e:
result['code'] = 500
result['message'] = 'testMonitoring Internal Error'
logger.error(traceback.format_exc())
raise TestException(1, "TestException: monitoringPostTest()")
finally:
return returnHttpResponseLogging(request, result)
@response_timer
@api_view(["DELETE"])
def monitoringDeleteTest(request):
try:
result = dict()
db = TestDB()
result['data'] = db.selectApiCallLog()
result['code'] = 200
result['message'] = 'OK'
logger.info("""HTTP method used: %s, client IP : %s, message : %s, code : %s""",request.method ,request.META['REMOTE_ADDR'], result['message'], result['code'])
except Exception as e:
result['code'] = 500
result['message'] = 'testMonitoring Internal Error'
logger.error(traceback.format_exc())
raise TestException(1, "TestException: monitoring()")
finally:
return returnHttpResponseLogging(request, result)
@response_timer
@api_view(["PUT"])
def monitoringPutTest(request):
try:
result = dict()
db = TestDB()
result['data'] = db.selectApiCallLog()
result['code'] = 200
result['message'] = 'OK'
logger.info("""HTTP method used: %s, client IP : %s, message : %s, code : %s""",request.method ,request.META['REMOTE_ADDR'], result['message'], result['code'])
except Exception as e:
result['code'] = 500
result['message'] = 'testMonitoring Internal Error'
logger.error(traceback.format_exc())
raise TestException(1, "TestException: monitoringPostTest()")
finally:
return returnHttpResponseLogging(request, result)
def datetime_handler(x):
if isinstance(x, datetime.datetime):
return x.isoformat()
raise TypeError("Unknown type")
\ No newline at end of file
No preview for this file type
No preview for this file type
from locust import HttpUser, task, between
class WebsiteTestUser(HttpUser):
wait_time = between(1, 2.5)
@task
def my_task(self):
self.client.get("")
\ No newline at end of file
This diff is collapsed. Click to expand it.
[2021-05-25 20:05:32] INFO [common_logger.monitoringGetTest:70]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:07:41] INFO [common_logger.monitoringGetTest:70]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:09:18] INFO [common_logger.monitoringGetTest:70]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:09:43] INFO [common_logger.monitoringGetTest:70]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:14:43] INFO [common_logger.monitoringGetTest:70]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:14:45] INFO [common_logger.monitoringGetTest:70]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:14:45] INFO [common_logger.monitoringGetTest:70]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:15:57] INFO [common_logger.monitoringGetTest:70]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:17:16] INFO [common_logger.monitoringGetTest:70]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:23:03] INFO [common_logger.monitoringGetTest:67]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:37:29] INFO [common_logger.monitoringPostTest:91]:: HTTP method used: POST, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:37:38] INFO [common_logger.monitoringDeleteTest:115]:: HTTP method used: DELETE, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:37:45] INFO [common_logger.monitoringPutTest:139]:: HTTP method used: PUT, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:38:32] INFO [common_logger.monitoringGetTest:67]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:38:59] INFO [common_logger.monitoringGetTest:67]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-05-25 20:40:35] INFO [common_logger.monitoringGetTest:67]:: HTTP method used: GET, client IP : 192.168.0.49, message : OK, code : 200
[2021-05-25 20:41:54] INFO [common_logger.monitoringGetTest:67]:: HTTP method used: GET, client IP : 192.168.0.50, message : OK, code : 200
[2021-05-25 20:42:11] INFO [common_logger.monitoringGetTest:67]:: HTTP method used: GET, client IP : 192.168.0.50, message : OK, code : 200
[2021-06-09 23:26:26] ERROR [common_logger.monitoringGetTest:71]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/views.py", line 59, in monitoringGetTest
db = TestDB()
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 18, in __init__
raise TestDBException(-1, "TestDBException: cannot connect TestDB(%s)"%(e[1]))
TypeError: __init__() takes exactly 2 arguments (3 given)
[2021-06-09 23:29:03] ERROR [common_logger.monitoringGetTest:71]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/views.py", line 59, in monitoringGetTest
db = TestDB()
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 18, in __init__
raise TestDBException(-1, "TestDBException: cannot connect TestDB(%s)"%(e[1]))
TypeError: __init__() takes exactly 2 arguments (3 given)
[2021-06-09 23:29:39] INFO [common_logger.monitoringGetTest:66]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-06-09 23:30:13] INFO [common_logger.monitoringGetTest:66]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-06-09 23:30:13] INFO [common_logger.monitoringGetTest:66]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-06-09 23:31:34] INFO [common_logger.monitoringGetTest:69]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
[2021-06-09 23:51:05] INFO [common_logger.monitoringGetTest:69]:: HTTP method used: GET, client IP : 127.0.0.1, message : OK, code : 200
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
[2021-05-25 20:05:32] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:05:32] ERROR [db_logger.insertIntoApiCallLog:110]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 98, in insertIntoApiCallLog
% (url, calcIPValue(src_ipaddr_str), src_ipaddr_str, method, result.get('code'), result.get('message'), response_time))
NameError: global name 'calcIPValue' is not defined
[2021-05-25 20:07:41] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:07:41] ERROR [db_logger.insertIntoApiCallLog:110]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 98, in insertIntoApiCallLog
% (url, ip, method, result.get('code'), result.get('message'), response_time))
TypeError: not enough arguments for format string
[2021-05-25 20:09:18] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:09:18] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/getTest/', 127.0.0.1, 'GET', '200', 'OK', '21');
[2021-05-25 20:09:18] ERROR [db_logger.executeQuery:59]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 56, in executeQuery
row = cursor.execute(query)
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.0.1, 'GET', '200', 'OK', '21')' at line 1")
[2021-05-25 20:09:18] ERROR [db_logger.executeQuery:60]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/getTest/', 127.0.0.1, 'GET', '200', 'OK', '21');
[2021-05-25 20:09:18] ERROR [db_logger.insertIntoApiCallLog:110]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 99, in insertIntoApiCallLog
row = self.executeQuery(cursor, query)
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 61, in executeQuery
raise TestDBException(-1, "TestDBException: cannot execute query(%s)" %(query))
TypeError: __init__() takes exactly 2 arguments (3 given)
[2021-05-25 20:09:43] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:09:43] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/getTest/', '127.0.0.1', 'GET', '200', 'OK', '27');
[2021-05-25 20:14:43] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:14:43] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/getTest/', '127.0.0.1', 'GET', '200', 'OK', '28');
[2021-05-25 20:14:45] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:14:45] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/getTest/', '127.0.0.1', 'GET', '200', 'OK', '8');
[2021-05-25 20:14:45] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:14:45] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/getTest/', '127.0.0.1', 'GET', '200', 'OK', '3');
[2021-05-25 20:15:57] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:15:57] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '22');
[2021-05-25 20:17:16] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:17:16] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '14');
[2021-05-25 20:17:16] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '500', 'Internal Server Error', '36');
[2021-05-25 20:23:03] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:23:03] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '27');
[2021-05-25 20:37:29] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:37:29] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringPostTest', '127.0.0.1', 'POST', '200', 'OK', '17');
[2021-05-25 20:37:38] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:37:38] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringDeleteTest', '127.0.0.1', 'DELETE', '200', 'OK', '10');
[2021-05-25 20:37:45] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log;
[2021-05-25 20:37:45] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringPutTest', '127.0.0.1', 'PUT', '200', 'OK', '3');
[2021-05-25 20:38:32] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-05-25 20:38:32] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '17');
[2021-05-25 20:38:59] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-05-25 20:38:59] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '20');
[2021-05-25 20:40:35] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-05-25 20:40:35] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '192.168.0.49', 'GET', '200', 'OK', '21');
[2021-05-25 20:41:54] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-05-25 20:41:54] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '192.168.0.50', 'GET', '200', 'OK', '2');
[2021-05-25 20:42:11] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-05-25 20:42:11] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '192.168.0.50', 'GET', '200', 'OK', '1');
[2021-06-09 23:26:26] ERROR [db_logger.__init__:17]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 15, in __init__
self.db = MySQLdb.connect(host='localhost', user='root', passwd='', db='mydb', port=3306, charset='utf8')
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")
[2021-06-09 23:26:26] ERROR [db_logger.__init__:17]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 15, in __init__
self.db = MySQLdb.connect(host='localhost', user='root', passwd='', db='mydb', port=3306, charset='utf8')
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")
[2021-06-09 23:29:03] ERROR [db_logger.__init__:17]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 15, in __init__
self.db = MySQLdb.connect(host='localhost', user='root', passwd='', db='mydb', port=3306, charset='utf8')
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")
[2021-06-09 23:29:03] ERROR [db_logger.__init__:17]:: Traceback (most recent call last):
File "/Users/nhn/Desktop/capstone/testMonitoring/common/testDB.py", line 15, in __init__
self.db = MySQLdb.connect(host='localhost', user='root', passwd='', db='mydb', port=3306, charset='utf8')
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/Users/nhn/.pyenv/versions/testVirenv/lib/python2.7/site-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")
[2021-06-09 23:29:39] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-06-09 23:29:39] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '13');
[2021-06-09 23:30:13] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-06-09 23:30:13] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '2');
[2021-06-09 23:30:13] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-06-09 23:30:13] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '3');
[2021-06-09 23:31:33] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-06-09 23:31:34] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '1016');
[2021-06-09 23:51:05] INFO [db_logger.executeQuery:55]:: SELECT * FROM api_call_log LIMIT 10;
[2021-06-09 23:51:05] INFO [db_logger.executeQuery:55]:: INSERT INTO api_call_log (url, ip, method, ret_code, ret_message, response_time) VALUES ('/tests/monitoringGetTest', '127.0.0.1', 'GET', '200', 'OK', '18');
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testMonitoring.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
"""
Django settings for testMonitoring project.
Generated by 'django-admin startproject' using Django 1.11.5.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'n8(d7&b)3mg(518^8=vn-5!_1+iu#a*nf%a)l(!dryh5%9#7++'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = [
'*'
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'common',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'testMonitoring.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'testMonitoring.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'ko-kr'
TIME_ZONE = 'Asia/Seoul'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
},
},
'formatters': {
'simple': {
'format': '[%(asctime)s] %(levelname)s:: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S'
},
'verbose': {
'format': '[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d]:: %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'db_logfile': {
'level': 'DEBUG',
'class': 'logging.handlers.TimedRotatingFileHandler',
'when': "midnight",
'backupCount':15,
'filename': '/Users/nhn/Desktop/capstone/testMonitoring/logs/db.log',
'formatter': 'verbose'
},
'common_logfile': {
'level': 'DEBUG',
'class': 'logging.handlers.TimedRotatingFileHandler',
'when': "midnight",
'backupCount':15,
'filename': '/Users/nhn/Desktop/capstone/testMonitoring/logs/common.log',
'formatter': 'verbose'
},
},
'loggers': {
'db_logger': {
'level': 'DEBUG',
'handlers': ['db_logfile'],
},
'common_logger': {
'level': 'DEBUG',
'handlers': ['common_logfile'],
},
}
}
\ No newline at end of file
"""testMonitoring URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include, url
from django.contrib import admin
from common import views as common
urlpatterns = [
url(r'^tests/', include('urls.tests_url')),
]
"""
WSGI config for testMonitoring project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testMonitoring.settings")
application = get_wsgi_application()
No preview for this file type
# -*- coding: utf-8 -*-
__author__ = 'Minseok'
from django.conf.urls import url
from common import views as tests
urlpatterns = [
url(r'^monitoringGetTest$', tests.monitoringGetTest),
url(r'^monitoringPostTest$', tests.monitoringPostTest),
url(r'^monitoringDeleteTest$', tests.monitoringDeleteTest),
url(r'^monitoringPutTest$', tests.monitoringPutTest),
]
\ No newline at end of file