김민석

최종 업로드

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