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