Exports the metrics in the registry to an HTTP response.
(&self)
| 192 | |
| 193 | /// Exports the metrics in the registry to an HTTP response. |
| 194 | pub fn export_metrics_as_http_response(&self) -> HttpResponse { |
| 195 | let metrics_result = self.export_metrics(); |
| 196 | |
| 197 | match metrics_result { |
| 198 | Ok(metrics) => HttpResponse { |
| 199 | status_code: 200, |
| 200 | headers: vec![HeaderField( |
| 201 | "Content-Type".to_string(), |
| 202 | "text/plain".to_string(), |
| 203 | )], |
| 204 | body: metrics, |
| 205 | }, |
| 206 | Err(err) => { |
| 207 | print(format!("Error exporting metrics: {err:?}")); |
| 208 | |
| 209 | HttpResponse { |
| 210 | status_code: 500, |
| 211 | headers: vec![HeaderField( |
| 212 | "Content-Type".to_string(), |
| 213 | "text/plain".to_string(), |
| 214 | )], |
| 215 | body: "500 Internal Server Error".as_bytes().to_owned(), |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /// A trait for application metrics that can be recalculated and updated based on the current state of the application. |
no test coverage detected