cavisson-pythonagent 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cavisson_pythonagent-0.0.1.dist-info/METADATA +32 -0
- cavisson_pythonagent-0.0.1.dist-info/RECORD +180 -0
- cavisson_pythonagent-0.0.1.dist-info/WHEEL +5 -0
- cavisson_pythonagent-0.0.1.dist-info/licenses/LICENSE +19 -0
- cavisson_pythonagent-0.0.1.dist-info/top_level.txt +1 -0
- pythonagent/__init__.py +22 -0
- pythonagent/agent/__init__.py +219 -0
- pythonagent/agent/internal/__init__.py +1 -0
- pythonagent/agent/internal/agent.py +1651 -0
- pythonagent/agent/internal/framesinfo.py +152 -0
- pythonagent/agent/internal/heap_dump.py +39 -0
- pythonagent/agent/internal/intercept_module.py +70 -0
- pythonagent/agent/internal/logs.py +122 -0
- pythonagent/agent/internal/metadata/__init__.py +0 -0
- pythonagent/agent/internal/metadata/agent_meta_data.py +276 -0
- pythonagent/agent/internal/proc_compat.py +75 -0
- pythonagent/agent/internal/profile.py +47 -0
- pythonagent/agent/internal/provider.py +83 -0
- pythonagent/agent/internal/thread_dump.py +85 -0
- pythonagent/agent/internal/udp.py +245 -0
- pythonagent/agent/internal/udp_message.py +800 -0
- pythonagent/agent/probes/Instrumentation/__init__.py +340 -0
- pythonagent/agent/probes/Instrumentation/find.py +243 -0
- pythonagent/agent/probes/Instrumentation/module_version_resolver.py +155 -0
- pythonagent/agent/probes/Instrumentation/new_parser.py +64 -0
- pythonagent/agent/probes/Instrumentation/parser.py +129 -0
- pythonagent/agent/probes/__init__.py +219 -0
- pythonagent/agent/probes/base.py +303 -0
- pythonagent/agent/probes/cache/__init__.py +51 -0
- pythonagent/agent/probes/cache/redis.py +119 -0
- pythonagent/agent/probes/cache/redis_asyncio.py +83 -0
- pythonagent/agent/probes/coroutines/__init__.py +1 -0
- pythonagent/agent/probes/coroutines/asyncio.py +63 -0
- pythonagent/agent/probes/elasticdb/__init__.py +7 -0
- pythonagent/agent/probes/elasticdb/aelastic.py +54 -0
- pythonagent/agent/probes/frameworks/__init__.py +27 -0
- pythonagent/agent/probes/frameworks/agentprofiler.py +105 -0
- pythonagent/agent/probes/frameworks/aiohttp_web.py +155 -0
- pythonagent/agent/probes/frameworks/aisess.py +151 -0
- pythonagent/agent/probes/frameworks/asgi.py +340 -0
- pythonagent/agent/probes/frameworks/bottle.py +27 -0
- pythonagent/agent/probes/frameworks/cherry.py +25 -0
- pythonagent/agent/probes/frameworks/django.py +128 -0
- pythonagent/agent/probes/frameworks/falcon.py +21 -0
- pythonagent/agent/probes/frameworks/fastapi.py +35 -0
- pythonagent/agent/probes/frameworks/flask.py +30 -0
- pythonagent/agent/probes/frameworks/pyramid.py +56 -0
- pythonagent/agent/probes/frameworks/test.py +108 -0
- pythonagent/agent/probes/frameworks/tornado_async_web.py +117 -0
- pythonagent/agent/probes/frameworks/tornado_web.py +133 -0
- pythonagent/agent/probes/frameworks/wsgi.py +353 -0
- pythonagent/agent/probes/grpc/__init__.py +76 -0
- pythonagent/agent/probes/grpc/client_interceptor.py +132 -0
- pythonagent/agent/probes/grpc/server_interceptor.py +129 -0
- pythonagent/agent/probes/havoc/__init__.py +0 -0
- pythonagent/agent/probes/havoc/custom_memory_stress.py +186 -0
- pythonagent/agent/probes/havoc/custom_thread_stress.py +187 -0
- pythonagent/agent/probes/havoc/havoc_constants.py +218 -0
- pythonagent/agent/probes/havoc/havoc_manager.py +981 -0
- pythonagent/agent/probes/http/__init__.py +49 -0
- pythonagent/agent/probes/http/aiohttp_client.py +59 -0
- pythonagent/agent/probes/http/boto.py +12 -0
- pythonagent/agent/probes/http/httplib.py +110 -0
- pythonagent/agent/probes/http/httpx_client.py +116 -0
- pythonagent/agent/probes/http/requests.py +15 -0
- pythonagent/agent/probes/http/tornado_httpclient.py +85 -0
- pythonagent/agent/probes/http/urllib3.py +16 -0
- pythonagent/agent/probes/langchain/__init__.py +21 -0
- pythonagent/agent/probes/langchain/base_tool.py +95 -0
- pythonagent/agent/probes/langchain/langchain_community.py +136 -0
- pythonagent/agent/probes/langchain/langchain_core.py +32 -0
- pythonagent/agent/probes/langchain/langchain_openai.py +110 -0
- pythonagent/agent/probes/logging/__init__.py +106 -0
- pythonagent/agent/probes/message_brokers/__init__.py +4 -0
- pythonagent/agent/probes/message_brokers/pika.py +126 -0
- pythonagent/agent/probes/mongodb/__init__.py +6 -0
- pythonagent/agent/probes/mongodb/pymongo.py +286 -0
- pythonagent/agent/probes/openai/__init__.py +3 -0
- pythonagent/agent/probes/openai/openai.py +797 -0
- pythonagent/agent/probes/span.py +101 -0
- pythonagent/agent/probes/sql/__init__.py +13 -0
- pythonagent/agent/probes/sql/botocores3.py +51 -0
- pythonagent/agent/probes/sql/dbapi.py +285 -0
- pythonagent/agent/probes/sql/dynamodb.py +90 -0
- pythonagent/agent/probes/sql/mysql_connector.py +24 -0
- pythonagent/agent/probes/sql/mysql_connector_cext.py +24 -0
- pythonagent/agent/probes/sql/mysqldb.py +43 -0
- pythonagent/agent/probes/sql/psycopg2.py +174 -0
- pythonagent/agent/probes/sql/pymysql.py +25 -0
- pythonagent/bootstrap/__init__.py +0 -0
- pythonagent/bootstrap/cav_gunicorn.py +26 -0
- pythonagent/bootstrap/cavagent_lambda_wrapper.py +291 -0
- pythonagent/bootstrap/run.py +47 -0
- pythonagent/bootstrap/sitecustomize.py +287 -0
- pythonagent/cavisson/netdiagnostics/CavAgent/instrumentationprofile.json +26 -0
- pythonagent/cavisson/netdiagnostics/CavAgent/interceptor_points.txt +29 -0
- pythonagent/cavisson/netdiagnostics/python/CavAgent/instrumentationprofile.json +42 -0
- pythonagent/cavisson/netdiagnostics/python/CavAgent/interceptor_points.txt +29 -0
- pythonagent/cavisson/netdiagnostics/python/config/ndsettings.conf +6 -0
- pythonagent/config.py +279 -0
- pythonagent/find.py +72 -0
- pythonagent/find_mod_cls_name.py +54 -0
- pythonagent/lang.py +131 -0
- pythonagent/lib.py +91 -0
- pythonagent/main/__init__.py +0 -0
- pythonagent/main/pytrace/__init__.py +79 -0
- pythonagent/main/pytrace/commands/__init__.py +0 -0
- pythonagent/main/pytrace/commands/auto_discovery.py +25 -0
- pythonagent/main/pytrace/commands/run.py +401 -0
- pythonagent/main/pytrace/pytrace.py +133 -0
- pythonagent/main/wsgi.py +6 -0
- pythonagent/main.py +27 -0
- pythonagent/run.py +46 -0
- pythonagent/sqins.py +8 -0
- pythonagent/test.py +73 -0
- pythonagent/utils.py +168 -0
- pythonagent/vendor/__init__.py +0 -0
- pythonagent/vendor/pympler/__init__.py +1 -0
- pythonagent/vendor/pympler/asizeof.py +2810 -0
- pythonagent/vendor/pympler/charts.py +62 -0
- pythonagent/vendor/pympler/classtracker.py +590 -0
- pythonagent/vendor/pympler/classtracker_stats.py +780 -0
- pythonagent/vendor/pympler/garbagegraph.py +80 -0
- pythonagent/vendor/pympler/mprofile.py +97 -0
- pythonagent/vendor/pympler/muppy.py +275 -0
- pythonagent/vendor/pympler/panels.py +115 -0
- pythonagent/vendor/pympler/process.py +238 -0
- pythonagent/vendor/pympler/py.typed +0 -0
- pythonagent/vendor/pympler/refbrowser.py +451 -0
- pythonagent/vendor/pympler/refgraph.py +350 -0
- pythonagent/vendor/pympler/summary.py +321 -0
- pythonagent/vendor/pympler/tracker.py +267 -0
- pythonagent/vendor/pympler/util/__init__.py +0 -0
- pythonagent/vendor/pympler/util/bottle.py +3809 -0
- pythonagent/vendor/pympler/util/compat.py +23 -0
- pythonagent/vendor/pympler/util/stringutils.py +77 -0
- pythonagent/vendor/pympler/web.py +346 -0
- pythonagent/vendor/werkzeug/__init__.py +20 -0
- pythonagent/vendor/werkzeug/_compat.py +228 -0
- pythonagent/vendor/werkzeug/_internal.py +473 -0
- pythonagent/vendor/werkzeug/_reloader.py +341 -0
- pythonagent/vendor/werkzeug/datastructures.py +3120 -0
- pythonagent/vendor/werkzeug/debug/__init__.py +498 -0
- pythonagent/vendor/werkzeug/debug/console.py +218 -0
- pythonagent/vendor/werkzeug/debug/repr.py +297 -0
- pythonagent/vendor/werkzeug/debug/tbtools.py +628 -0
- pythonagent/vendor/werkzeug/exceptions.py +829 -0
- pythonagent/vendor/werkzeug/filesystem.py +64 -0
- pythonagent/vendor/werkzeug/formparser.py +584 -0
- pythonagent/vendor/werkzeug/http.py +1307 -0
- pythonagent/vendor/werkzeug/local.py +420 -0
- pythonagent/vendor/werkzeug/middleware/__init__.py +25 -0
- pythonagent/vendor/werkzeug/middleware/dispatcher.py +66 -0
- pythonagent/vendor/werkzeug/middleware/http_proxy.py +219 -0
- pythonagent/vendor/werkzeug/middleware/lint.py +408 -0
- pythonagent/vendor/werkzeug/middleware/profiler.py +132 -0
- pythonagent/vendor/werkzeug/middleware/proxy_fix.py +169 -0
- pythonagent/vendor/werkzeug/middleware/shared_data.py +293 -0
- pythonagent/vendor/werkzeug/posixemulation.py +117 -0
- pythonagent/vendor/werkzeug/routing.py +2210 -0
- pythonagent/vendor/werkzeug/security.py +249 -0
- pythonagent/vendor/werkzeug/serving.py +1117 -0
- pythonagent/vendor/werkzeug/test.py +1123 -0
- pythonagent/vendor/werkzeug/testapp.py +241 -0
- pythonagent/vendor/werkzeug/urls.py +1138 -0
- pythonagent/vendor/werkzeug/useragents.py +202 -0
- pythonagent/vendor/werkzeug/utils.py +778 -0
- pythonagent/vendor/werkzeug/wrappers/__init__.py +36 -0
- pythonagent/vendor/werkzeug/wrappers/accept.py +50 -0
- pythonagent/vendor/werkzeug/wrappers/auth.py +33 -0
- pythonagent/vendor/werkzeug/wrappers/base_request.py +673 -0
- pythonagent/vendor/werkzeug/wrappers/base_response.py +700 -0
- pythonagent/vendor/werkzeug/wrappers/common_descriptors.py +341 -0
- pythonagent/vendor/werkzeug/wrappers/cors.py +100 -0
- pythonagent/vendor/werkzeug/wrappers/etag.py +304 -0
- pythonagent/vendor/werkzeug/wrappers/json.py +145 -0
- pythonagent/vendor/werkzeug/wrappers/request.py +49 -0
- pythonagent/vendor/werkzeug/wrappers/response.py +84 -0
- pythonagent/vendor/werkzeug/wrappers/user_agent.py +14 -0
- pythonagent/vendor/werkzeug/wsgi.py +1000 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
"""Entry-point interceptors for various web/application frameworks.
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import unicode_literals
|
|
7
|
+
|
|
8
|
+
from .django import intercept_django_wsgi_handler, intercept_django_base_handler, intercept_django_asgi_handler
|
|
9
|
+
from .flask import intercept_flask
|
|
10
|
+
from .bottle import intercept_bottle
|
|
11
|
+
from .tornado_web import intercept_tornado_web
|
|
12
|
+
from .cherry import intercept_cherrypy
|
|
13
|
+
from .pyramid import intercept_pyramid
|
|
14
|
+
from .falcon import intercept_falcon
|
|
15
|
+
from .fastapi import intercept_fastapi_asgi_handler
|
|
16
|
+
from .tornado_async_web import intercept_tornado_async_web
|
|
17
|
+
from .aiohttp_web import intercept_aiohttp_web
|
|
18
|
+
from .asgi import intercept_uvicorn_config
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
#__all__ = [
|
|
22
|
+
# 'intercept_flask',
|
|
23
|
+
# 'intercept_django_wsgi_handler',
|
|
24
|
+
# 'intercept_django_base_handler',
|
|
25
|
+
# 'intercept_bottle',
|
|
26
|
+
# 'intercept_tornado_web',
|
|
27
|
+
#]
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from pyclbr import readmodule
|
|
2
|
+
import os
|
|
3
|
+
import threading
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def application_callable_pro(self, application, instance, environ, start_response):
|
|
7
|
+
stack = inspect.stack()
|
|
8
|
+
temp={}
|
|
9
|
+
the_method_called = stack[3][0].f_code.co_name
|
|
10
|
+
request = Request(environ)
|
|
11
|
+
prof = cProfile.Profile()
|
|
12
|
+
prof.enable()
|
|
13
|
+
bt = self.start_business_transaction(request.full_path, '')
|
|
14
|
+
self.agent.logger.debug("Modulename: WSGI intercepto class || bt value is :{0}".format(bt))
|
|
15
|
+
method = self.agent.method_entry(bt,the_method_called)
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
self.agent.logger.info("Modulename: WSGI interceptor class || request is :{0} || request path is {1} || query_string: {2} || host: {3} ".format(request,(request.path,request.query_string,request.host)))
|
|
19
|
+
except:
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
response = application(instance, environ, self._make_start_response_wrapper(start_response))
|
|
24
|
+
self.agent.logger.info("Modulename: WSGI interceptor class || response is :{0}".format(response))
|
|
25
|
+
|
|
26
|
+
except:
|
|
27
|
+
with self.log_exceptions():
|
|
28
|
+
if bt:
|
|
29
|
+
bt.add_exception(*sys.exc_info())
|
|
30
|
+
raise
|
|
31
|
+
finally:
|
|
32
|
+
method = the_method_called
|
|
33
|
+
self.agent.method_exit(bt,method)
|
|
34
|
+
self.end_business_transaction(bt)
|
|
35
|
+
prof.disable()
|
|
36
|
+
prof.print_stats()
|
|
37
|
+
p = pstats.Stats(prof)
|
|
38
|
+
#client application path
|
|
39
|
+
client_app_root = os.path.dirname(sys.argv[0])
|
|
40
|
+
|
|
41
|
+
for k,v in p.stats.items():
|
|
42
|
+
|
|
43
|
+
if client_app_root in k[0]:
|
|
44
|
+
module = k[0]
|
|
45
|
+
print("module:-", k[0])
|
|
46
|
+
module_path = os.path.split(os.path.abspath(module))[0]
|
|
47
|
+
modulefullname = os.path.split(os.path.abspath(module))[1]
|
|
48
|
+
module_name = modulefullname.split('.')[0]
|
|
49
|
+
methodname = k[-1]
|
|
50
|
+
print('module path:-', module_path)
|
|
51
|
+
print('module name:-', module_name)
|
|
52
|
+
print('method name:- ',k[-1])
|
|
53
|
+
print('Total call:- ',v[1])
|
|
54
|
+
print('Response time of method:-',v[3])
|
|
55
|
+
mod = readmodule(module_name, path=[module_path])
|
|
56
|
+
li = []
|
|
57
|
+
for k, v in mod.items():
|
|
58
|
+
li.append(k)
|
|
59
|
+
methods = v.methods.items()
|
|
60
|
+
lk = []
|
|
61
|
+
for method, lineno in methods:
|
|
62
|
+
lk.append(method)
|
|
63
|
+
li.append(lk)
|
|
64
|
+
count=0
|
|
65
|
+
for i in li:
|
|
66
|
+
count +=1
|
|
67
|
+
if type(i)==str:
|
|
68
|
+
pass
|
|
69
|
+
else:
|
|
70
|
+
for j in i:
|
|
71
|
+
if j == methodname:
|
|
72
|
+
print("classname:-",li[count-2])
|
|
73
|
+
else:
|
|
74
|
+
pass
|
|
75
|
+
return response
|
|
76
|
+
|
|
77
|
+
def application_callable(self, application, instance, environ, start_response):
|
|
78
|
+
stack = inspect.stack()
|
|
79
|
+
temp={}
|
|
80
|
+
the_method_called = stack[3][0].f_code.co_name
|
|
81
|
+
request = Request(environ)
|
|
82
|
+
bt = self.start_business_transaction(request.full_path, '')
|
|
83
|
+
self.agent.logger.debug("Modulename: WSGI interceptor class || bt value is :{0}".format(bt))
|
|
84
|
+
method = self.agent.method_entry(bt,the_method_called)
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
self.agent.logger.info("Modulename: WSGI interceptor class || request is :{0} || request path is {1} || query_string: {2} || host: {3} ".format(request,(request.path,request.query_string,request.host)))
|
|
88
|
+
except:
|
|
89
|
+
pass
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
response = application(instance, environ, self._make_start_response_wrapper(start_response))
|
|
93
|
+
self.agent.logger.info("Modulename: WSGI interceptor class || response is :{0}".format(response))
|
|
94
|
+
|
|
95
|
+
except:
|
|
96
|
+
with self.log_exceptions():
|
|
97
|
+
if bt:
|
|
98
|
+
bt.add_exception(*sys.exc_info())
|
|
99
|
+
raise
|
|
100
|
+
finally:
|
|
101
|
+
method = the_method_called
|
|
102
|
+
self.agent.method_exit(bt,method)
|
|
103
|
+
self.end_business_transaction(bt)
|
|
104
|
+
|
|
105
|
+
return response
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""Interceptor for AIOHTTP Server framework.
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
from ..base import BaseInterceptor
|
|
7
|
+
from pythonagent.utils import get_current_thread_time_in_us, parse_headers, get_true_false
|
|
8
|
+
from pythonagent.agent.probes.havoc.havoc_manager import NDHavocException
|
|
9
|
+
|
|
10
|
+
class AIOHTTPWebInterceptor(BaseInterceptor):
|
|
11
|
+
|
|
12
|
+
def decode_cookie_method_position(self, mpos):
|
|
13
|
+
mpos_bin = format(mpos, '03b')
|
|
14
|
+
return get_true_false(mpos_bin[0]), get_true_false(mpos_bin[1]), get_true_false(mpos_bin[2])
|
|
15
|
+
|
|
16
|
+
async def wrapped_handle(self, _handle, *args, **kwargs):
|
|
17
|
+
|
|
18
|
+
bt = None
|
|
19
|
+
cpu_time_before = None
|
|
20
|
+
path = None
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
request = args[1]
|
|
24
|
+
raw_request_message = request._message
|
|
25
|
+
|
|
26
|
+
path = raw_request_message.path
|
|
27
|
+
method = raw_request_message.method
|
|
28
|
+
raw_headers = raw_request_message.raw_headers
|
|
29
|
+
|
|
30
|
+
bt_name = path + "|" + method
|
|
31
|
+
correlation_header = ""
|
|
32
|
+
req_headers = parse_headers(raw_headers, "$", "|")
|
|
33
|
+
bt_header_value = parse_headers(raw_headers, "=", "&")
|
|
34
|
+
|
|
35
|
+
nd_cookie_value = None
|
|
36
|
+
nv_cookie_value = None
|
|
37
|
+
fp_instance = None
|
|
38
|
+
|
|
39
|
+
nd_cookie_key = self.agent.nd_cookie_key
|
|
40
|
+
nv_cookie_key = self.agent.nv_cookie_key
|
|
41
|
+
|
|
42
|
+
for key, val in raw_headers:
|
|
43
|
+
key = key.decode()
|
|
44
|
+
val = val.decode()
|
|
45
|
+
|
|
46
|
+
if key.lower() == 'cavndfpinstance':
|
|
47
|
+
fp_instance = val
|
|
48
|
+
|
|
49
|
+
if key.lower() == 'cookie':
|
|
50
|
+
cookie_list = val.split("; ")
|
|
51
|
+
for cookie in cookie_list:
|
|
52
|
+
cookie_key_val = cookie.split("=")
|
|
53
|
+
cookie_key = cookie_key_val[0]
|
|
54
|
+
cookie_val = cookie_key_val[1]
|
|
55
|
+
|
|
56
|
+
if cookie_key == nd_cookie_key:
|
|
57
|
+
nd_cookie_value = cookie_val
|
|
58
|
+
if cookie_key == nv_cookie_key:
|
|
59
|
+
nv_cookie_value = cookie_val
|
|
60
|
+
|
|
61
|
+
cpu_time_before = get_current_thread_time_in_us()
|
|
62
|
+
|
|
63
|
+
bt = self.agent.start_business_transaction(bt_name, correlation_header, nd_cookie_value,
|
|
64
|
+
nv_cookie_value, bt_header_value, fp_instance)
|
|
65
|
+
print("bt", bt)
|
|
66
|
+
|
|
67
|
+
self.agent.http_req_resp_wrapper(bt, req_headers, "req", 200)
|
|
68
|
+
|
|
69
|
+
except Exception as e:
|
|
70
|
+
self.agent.logger.exception("Exception in Start BT for AIOHTTP Web {}".format(e))
|
|
71
|
+
|
|
72
|
+
# Invoking inbound havoc failure at the entry of the instrumented method
|
|
73
|
+
# so that the transaction fails at the start and does not continue
|
|
74
|
+
# processing to capture callouts or other downstream operations.
|
|
75
|
+
try:
|
|
76
|
+
context = self.agent.get_transaction_context()
|
|
77
|
+
btname = context.btname if context else None
|
|
78
|
+
self.agent.havoc_monitor.apply_inbound_service_failure(path, btname)
|
|
79
|
+
except Exception as e:
|
|
80
|
+
if isinstance(e, NDHavocException):
|
|
81
|
+
cpu_time_after = get_current_thread_time_in_us()
|
|
82
|
+
cpu_time = cpu_time_after - (cpu_time_before or 0)
|
|
83
|
+
self.agent.set_current_status_code(503)
|
|
84
|
+
self.agent.end_business_transaction(bt, cpu_time)
|
|
85
|
+
self.agent.havoc_monitor.refresh_configs(self.agent)
|
|
86
|
+
raise e
|
|
87
|
+
else:
|
|
88
|
+
self.agent.logger.debug("Non-Havoc Exception {}".format(e))
|
|
89
|
+
|
|
90
|
+
response = await _handle(*args, **kwargs)
|
|
91
|
+
|
|
92
|
+
try:
|
|
93
|
+
if bt:
|
|
94
|
+
cpu_time_after = get_current_thread_time_in_us()
|
|
95
|
+
cpu_time = cpu_time_after - cpu_time_before
|
|
96
|
+
|
|
97
|
+
nd_cookie_key = None
|
|
98
|
+
x_cav_nv = None
|
|
99
|
+
x_cav_nv_headers = None
|
|
100
|
+
|
|
101
|
+
if self.agent.cookie_method_position:
|
|
102
|
+
r_commit, m_entry, m_exit = self.decode_cookie_method_position(self.agent.cookie_method_position)
|
|
103
|
+
|
|
104
|
+
if self.agent.header_in_response:
|
|
105
|
+
x_cav_nv = get_true_false(self.agent.header_in_response)
|
|
106
|
+
|
|
107
|
+
nd_cookie_value = self.agent.sdk_getNDSessionCookie(bt).decode()
|
|
108
|
+
|
|
109
|
+
if nd_cookie_key: # CavNV Enabled
|
|
110
|
+
if nd_cookie_value:
|
|
111
|
+
nd_cookie_str = "{}={}".format(nd_cookie_key, nd_cookie_value)
|
|
112
|
+
response.headers['Set-Cookie'] = nd_cookie_str
|
|
113
|
+
else:
|
|
114
|
+
if self.agent.disable_nd_nv: # CavNV Disabled Just Now
|
|
115
|
+
nd_cookie_str = "CavNV=None; Max-Age=0"
|
|
116
|
+
response.headers['Set-Cookie'] = nd_cookie_str
|
|
117
|
+
self.agent.disable_nd_nv = False
|
|
118
|
+
|
|
119
|
+
if x_cav_nv: # X-CavNV Enabled
|
|
120
|
+
if nd_cookie_value:
|
|
121
|
+
response.headers['X-CavNV'] = nd_cookie_value
|
|
122
|
+
x_cav_nv_headers = "|X-CavNV$" + nd_cookie_value
|
|
123
|
+
|
|
124
|
+
key_val_sep = "$"
|
|
125
|
+
item_value_sep = "|"
|
|
126
|
+
resp_headers = ""
|
|
127
|
+
|
|
128
|
+
for key, value in response.headers.items():
|
|
129
|
+
|
|
130
|
+
print("key", key)
|
|
131
|
+
print("value", value)
|
|
132
|
+
key = str(key)
|
|
133
|
+
value = str(value)
|
|
134
|
+
|
|
135
|
+
value = value.replace("|", "%7C") # CavSF has | in value
|
|
136
|
+
value = value.replace(":", "%3A") # Host as : in value
|
|
137
|
+
value = value.replace("=", "%3D") # Accept, Accept-Language, and ND-NV cookies have = in value
|
|
138
|
+
new_str = key + key_val_sep + value + item_value_sep
|
|
139
|
+
resp_headers += new_str
|
|
140
|
+
resp_headers = resp_headers[:-1] # Remove last |
|
|
141
|
+
|
|
142
|
+
self.agent.http_req_resp_wrapper(bt, resp_headers, "resp", 200)
|
|
143
|
+
|
|
144
|
+
self.agent.end_business_transaction(bt, cpu_time)
|
|
145
|
+
print("END BT")
|
|
146
|
+
|
|
147
|
+
except Exception as e:
|
|
148
|
+
self.agent.logger.exception("Exception in End BT for AIOHTTP Web {}".format(e))
|
|
149
|
+
|
|
150
|
+
return response
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def intercept_aiohttp_web(agent, mod):
|
|
154
|
+
agent.logger.warning("Instrument module: aiohttp.web_app{}".format(", mod: {}".format(mod) if mod else ""))
|
|
155
|
+
AIOHTTPWebInterceptor(agent, mod.Application).attach('_handle', patched_method_name='wrapped_handle')
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import cProfile
|
|
4
|
+
import threading
|
|
5
|
+
import pstats
|
|
6
|
+
from collections import Counter
|
|
7
|
+
from pyclbr import readmodule
|
|
8
|
+
|
|
9
|
+
class Aisession():
|
|
10
|
+
def __init__(self, istart, starttime, duration, sess):
|
|
11
|
+
self.duration = duration
|
|
12
|
+
self.istart = istart
|
|
13
|
+
self.starttime = starttime
|
|
14
|
+
self.sess = sess
|
|
15
|
+
print("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSEEEEEEEEEEEEEEEEEEEEEEEEEEEESSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", sess)
|
|
16
|
+
self.prof = cProfile.Profile()
|
|
17
|
+
os.environ['aisess_status'] = 'True'
|
|
18
|
+
|
|
19
|
+
def enableprof(self):
|
|
20
|
+
self.prof.enable()
|
|
21
|
+
#os.environ['aisess_status'] = 'True'
|
|
22
|
+
#os.environ['Aisession_flag'] = 'True'
|
|
23
|
+
|
|
24
|
+
def endsession(self):
|
|
25
|
+
self.prof.disable()
|
|
26
|
+
self.printst()
|
|
27
|
+
os.environ['aisess_status'] = 'False'
|
|
28
|
+
os.environ['Aisession_flag'] = 'False'
|
|
29
|
+
print("@!#@$#%$^&*^&%^$%#$@####$#%$^% IN endsession")
|
|
30
|
+
self.prof = None
|
|
31
|
+
|
|
32
|
+
"""def disableprof(self):
|
|
33
|
+
timer = threading.Timer(self.time,self.endsession)
|
|
34
|
+
timer.start()"""
|
|
35
|
+
def disableprof(self):
|
|
36
|
+
#if self.istart == 0:
|
|
37
|
+
# self.endsession()
|
|
38
|
+
timer = threading.Timer(self.duration,self.endsession)
|
|
39
|
+
timer.start()
|
|
40
|
+
print("exiting endsession")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
"""def stopaisession(self, duration):
|
|
44
|
+
self.disableprof(duration)
|
|
45
|
+
print(" IN stopaisession")
|
|
46
|
+
self.printst()
|
|
47
|
+
self.aiobj = None"""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def printst(self):
|
|
51
|
+
ndhome = os.environ.get('NDHOME')
|
|
52
|
+
path = ndhome + '/python/logs/'
|
|
53
|
+
filename = str(self.sess.decode('ascii'))+"_AI.txt"
|
|
54
|
+
file_to_open = os.path.join(path, filename)
|
|
55
|
+
filenameai = str(self.sess.decode('ascii'))+".txt"
|
|
56
|
+
aifile_to_open = os.path.join(path, filenameai)
|
|
57
|
+
xmlfilename = str(self.sess.decode('ascii'))+".xml"
|
|
58
|
+
xmlfile_to_open = os.path.join(path, xmlfilename)
|
|
59
|
+
xmlfile = open(xmlfile_to_open, 'w')
|
|
60
|
+
f = open(file_to_open, 'w')
|
|
61
|
+
f2 = open(aifile_to_open, 'w')
|
|
62
|
+
#f = open(f'/opt/cavisson/netdiagnostics/logs/{self.sess}.txt', 'w')
|
|
63
|
+
f.writelines("************************************ AUTO-INSTRUMENTATION **************************************** \n")
|
|
64
|
+
f2.writelines("************************************ AUTO-INSTRUMENTATION **************************************** \n")
|
|
65
|
+
f.writelines("# <FQM>| <I:(instrumented) / C :(consisdered) / R :(remove) >| < Total Count > | < Total Duration > | < Added TimeStamp > | < Remove TimeStamp > \n")
|
|
66
|
+
f.writelines(f"#Start_Time {self.starttime}\n")
|
|
67
|
+
#f.writelines(f"#End_Time {}")
|
|
68
|
+
f.writelines(f"#Total Duration {self.duration}\n")
|
|
69
|
+
p = pstats.Stats(self.prof)
|
|
70
|
+
client_app_root = os.path.abspath(os.path.dirname(sys.argv[0]))
|
|
71
|
+
print("application:-",client_app_root)
|
|
72
|
+
methodcountdict = {}
|
|
73
|
+
for k,v in p.stats.items():
|
|
74
|
+
#print(k[0])
|
|
75
|
+
if client_app_root in k[0]:
|
|
76
|
+
modulek001 = k[0]
|
|
77
|
+
print("$$$$$$$$$$$$$$$$$$", modulek001)
|
|
78
|
+
module = k[0]
|
|
79
|
+
print("module:-", k[0])
|
|
80
|
+
module_path = os.path.split(os.path.abspath(module))[0]
|
|
81
|
+
modulefullname = os.path.split(os.path.abspath(module))[1]
|
|
82
|
+
module_name = modulefullname.split('.')[0]
|
|
83
|
+
methodname = k[-1]
|
|
84
|
+
modulemethod = module_path+'*'+module_name+'*'+methodname
|
|
85
|
+
total_call = str(v[1])
|
|
86
|
+
total_duration =str(v[3])
|
|
87
|
+
print('modulemethod:-', modulemethod)
|
|
88
|
+
print('module path:-', module_path)
|
|
89
|
+
print('module name:-', module_name)
|
|
90
|
+
print('method name:- ',k[-1])
|
|
91
|
+
print('Total call:- ',v[1])
|
|
92
|
+
print('Response time of method:-',v[3])
|
|
93
|
+
#methodcountdict = {}
|
|
94
|
+
methodcountdict[modulemethod] = total_call
|
|
95
|
+
mod = readmodule(module_name, path=[module_path])
|
|
96
|
+
li = []
|
|
97
|
+
for k, v in mod.items():
|
|
98
|
+
li.append(k)
|
|
99
|
+
methods = v.methods.items()
|
|
100
|
+
lk = []
|
|
101
|
+
for method, lineno in methods:
|
|
102
|
+
lk.append(method)
|
|
103
|
+
li.append(lk)
|
|
104
|
+
count=0
|
|
105
|
+
classname =''
|
|
106
|
+
for i in li:
|
|
107
|
+
count +=1
|
|
108
|
+
if type(i)==str:
|
|
109
|
+
pass
|
|
110
|
+
else:
|
|
111
|
+
for j in i:
|
|
112
|
+
if j == methodname:
|
|
113
|
+
classname = li[count-2]
|
|
114
|
+
#print("classname:-",li[count-2])
|
|
115
|
+
varfullname = module_name+"."+li[count-2]+"."+methodname
|
|
116
|
+
#print("))))))))))))*((((((((((((",a)
|
|
117
|
+
else:
|
|
118
|
+
pass
|
|
119
|
+
if len(classname)>0:
|
|
120
|
+
print(varfullname)
|
|
121
|
+
else:
|
|
122
|
+
varfullname = module_name+"."+methodname
|
|
123
|
+
print(varfullname)
|
|
124
|
+
outputform = varfullname+"|"+"I"+"|"+total_call+"|"+total_duration+"|"+"0"+"|"+"0"
|
|
125
|
+
print("************************************XWWDWSASSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", outputform)
|
|
126
|
+
# f.writelines("************************************ AUTO-INSTRUMENTATION **************************************** \n")
|
|
127
|
+
f.writelines(f"{outputform} \n")
|
|
128
|
+
if (float(total_duration)/int(total_call)) >=0.7:
|
|
129
|
+
outputformai = varfullname+"|"+"I"+"|"+total_call+"|"+total_duration+"|"+"0"+"|"+"0"
|
|
130
|
+
f2.writelines(f"{outputformai} \n")
|
|
131
|
+
f.close()
|
|
132
|
+
f2.close()
|
|
133
|
+
xmlfile.close()
|
|
134
|
+
print(methodcountdict)
|
|
135
|
+
|
|
136
|
+
"""def aisession():
|
|
137
|
+
ai = WSGIInterceptor()
|
|
138
|
+
ai.application_callable = agentprofiler.application_callable_pro
|
|
139
|
+
|
|
140
|
+
#aisession()
|
|
141
|
+
|
|
142
|
+
def ta():
|
|
143
|
+
wsgi.WSGIInterceptor.application_callable = agentprofiler.application_callable
|
|
144
|
+
|
|
145
|
+
#if flag ==True:
|
|
146
|
+
#timer = threading.Timer(300, ta)
|
|
147
|
+
#timer.start()
|
|
148
|
+
def enablendisablesess():
|
|
149
|
+
aisession()
|
|
150
|
+
timer = threading.Timer(300, ta)
|
|
151
|
+
timer.start()"""
|