22
33from django .conf import settings
44from django .utils .deprecation import MiddlewareMixin
5+ from django_prometheus .conf import NAMESPACE
56from django_prometheus .utils import PowersOf , Time , TimeSince
67
78DEFAULT_LATENCY_BUCKETS = (
@@ -47,11 +48,13 @@ def register(self):
4748 Counter ,
4849 "django_http_requests_before_middlewares_total" ,
4950 "Total count of requests before middlewares run." ,
51+ namespace = NAMESPACE ,
5052 )
5153 self .responses_total = self .register_metric (
5254 Counter ,
5355 "django_http_responses_before_middlewares_total" ,
5456 "Total count of responses before middlewares run." ,
57+ namespace = NAMESPACE ,
5558 )
5659 self .requests_latency_before = self .register_metric (
5760 Histogram ,
@@ -60,6 +63,7 @@ def register(self):
6063 "Histogram of requests processing time (including middleware "
6164 "processing time)."
6265 ),
66+ namespace = NAMESPACE ,
6367 )
6468 self .requests_unknown_latency_before = self .register_metric (
6569 Counter ,
@@ -68,6 +72,7 @@ def register(self):
6872 "Count of requests for which the latency was unknown (when computing "
6973 "django_http_requests_latency_including_middlewares_seconds)."
7074 ),
75+ namespace = NAMESPACE ,
7176 )
7277 self .requests_latency_by_view_method = self .register_metric (
7378 Histogram ,
@@ -77,90 +82,107 @@ def register(self):
7782 buckets = getattr (
7883 settings , "PROMETHEUS_LATENCY_BUCKETS" , DEFAULT_LATENCY_BUCKETS
7984 ),
85+ namespace = NAMESPACE ,
8086 )
8187 self .requests_unknown_latency = self .register_metric (
8288 Counter ,
8389 "django_http_requests_unknown_latency_total" ,
8490 "Count of requests for which the latency was unknown." ,
91+ namespace = NAMESPACE ,
8592 )
8693 # Set in process_request
8794 self .requests_ajax = self .register_metric (
88- Counter , "django_http_ajax_requests_total" , "Count of AJAX requests."
95+ Counter ,
96+ "django_http_ajax_requests_total" ,
97+ "Count of AJAX requests." ,
98+ namespace = NAMESPACE ,
8999 )
90100 self .requests_by_method = self .register_metric (
91101 Counter ,
92102 "django_http_requests_total_by_method" ,
93103 "Count of requests by method." ,
94104 ["method" ],
105+ namespace = NAMESPACE ,
95106 )
96107 self .requests_by_transport = self .register_metric (
97108 Counter ,
98109 "django_http_requests_total_by_transport" ,
99110 "Count of requests by transport." ,
100111 ["transport" ],
112+ namespace = NAMESPACE ,
101113 )
102114 # Set in process_view
103115 self .requests_by_view_transport_method = self .register_metric (
104116 Counter ,
105117 "django_http_requests_total_by_view_transport_method" ,
106118 "Count of requests by view, transport, method." ,
107119 ["view" , "transport" , "method" ],
120+ namespace = NAMESPACE ,
108121 )
109122 self .requests_body_bytes = self .register_metric (
110123 Histogram ,
111124 "django_http_requests_body_total_bytes" ,
112125 "Histogram of requests by body size." ,
113126 buckets = PowersOf (2 , 30 ),
127+ namespace = NAMESPACE ,
114128 )
115129 # Set in process_template_response
116130 self .responses_by_templatename = self .register_metric (
117131 Counter ,
118132 "django_http_responses_total_by_templatename" ,
119133 "Count of responses by template name." ,
120134 ["templatename" ],
135+ namespace = NAMESPACE ,
121136 )
122137 # Set in process_response
123138 self .responses_by_status = self .register_metric (
124139 Counter ,
125140 "django_http_responses_total_by_status" ,
126141 "Count of responses by status." ,
127142 ["status" ],
143+ namespace = NAMESPACE ,
128144 )
129145 self .responses_by_status_view_method = self .register_metric (
130146 Counter ,
131147 "django_http_responses_total_by_status_view_method" ,
132148 "Count of responses by status, view, method." ,
133149 ["status" , "view" , "method" ],
150+ namespace = NAMESPACE ,
134151 )
135152 self .responses_body_bytes = self .register_metric (
136153 Histogram ,
137154 "django_http_responses_body_total_bytes" ,
138155 "Histogram of responses by body size." ,
139156 buckets = PowersOf (2 , 30 ),
157+ namespace = NAMESPACE ,
140158 )
141159 self .responses_by_charset = self .register_metric (
142160 Counter ,
143161 "django_http_responses_total_by_charset" ,
144162 "Count of responses by charset." ,
145163 ["charset" ],
164+ namespace = NAMESPACE ,
146165 )
147166 self .responses_streaming = self .register_metric (
148167 Counter ,
149168 "django_http_responses_streaming_total" ,
150169 "Count of streaming responses." ,
170+ namespace = NAMESPACE ,
151171 )
152172 # Set in process_exception
153173 self .exceptions_by_type = self .register_metric (
154174 Counter ,
155175 "django_http_exceptions_total_by_type" ,
156176 "Count of exceptions by object type." ,
157177 ["type" ],
178+ namespace = NAMESPACE ,
158179 )
159180 self .exceptions_by_view = self .register_metric (
160181 Counter ,
161182 "django_http_exceptions_total_by_view" ,
162183 "Count of exceptions by view." ,
163184 ["view" ],
185+ namespace = NAMESPACE ,
164186 )
165187
166188
0 commit comments