4
4
from django .utils .deprecation import MiddlewareMixin
5
5
from django_prometheus .utils import PowersOf , Time , TimeSince
6
6
7
+ from django_prometheus .conf import NAMESPACE
8
+
7
9
DEFAULT_LATENCY_BUCKETS = (
8
10
0.01 ,
9
11
0.025 ,
@@ -47,11 +49,13 @@ def register(self):
47
49
Counter ,
48
50
"django_http_requests_before_middlewares_total" ,
49
51
"Total count of requests before middlewares run." ,
52
+ namespace = NAMESPACE
50
53
)
51
54
self .responses_total = self .register_metric (
52
55
Counter ,
53
56
"django_http_responses_before_middlewares_total" ,
54
57
"Total count of responses before middlewares run." ,
58
+ namespace = NAMESPACE
55
59
)
56
60
self .requests_latency_before = self .register_metric (
57
61
Histogram ,
@@ -60,6 +64,7 @@ def register(self):
60
64
"Histogram of requests processing time (including middleware "
61
65
"processing time)."
62
66
),
67
+ namespace = NAMESPACE
63
68
)
64
69
self .requests_unknown_latency_before = self .register_metric (
65
70
Counter ,
@@ -68,6 +73,7 @@ def register(self):
68
73
"Count of requests for which the latency was unknown (when computing "
69
74
"django_http_requests_latency_including_middlewares_seconds)."
70
75
),
76
+ namespace = NAMESPACE
71
77
)
72
78
self .requests_latency_by_view_method = self .register_metric (
73
79
Histogram ,
@@ -77,90 +83,105 @@ def register(self):
77
83
buckets = getattr (
78
84
settings , "PROMETHEUS_LATENCY_BUCKETS" , DEFAULT_LATENCY_BUCKETS
79
85
),
86
+ namespace = NAMESPACE
80
87
)
81
88
self .requests_unknown_latency = self .register_metric (
82
89
Counter ,
83
90
"django_http_requests_unknown_latency_total" ,
84
91
"Count of requests for which the latency was unknown." ,
92
+ namespace = NAMESPACE
85
93
)
86
94
# Set in process_request
87
95
self .requests_ajax = self .register_metric (
88
- Counter , "django_http_ajax_requests_total" , "Count of AJAX requests."
96
+ Counter , "django_http_ajax_requests_total" , "Count of AJAX requests." ,
97
+ namespace = NAMESPACE
89
98
)
90
99
self .requests_by_method = self .register_metric (
91
100
Counter ,
92
101
"django_http_requests_total_by_method" ,
93
102
"Count of requests by method." ,
94
103
["method" ],
104
+ namespace = NAMESPACE
95
105
)
96
106
self .requests_by_transport = self .register_metric (
97
107
Counter ,
98
108
"django_http_requests_total_by_transport" ,
99
109
"Count of requests by transport." ,
100
110
["transport" ],
111
+ namespace = NAMESPACE
101
112
)
102
113
# Set in process_view
103
114
self .requests_by_view_transport_method = self .register_metric (
104
115
Counter ,
105
116
"django_http_requests_total_by_view_transport_method" ,
106
117
"Count of requests by view, transport, method." ,
107
118
["view" , "transport" , "method" ],
119
+ namespace = NAMESPACE
108
120
)
109
121
self .requests_body_bytes = self .register_metric (
110
122
Histogram ,
111
123
"django_http_requests_body_total_bytes" ,
112
124
"Histogram of requests by body size." ,
113
125
buckets = PowersOf (2 , 30 ),
126
+ namespace = NAMESPACE
114
127
)
115
128
# Set in process_template_response
116
129
self .responses_by_templatename = self .register_metric (
117
130
Counter ,
118
131
"django_http_responses_total_by_templatename" ,
119
132
"Count of responses by template name." ,
120
133
["templatename" ],
134
+ namespace = NAMESPACE
121
135
)
122
136
# Set in process_response
123
137
self .responses_by_status = self .register_metric (
124
138
Counter ,
125
139
"django_http_responses_total_by_status" ,
126
140
"Count of responses by status." ,
127
141
["status" ],
142
+ namespace = NAMESPACE
128
143
)
129
144
self .responses_by_status_view_method = self .register_metric (
130
145
Counter ,
131
146
"django_http_responses_total_by_status_view_method" ,
132
147
"Count of responses by status, view, method." ,
133
148
["status" , "view" , "method" ],
149
+ namespace = NAMESPACE
134
150
)
135
151
self .responses_body_bytes = self .register_metric (
136
152
Histogram ,
137
153
"django_http_responses_body_total_bytes" ,
138
154
"Histogram of responses by body size." ,
139
155
buckets = PowersOf (2 , 30 ),
156
+ namespace = NAMESPACE
140
157
)
141
158
self .responses_by_charset = self .register_metric (
142
159
Counter ,
143
160
"django_http_responses_total_by_charset" ,
144
161
"Count of responses by charset." ,
145
162
["charset" ],
163
+ namespace = NAMESPACE
146
164
)
147
165
self .responses_streaming = self .register_metric (
148
166
Counter ,
149
167
"django_http_responses_streaming_total" ,
150
168
"Count of streaming responses." ,
169
+ namespace = NAMESPACE
151
170
)
152
171
# Set in process_exception
153
172
self .exceptions_by_type = self .register_metric (
154
173
Counter ,
155
174
"django_http_exceptions_total_by_type" ,
156
175
"Count of exceptions by object type." ,
157
176
["type" ],
177
+ namespace = NAMESPACE
158
178
)
159
179
self .exceptions_by_view = self .register_metric (
160
180
Counter ,
161
181
"django_http_exceptions_total_by_view" ,
162
182
"Count of exceptions by view." ,
163
183
["view" ],
184
+ namespace = NAMESPACE
164
185
)
165
186
166
187
0 commit comments