|
10 | 10 | Counter, |
11 | 11 | Gauge, |
12 | 12 | Histogram, |
13 | | - Summary, |
14 | 13 | generate_latest, |
15 | 14 | push_to_gateway, |
16 | 15 | start_http_server, |
@@ -55,7 +54,6 @@ def __init__(self, config: Optional[PrometheusConfig] = None): |
55 | 54 | self._counters: Dict[str, Counter] = {} |
56 | 55 | self._gauges: Dict[str, Gauge] = {} |
57 | 56 | self._histograms: Dict[str, Histogram] = {} |
58 | | - self._summaries: Dict[str, Summary] = {} |
59 | 57 |
|
60 | 58 | # HTTP server handle |
61 | 59 | self._http_server: Optional[Any] = None |
@@ -128,23 +126,23 @@ def _get_or_create_histogram( |
128 | 126 |
|
129 | 127 | return self._histograms[metric_name] |
130 | 128 |
|
131 | | - def _get_or_create_summary( |
| 129 | + def _get_or_create_timer( |
132 | 130 | self, name: str, labels: Optional[Dict[str, str]] |
133 | | - ) -> Summary: |
134 | | - """Get or create a Summary metric.""" |
| 131 | + ) -> Histogram: |
| 132 | + """Get or create a timer metric (implemented as histogram).""" |
135 | 133 | metric_name = self._get_metric_name(name) |
136 | 134 |
|
137 | | - if metric_name not in self._summaries: |
| 135 | + if metric_name not in self._histograms: |
138 | 136 | label_names = list(self._merge_labels(labels).keys()) if labels else [] |
139 | | - self._summaries[metric_name] = Summary( |
| 137 | + self._histograms[metric_name] = Histogram( |
140 | 138 | metric_name, |
141 | | - f"Summary metric for {name}", |
| 139 | + f"Timer metric for {name}", |
142 | 140 | labelnames=label_names, |
143 | 141 | registry=self.registry, |
144 | 142 | ) |
145 | | - logger.debug(f"Created summary metric: {metric_name}") |
| 143 | + logger.debug(f"Created timer metric: {metric_name}") |
146 | 144 |
|
147 | | - return self._summaries[metric_name] |
| 145 | + return self._histograms[metric_name] |
148 | 146 |
|
149 | 147 | def counter( |
150 | 148 | self, key: str, n: int = 1, tags: Optional[Dict[str, str]] = None |
@@ -183,13 +181,13 @@ def timer( |
183 | 181 | ) -> None: |
184 | 182 | """Send a timer metric - implemented as histogram.""" |
185 | 183 | try: |
186 | | - histogram = self._get_or_create_histogram(key, tags) |
| 184 | + timer = self._get_or_create_timer(key, tags) |
187 | 185 | merged_tags = self._merge_labels(tags) |
188 | 186 |
|
189 | 187 | if merged_tags: |
190 | | - histogram.labels(**merged_tags).observe(duration) |
| 188 | + timer.labels(**merged_tags).observe(duration) |
191 | 189 | else: |
192 | | - histogram.observe(duration) |
| 190 | + timer.observe(duration) |
193 | 191 |
|
194 | 192 | except Exception as e: |
195 | 193 | logger.error(f"Failed to send timer {key}: {e}") |
|
0 commit comments