(&self, request: HttpRequest)
| 37 | } |
| 38 | |
| 39 | async fn metrics(&self, request: HttpRequest) -> HttpResponse { |
| 40 | if request.method.to_lowercase() != "get" { |
| 41 | return HttpResponse { |
| 42 | status_code: 405, |
| 43 | headers: vec![HeaderField("Allow".into(), "GET".into())], |
| 44 | body: "405 Method Not Allowed".as_bytes().to_owned(), |
| 45 | }; |
| 46 | } |
| 47 | |
| 48 | // Add dynamic metrics, dropped after the request since query calls don't save state changes. |
| 49 | with_metrics_registry(SERVICE_NAME, |registry| { |
| 50 | registry |
| 51 | .gauge_mut( |
| 52 | "canister_cycles_balance", |
| 53 | "cycles balance available to the canister", |
| 54 | ) |
| 55 | .set(canister_balance() as f64); |
| 56 | }); |
| 57 | |
| 58 | with_metrics_registry(SERVICE_NAME, |registry| { |
| 59 | registry.export_metrics_as_http_response() |
| 60 | }) |
| 61 | } |
| 62 | } |
no test coverage detected