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