41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186 | def __init__(
self,
registry: "CollectorRegistry",
*,
metrics_prefix: str = "faststream",
received_messages_size_buckets: Sequence[float] | None = None,
custom_label_names: Sequence[str],
) -> None:
self._registry = registry
self._metrics_prefix = metrics_prefix
received_messages_total_name = f"{metrics_prefix}_received_messages_total"
self.received_messages_total = cast(
"Counter | None",
self._get_registered_metric(received_messages_total_name),
) or Counter(
name=received_messages_total_name,
documentation="Count of received messages by broker and handler",
labelnames=["app_name", "broker", "handler", *custom_label_names],
registry=registry,
)
received_messages_size_bytes_name = (
f"{metrics_prefix}_received_messages_size_bytes"
)
self.received_messages_size_bytes = cast(
"Histogram | None",
self._get_registered_metric(received_messages_size_bytes_name),
) or Histogram(
name=received_messages_size_bytes_name,
documentation="Histogram of received messages size in bytes by broker and handler",
labelnames=["app_name", "broker", "handler", *custom_label_names],
registry=registry,
buckets=received_messages_size_buckets or self.DEFAULT_SIZE_BUCKETS,
)
received_messages_in_process_name = (
f"{metrics_prefix}_received_messages_in_process"
)
self.received_messages_in_process = cast(
"Gauge | None",
self._get_registered_metric(received_messages_in_process_name),
) or Gauge(
name=received_messages_in_process_name,
documentation="Gauge of received messages in process by broker and handler",
labelnames=["app_name", "broker", "handler", *custom_label_names],
registry=registry,
)
received_processed_messages_total_name = (
f"{metrics_prefix}_received_processed_messages_total"
)
self.received_processed_messages_total = cast(
"Counter | None",
self._get_registered_metric(received_processed_messages_total_name),
) or Counter(
name=received_processed_messages_total_name,
documentation="Count of received processed messages by broker, handler and status",
labelnames=["app_name", "broker", "handler", "status", *custom_label_names],
registry=registry,
)
received_processed_messages_duration_seconds_name = (
f"{metrics_prefix}_received_processed_messages_duration_seconds"
)
self.received_processed_messages_duration_seconds = cast(
"Histogram | None",
self._get_registered_metric(
received_processed_messages_duration_seconds_name,
),
) or Histogram(
name=received_processed_messages_duration_seconds_name,
documentation="Histogram of received processed messages duration in seconds by broker and handler",
labelnames=["app_name", "broker", "handler", *custom_label_names],
registry=registry,
)
received_processed_messages_exceptions_total_name = (
f"{metrics_prefix}_received_processed_messages_exceptions_total"
)
self.received_processed_messages_exceptions_total = cast(
"Counter | None",
self._get_registered_metric(
received_processed_messages_exceptions_total_name,
),
) or Counter(
name=received_processed_messages_exceptions_total_name,
documentation="Count of received processed messages exceptions by broker, handler and exception_type",
labelnames=[
"app_name",
"broker",
"handler",
"exception_type",
*custom_label_names,
],
registry=registry,
)
published_messages_total_name = f"{metrics_prefix}_published_messages_total"
self.published_messages_total = cast(
"Counter | None",
self._get_registered_metric(published_messages_total_name),
) or Counter(
name=published_messages_total_name,
documentation="Count of published messages by destination and status",
labelnames=[
"app_name",
"broker",
"destination",
"status",
*custom_label_names,
],
registry=registry,
)
published_messages_duration_seconds_name = (
f"{metrics_prefix}_published_messages_duration_seconds"
)
self.published_messages_duration_seconds = cast(
"Histogram | None",
self._get_registered_metric(published_messages_duration_seconds_name),
) or Histogram(
name=published_messages_duration_seconds_name,
documentation="Histogram of published messages duration in seconds by broker and destination",
labelnames=["app_name", "broker", "destination", *custom_label_names],
registry=registry,
)
published_messages_exceptions_total_name = (
f"{metrics_prefix}_published_messages_exceptions_total"
)
self.published_messages_exceptions_total = cast(
"Counter | None",
self._get_registered_metric(published_messages_exceptions_total_name),
) or Counter(
name=published_messages_exceptions_total_name,
documentation="Count of published messages exceptions by broker, destination and exception_type",
labelnames=[
"app_name",
"broker",
"destination",
"exception_type",
*custom_label_names,
],
registry=registry,
)
|