@@ -164,7 +164,7 @@ mod internal {
164164 routing:: get,
165165 } ;
166166 use hyper:: StatusCode ;
167- use metrics_exporter_prometheus:: PrometheusBuilder ;
167+ use metrics_exporter_prometheus:: { PrometheusBuilder , PrometheusHandle } ;
168168 use pprof:: { ProfilerGuard , protos:: Message } ;
169169 use pulsebeam_runtime:: actor:: Actor ;
170170 use serde:: Deserialize ;
@@ -225,7 +225,7 @@ mod internal {
225225 . with_interval ( std:: time:: Duration :: from_secs ( 5 ) )
226226 . describe_and_run ( ) ,
227227 ) ;
228- let actor_monitor_join = tokio:: spawn ( monitor_actors ( ) ) ;
228+ let actor_monitor_join = tokio:: spawn ( background_monitor ( prometheus_handle ) ) ;
229229
230230 tokio:: select! {
231231 res = axum:: serve( listener, router) => {
@@ -243,7 +243,7 @@ mod internal {
243243 Ok ( ( ) )
244244 }
245245
246- async fn monitor_actors ( ) {
246+ async fn background_monitor ( prometheus_handle : PrometheusHandle ) {
247247 let mut monitors = [
248248 ( "gateway" , gateway:: GatewayActor :: monitor ( ) . intervals ( ) ) ,
249249 (
@@ -267,6 +267,11 @@ mod internal {
267267 loop {
268268 interval. tick ( ) . await ;
269269
270+ // https://docs.rs/metrics-exporter-prometheus/latest/metrics_exporter_prometheus/#upkeep-and-maintenance
271+ // Keep memory usage and CPU usage bounded per prometheus interval.
272+ // 5 seconds matches the default from the crate.
273+ prometheus_handle. run_upkeep ( ) ;
274+
270275 for ( actor_name, monitor) in & mut monitors {
271276 let Some ( snapshot) = monitor. next ( ) else {
272277 continue ;
0 commit comments