Skip to main content

risingwave_storage/monitor/
pin_cache_metrics.rs

1// Copyright 2026 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::LazyLock;
16
17use prometheus::{IntGauge, Registry, register_int_gauge_with_registry};
18use risingwave_common::monitor::GLOBAL_METRICS_REGISTRY;
19
20pub(crate) static GLOBAL_PIN_CACHE_METRICS: LazyLock<PinCacheMetrics> =
21    LazyLock::new(|| PinCacheMetrics::new(&GLOBAL_METRICS_REGISTRY));
22
23/// Metrics for the Hummock-local Pin Cache lifecycle and physical reclamation.
24pub(crate) struct PinCacheMetrics {
25    pub published_objects: IntGauge,
26    pub published_bytes: IntGauge,
27}
28
29impl PinCacheMetrics {
30    fn new(registry: &Registry) -> Self {
31        let published_objects = register_int_gauge_with_registry!(
32            "pin_cache_published_objects",
33            "Complete SST objects currently routed to the local Pin Cache",
34            registry
35        )
36        .unwrap();
37        let published_bytes = register_int_gauge_with_registry!(
38            "pin_cache_published_bytes",
39            "Complete SST bytes currently routed to the local Pin Cache",
40            registry
41        )
42        .unwrap();
43        Self {
44            published_objects,
45            published_bytes,
46        }
47    }
48}